cedro 0.1.8 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/README.md +7 -4
  2. package/dist/cedro-logo.png +0 -0
  3. package/dist/fangio.jpg +0 -0
  4. package/package.json +4 -2
  5. package/src/core/application.builder.tsx +121 -0
  6. package/src/core/{application.core.ts → application.core.tsx} +175 -9
  7. package/src/core/themes.core.ts +160 -1
  8. package/src/core/uid.ts +3 -3
  9. package/src/index.ts +1 -1
  10. package/src/interfaces/application.interface.ts +10 -3
  11. package/src/interfaces/widget.interface.ts +6 -1
  12. package/src/types/select.item.type.ts +11 -0
  13. package/src/ui/Icon.ui.tsx +158 -0
  14. package/src/ui/IconButton.ui.tsx +233 -0
  15. package/src/ui/{textbox.ui.ts → Textbox.ui.tsx} +69 -8
  16. package/src/ui/accordion.ui.tsx +152 -0
  17. package/src/ui/button.ui.tsx +209 -0
  18. package/src/ui/buttonColor.ui.tsx +87 -0
  19. package/src/ui/buttonmenu.ui.tsx +134 -0
  20. package/src/ui/{buttonstack.ui.ts → buttonstack.ui.tsx} +67 -1
  21. package/src/ui/checkbox.ui.tsx +43 -0
  22. package/src/ui/container.ui.tsx +141 -0
  23. package/src/ui/datagrid.ui.tsx +518 -0
  24. package/src/ui/dialog.tsx +143 -56
  25. package/src/ui/{hpanel.ui.ts → hpanel.ui.tsx} +64 -1
  26. package/src/ui/iconButtonMenu.ui.tsx +176 -0
  27. package/src/ui/image.ui.tsx +123 -0
  28. package/src/ui/index.ts +9 -9
  29. package/src/ui/label.ui.tsx +184 -0
  30. package/src/ui/loading.ui.ts +10 -10
  31. package/src/ui/menu.ui.ts +2 -2
  32. package/src/ui/progressbar.ui.tsx +135 -0
  33. package/src/ui/radiobutton.ui.tsx +47 -0
  34. package/src/ui/scroll.ui.ts +13 -12
  35. package/src/ui/select.ui.tsx +143 -0
  36. package/src/ui/styles/button.css +114 -32
  37. package/src/ui/styles/buttoncolor.css +8 -8
  38. package/src/ui/styles/container.css +29 -0
  39. package/src/ui/styles/hpanel.css +1 -1
  40. package/src/ui/styles/icon.css +29 -0
  41. package/src/ui/styles/image.css +19 -19
  42. package/src/ui/styles/label.css +63 -0
  43. package/src/ui/styles/loading.css +12 -12
  44. package/src/ui/styles/main.css +5 -0
  45. package/src/ui/styles/progressbar.css +3 -2
  46. package/src/ui/styles/select.css +13 -0
  47. package/src/ui/styles/stackbutton.css +36 -0
  48. package/src/ui/styles/tabs.css +5 -7
  49. package/src/ui/styles/textarea.css +13 -13
  50. package/src/ui/styles/valuebar.css +1 -1
  51. package/src/ui/styles/vpanel.css +1 -1
  52. package/src/ui/switch.ui.tsx +42 -0
  53. package/src/ui/{tabs.ui.ts → tabs.ui.tsx} +114 -8
  54. package/src/ui/textarea.ui.tsx +48 -0
  55. package/src/ui/{toolbar.ui.ts → toolbar.ui.tsx} +44 -1
  56. package/src/ui/{valuebar.ui.ts → valuebar.ui.tsx} +35 -1
  57. package/src/ui/{vpanel.ui.ts → vpanel.ui.tsx} +44 -1
  58. package/src/ui/widget.builder.ts +243 -0
  59. package/src/ui/widget.collection.ts +57 -5
  60. package/src/ui/widget.ui.ts +176 -24
  61. package/src/ui/Icon.ui.ts +0 -64
  62. package/src/ui/IconButton.ui.ts +0 -114
  63. package/src/ui/accordion.ui.ts +0 -71
  64. package/src/ui/button.ui.ts +0 -105
  65. package/src/ui/buttonColor.ui.ts +0 -24
  66. package/src/ui/buttonmenu.ui.ts +0 -59
  67. package/src/ui/checkbox.ui.ts +0 -8
  68. package/src/ui/container.ui.ts +0 -38
  69. package/src/ui/datagrid.ui.ts +0 -231
  70. package/src/ui/iconButtonMenu.ui.ts +0 -59
  71. package/src/ui/image.ui.ts +0 -49
  72. package/src/ui/label.ui.ts +0 -82
  73. package/src/ui/progressbar.ui.ts +0 -74
  74. package/src/ui/radiobutton.ts +0 -8
  75. package/src/ui/select.ui.ts +0 -73
  76. package/src/ui/switch.ui.ts +0 -7
  77. package/src/ui/textarea.ui.ts +0 -20
  78. package/src/ui/widget.builder.ui.tsx +0 -676
  79. /package/src/ui/{toggle.ui.ts → toggle.ui.tsx} +0 -0
package/src/ui/index.ts CHANGED
@@ -1,47 +1,48 @@
1
+ import { WidgetAlignTypes, WidgetTypes, Widget } from "./widget.ui";
2
+ import { Textbox } from "./Textbox.ui";
3
+ import { Select } from "./select.ui";
1
4
  import { Accordion } from "./accordion.ui";
2
5
  import { Button } from "./button.ui";
3
6
  import { ButtonColor } from "./buttonColor.ui";
4
7
  import { ButtonMenu } from "./buttonmenu.ui";
5
8
  import { ButtonStack } from "./buttonstack.ui";
9
+ import { IconButton } from "./IconButton.ui";
6
10
  import { Checkbox } from "./checkbox.ui";
7
11
  import { Container, Spacer, ContainerParams } from "./container.ui";
8
- import { WidgetAlignTypes, WidgetTypes, Widget } from "./widget.ui";
9
12
  import { Dialog } from "./dialog";
10
13
  import { HPanel } from "./hpanel.ui";
11
14
  import { Icon } from "./Icon.ui";
12
- import { IconButton } from "./IconButton.ui";
13
15
  import { Image } from "./image.ui";
14
16
  import { Label } from "./label.ui";
15
17
  import { Menu } from "./menu.ui";
16
18
  import { ProgressBar } from "./progressbar.ui";
17
- import { Select } from "./select.ui";
18
19
  import { Switch } from "./switch.ui";
19
- import { Textbox } from "./textbox.ui";
20
20
  import { Tabs } from "./tabs.ui";
21
21
  import { TextArea } from "./textarea.ui";
22
22
  import { Toolbar } from "./toolbar.ui";
23
23
  import { DataGrid } from "./datagrid.ui";
24
- import { RadioButton } from "./radiobutton";
24
+ import { RadioButton } from "./radiobutton.ui";
25
25
  import { ValueBar } from "./valuebar.ui";
26
26
  import { VPanel } from "./vpanel.ui";
27
- import { createWidget } from "./widget.builder.ui";
27
+ import { createWidget } from "./widget.builder";
28
28
  import { IconButtonMenu } from "./iconButtonMenu.ui";
29
29
 
30
30
  export type { ContainerParams };
31
31
 
32
32
  export {
33
+ Textbox,
33
34
  Accordion,
34
35
  Button,
35
36
  ButtonColor,
36
37
  ButtonMenu,
37
38
  ButtonStack,
39
+ IconButton,
40
+ IconButtonMenu,
38
41
  Checkbox,
39
42
  Container,
40
43
  Dialog,
41
44
  HPanel,
42
45
  Icon,
43
- IconButton,
44
- IconButtonMenu,
45
46
  Image,
46
47
  Label,
47
48
  Menu,
@@ -52,7 +53,6 @@ export {
52
53
  Switch,
53
54
  Tabs,
54
55
  TextArea,
55
- Textbox,
56
56
  Toolbar,
57
57
  ValueBar,
58
58
  VPanel,
@@ -0,0 +1,184 @@
1
+ import "./styles/label.css";
2
+ import { normalizeWidget, WidgetProps } from "./widget.builder";
3
+ import { Colors } from "./colors.ui";
4
+ import { Widget, connectWidgetCallback, getOnlyEventProps } from "./widget.ui";
5
+ import { UID } from "../core/uid";
6
+
7
+ export type LabelVariants = "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "p" | "span";
8
+
9
+ export class Label extends Widget {
10
+ variant: LabelVariants;
11
+ color: Colors;
12
+ text: string;
13
+
14
+ requiredWidth: number;
15
+
16
+ isHCentered: boolean;
17
+ isVCentered: boolean;
18
+
19
+ constructor(id: string, variant: LabelVariants = "span", parent: Widget | null = null) {
20
+ super(id, variant, parent);
21
+
22
+ this.requiredWidth = -1;
23
+
24
+ this.isHCentered = false;
25
+ this.isVCentered = false;
26
+
27
+ this.variant = variant;
28
+ this.color = "primary";
29
+ this.text = "";
30
+
31
+ this.setColor(this.color);
32
+
33
+ //this.getBody().style.margin = "0px";
34
+
35
+ this.setVariant(this.variant);
36
+
37
+ this.init();
38
+ }
39
+
40
+ public init(): void {
41
+ super.init();
42
+ }
43
+
44
+ private updateRequiredWidth(): void {
45
+ const div = document.createElement("div");
46
+ div.id = this.id + ".requiredWidth";
47
+ div.innerHTML = this.text;
48
+ div.classList.add("WUILabel" + this.variant);
49
+ div.classList.add("WUILabel-" + this.color);
50
+ div.style.position = "absolute";
51
+ div.style.overflow = "hidden";
52
+ document.body.appendChild(div);
53
+ this.requiredWidth = div.clientWidth;
54
+ div.parentNode?.removeChild(div);
55
+ }
56
+
57
+ public setHCentered(isHCentered: boolean = true): void {
58
+ this.isHCentered = isHCentered;
59
+ }
60
+
61
+ public setVCentered(isVCentered: boolean = true): void {
62
+ this.isVCentered = isVCentered;
63
+ }
64
+
65
+ public render(): void {
66
+ super.render();
67
+
68
+ if (this.isHCentered) {
69
+ this.centerH();
70
+ }
71
+ if (this.isVCentered) {
72
+ this.centerV();
73
+ }
74
+ }
75
+
76
+ private centerV(): void {
77
+ this.getBody().style.lineHeight = this.getH() + "px";
78
+ }
79
+
80
+ private centerH(): void {
81
+ this.getBody().style.textAlign = "center";
82
+ }
83
+
84
+ public setText(text: string): void {
85
+ this.text = text;
86
+ this.body.innerHTML = text;
87
+ this.updateRequiredWidth();
88
+ }
89
+
90
+ public setVariant(variant: LabelVariants = "span"): void {
91
+ if (this.variant !== variant) {
92
+ this.deleteClass("WUILabel" + this.variant);
93
+ }
94
+
95
+ this.variant = variant;
96
+ this.addClass("WUILabel-" + this.variant);
97
+ this.updateRequiredWidth();
98
+ }
99
+
100
+ public setColor(color: Colors = "primary"): void {
101
+ if (this.color !== color) {
102
+ this.deleteClass("WUILabel-" + this.color);
103
+ }
104
+ this.color = color;
105
+ this.addClass("WUILabel-" + this.color);
106
+ this.updateRequiredWidth();
107
+ }
108
+
109
+ public getVariant(): LabelVariants {
110
+ return this.variant;
111
+ }
112
+
113
+ public getColor(): Colors {
114
+ return this.color;
115
+ }
116
+
117
+ public getText(): string {
118
+ return this.text;
119
+ }
120
+
121
+ public getRequiredWidth(): number {
122
+ return this.requiredWidth;
123
+ }
124
+ }
125
+
126
+ export type wLabelProps = WidgetProps & {
127
+ variant?: string | null;
128
+ color?: Colors | null;
129
+ text?: string | null;
130
+ centerX?: boolean | null;
131
+ centerY?: boolean | null;
132
+ };
133
+
134
+ export const WLabel = (props: wLabelProps) => {
135
+ if (!props.id) {
136
+ props.id = "Label." + UID();
137
+ }
138
+
139
+ connectWidgetCallback(props.id, getOnlyEventProps(props));
140
+
141
+ return normalizeWidget(
142
+ <div
143
+ id={props.id}
144
+ w-label
145
+ w-text={props.text}
146
+ w-variant={props.variant}
147
+ w-color={props.color}
148
+ w-centerX={props.centerX}
149
+ w-centerY={props.centerY}
150
+ ></div>,
151
+ props
152
+ );
153
+ };
154
+
155
+ export function createLabel(id: string, content: any, parent: Widget | null = null): Label {
156
+ const dataText = content.getAttribute("w-text");
157
+ const dataVariant = content.getAttribute("w-variant");
158
+ const dataColor = content.getAttribute("w-color");
159
+ let tag = dataVariant ? dataVariant : "span";
160
+
161
+ let newLabel = new Label(id, tag, parent);
162
+
163
+ if (dataText) {
164
+ newLabel.setText(dataText);
165
+ }
166
+
167
+ if (dataVariant) {
168
+ newLabel.setVariant(dataVariant);
169
+ }
170
+
171
+ if (dataColor) {
172
+ newLabel.setColor(dataColor);
173
+ }
174
+
175
+ if (content.getAttribute("w-centerX")) {
176
+ newLabel.setHCentered(true);
177
+ }
178
+
179
+ if (content.getAttribute("w-centerY")) {
180
+ newLabel.setVCentered(true);
181
+ }
182
+
183
+ return newLabel;
184
+ }
@@ -1,10 +1,10 @@
1
- import "./styles/loading.css";
2
- import { Widget } from "./widget.ui";
3
-
4
- export class Loading extends Widget {
5
- constructor(id: string, parent: Widget | null = null) {
6
- super(id, "div", parent);
7
- this.addClass("WUILoading");
8
- this.setVisible(false);
9
- }
10
- }
1
+ import "./styles/loading.css";
2
+ import { Widget } from "./widget.ui";
3
+
4
+ export class Loading extends Widget {
5
+ constructor(id: string, parent: Widget | null = null) {
6
+ super(id, "div", parent);
7
+ this.addClass("WUILoading");
8
+ this.setVisible(false);
9
+ }
10
+ }
package/src/ui/menu.ui.ts CHANGED
@@ -101,7 +101,7 @@ export class Menu extends Widget {
101
101
  if (this.triggeredBy) {
102
102
  const position = this.triggeredBy.getPosition(false);
103
103
 
104
- const triggerW = this.triggeredBy.getBody().clientWidth;
104
+ //const triggerW = this.triggeredBy.getBody().clientWidth;
105
105
  const triggerH = this.triggeredBy.getBody().clientHeight;
106
106
 
107
107
  const screenW = window.innerWidth;
@@ -162,7 +162,7 @@ export class Menu extends Widget {
162
162
  newOption.setAlign(WidgetAlignTypes.VERTICAL);
163
163
  newOption.setText(label);
164
164
  newOption.setFixedSize(MENU_OPTION_HEIGHT);
165
- //newOption.addClass("WUIMenuOptions");
165
+ newOption.addClass("WUIMenuOptions"); //Esta linea estaba comentada. Con esto se soliciono el ancho del menu
166
166
  //newOption.setH(MENU_OPTION_HEIGHT);
167
167
 
168
168
  newOption.subscribe({
@@ -0,0 +1,135 @@
1
+ import { UID } from "../core/uid";
2
+ import { Label } from "./label.ui";
3
+ import "./styles/progressbar.css";
4
+ import { normalizeWidget, WidgetProps } from "./widget.builder";
5
+ import { Widget, WidgetTypes, connectWidgetCallback, getOnlyEventProps } from "./widget.ui";
6
+
7
+ const PROGRESS_BAR_HEIGHT = 40;
8
+
9
+ //icono para el progress bar interactivo humidity_high
10
+
11
+ export class ProgressBar extends Widget {
12
+ private value: number;
13
+ private paddingBar: number;
14
+
15
+ private bar: Widget;
16
+ private lblValue: Label;
17
+
18
+ public constructor(id: string, parent: Widget | null = null) {
19
+ super(id, "div", parent);
20
+
21
+ this.setH(PROGRESS_BAR_HEIGHT);
22
+
23
+ this.paddingBar = 0;
24
+
25
+ this.bar = new Widget(id + ".bar", "div", this);
26
+ this.bar.addClass("WUIProgressBarBar");
27
+
28
+ this.value = 0;
29
+ this.addClass("WUIProgressBarContainer");
30
+
31
+ this.lblValue = new Label(id + ".value", "span", this);
32
+ this.lblValue.setType(WidgetTypes.CUSTOM);
33
+ this.lblValue.setVCentered(true);
34
+ this.lblValue.setHCentered(true);
35
+ this.lblValue.setText(this.value + "%");
36
+
37
+ this.lblValue.addClass("WUIProgressBarLabel");
38
+ }
39
+
40
+ public setPaddingBar(p: number): void {
41
+ this.paddingBar = p;
42
+ }
43
+
44
+ public hideLabel(): void {
45
+ this.lblValue.setVisible(false);
46
+ }
47
+
48
+ public displayLabel(): void {
49
+ this.lblValue.setVisible(true);
50
+ }
51
+
52
+ public render(): void {
53
+ super.render();
54
+
55
+ const padding = this.paddingBar;
56
+ const width = this.getW() - padding;
57
+ const height = this.getH();
58
+ const widthBar = width * (this.value / 100);
59
+
60
+ this.lblValue.setX(padding);
61
+ this.lblValue.setY(0);
62
+ this.lblValue.setW(width);
63
+ this.lblValue.setH(height);
64
+ this.lblValue.raisteTop();
65
+ this.lblValue.render();
66
+
67
+ this.bar.setX(padding);
68
+ this.bar.setY(padding);
69
+ this.bar.setW(widthBar);
70
+ this.bar.setH(height - padding * 2);
71
+ }
72
+
73
+ public setValue(value: number): void {
74
+ this.value = value;
75
+ this.lblValue.setText(this.value + "%");
76
+ this.render();
77
+ }
78
+
79
+ public getValue(): number {
80
+ return this.value;
81
+ }
82
+ }
83
+
84
+ export type wProgressBarProps = WidgetProps & {
85
+ value: number;
86
+ paddingBar?: number | null;
87
+ hideLabel?: boolean | null;
88
+ };
89
+
90
+ export const WProgressBar = (props: wProgressBarProps) => {
91
+ if (!props.id) {
92
+ props.id = "ProgressBar." + UID();
93
+ }
94
+
95
+ connectWidgetCallback(props.id, getOnlyEventProps(props));
96
+
97
+ return normalizeWidget(
98
+ <div
99
+ id={props.id}
100
+ w-progressbar
101
+ w-value={props.value}
102
+ w-padding-bar={props.paddingBar}
103
+ w-hide-label={props.hideLabel}
104
+ ></div>,
105
+ props
106
+ );
107
+ };
108
+
109
+ export function createProgressBar(
110
+ id: string,
111
+ content: any,
112
+ parent: Widget | null = null
113
+ ): ProgressBar {
114
+ let newProgressBar = new ProgressBar(id, parent);
115
+
116
+ const dataValue = content.getAttribute("w-value");
117
+ const dataPaddingBar = content.getAttribute("w-padding-bar");
118
+ const dataHideLabel = content.getAttribute("w-hide-label");
119
+
120
+ if (dataValue) {
121
+ newProgressBar.setValue(parseInt(dataValue));
122
+ }
123
+
124
+ if (dataPaddingBar) {
125
+ newProgressBar.setPaddingBar(parseInt(dataPaddingBar));
126
+ }
127
+
128
+ if (dataHideLabel !== null) {
129
+ newProgressBar.hideLabel();
130
+ } else {
131
+ newProgressBar.displayLabel();
132
+ }
133
+
134
+ return newProgressBar;
135
+ }
@@ -0,0 +1,47 @@
1
+ import { UID } from "../core/uid";
2
+ import { ToggleButton } from "./toggle.ui";
3
+ import { normalizeWidget, WidgetProps } from "./widget.builder";
4
+ import { Widget, connectWidgetCallback, getOnlyEventProps } from "./widget.ui";
5
+
6
+ export class RadioButton extends ToggleButton {
7
+ constructor(id: string, text: string = "", parent: Widget | null = null) {
8
+ super(id, text, "radio_button_checked", "radio_button_unchecked", parent);
9
+ }
10
+ }
11
+
12
+ export type wRadioButtonProps = WidgetProps & {
13
+ text: string;
14
+ checked?: boolean | null;
15
+ };
16
+
17
+ export const WRadioButton = (props: wRadioButtonProps) => {
18
+ if (!props.id) {
19
+ props.id = "RadioButton." + UID();
20
+ }
21
+
22
+ connectWidgetCallback(props.id, getOnlyEventProps(props));
23
+
24
+ return normalizeWidget(
25
+ <div id={props.id} w-radiobutton w-text={props.text} w-checked={props.checked} />,
26
+ props
27
+ );
28
+ };
29
+
30
+ export function createRadioButton(
31
+ id: string,
32
+ content: any,
33
+ parent: Widget | null = null
34
+ ): RadioButton {
35
+ const dataText = content.getAttribute("w-text");
36
+ const dataChecked = content.getAttribute("w-checked");
37
+
38
+ let newRadioButton = new RadioButton(id, dataText, parent);
39
+
40
+ if (dataChecked !== null) {
41
+ newRadioButton.setState(true);
42
+ } else {
43
+ newRadioButton.setState(false);
44
+ }
45
+
46
+ return newRadioButton;
47
+ }
@@ -25,7 +25,7 @@ export class Scroll extends Widget {
25
25
  drag: Draggable;
26
26
 
27
27
  constructor(id: string, contentArea: Widget, orientation: OrientationTypes = "vertical") {
28
- super(id, "div", contentArea.getParent());
28
+ super(id, "div");
29
29
 
30
30
  this.contentArea = contentArea;
31
31
  this.orientation = orientation;
@@ -33,7 +33,7 @@ export class Scroll extends Widget {
33
33
  this.setType(WidgetTypes.CUSTOM);
34
34
 
35
35
  this.getBody().style.overflow = "hidden";
36
- this.getBody().style.position = "absolute";
36
+ this.getBody().style.position = "fixed";
37
37
 
38
38
  this.addClass("WUIScrollbar");
39
39
 
@@ -110,14 +110,15 @@ export class Scroll extends Widget {
110
110
  if (this.orientation === "vertical") {
111
111
  const recorrido = scrollData.scrollHeight - scrollData.areaHeight;
112
112
  const maxY = this.drag.maxY ? this.drag.maxY : 1;
113
- const ratio = (this.getY() - this.contentArea.getY()) / maxY;
113
+ const ratio = (this.getY() - this.contentArea.getY(true)) / maxY;
114
114
  this.contentArea.getBody().scrollTop = recorrido * ratio;
115
115
  } else if (this.orientation === "horizontal") {
116
116
  const recorrido = scrollData.scrollWidth - scrollData.areaWidth;
117
117
  const maxX = this.drag.maxX ? this.drag.maxX : 1;
118
- const ratio = (this.getX() - this.contentArea.getX()) / maxX;
118
+ const ratio = (this.getX() - this.contentArea.getX(true)) / maxX;
119
119
  this.contentArea.getBody().scrollLeft = recorrido * ratio;
120
120
  }
121
+ this.run("scroll");
121
122
  }
122
123
 
123
124
  public render(): void {
@@ -133,14 +134,14 @@ export class Scroll extends Widget {
133
134
  return;
134
135
  }
135
136
 
136
- this.setX(this.contentArea.getX() + this.contentArea.getW() - SCROLL_SIZE - 1);
137
- this.setY(1 + this.contentArea.getY() + scrollData.position);
137
+ this.setX(this.contentArea.getX(true) + this.contentArea.getW() - SCROLL_SIZE - 1);
138
+ this.setY(1 + this.contentArea.getY(true) + scrollData.position);
138
139
  this.setH(scrollData.scrollBarHeight);
139
140
  this.setW(SCROLL_SIZE);
140
141
  this.raisteTop();
141
142
 
142
- const minY = 1 + this.contentArea.getY();
143
- const maxY = this.contentArea.getY() + scrollData.availablePositionSize;
143
+ const minY = 1 + this.contentArea.getY(true);
144
+ const maxY = this.contentArea.getY(true) + scrollData.availablePositionSize;
144
145
 
145
146
  this.drag.setMinY(minY);
146
147
  this.drag.setMaxY(maxY);
@@ -160,14 +161,14 @@ export class Scroll extends Widget {
160
161
  return;
161
162
  }
162
163
 
163
- this.setX(1 + this.contentArea.getX() + scrollData.position);
164
- this.setY(scrollData.scrollPositionY - SCROLL_SIZE - 1);
164
+ this.setX(1 + this.contentArea.getX(true) + scrollData.position);
165
+ this.setY(this.contentArea.getY(true) + scrollData.scrollPositionY - SCROLL_SIZE - 1);
165
166
  this.setW(scrollData.scrollBarWidth);
166
167
  this.setH(SCROLL_SIZE);
167
168
  this.raisteTop();
168
169
 
169
- const minX = 1 + this.contentArea.getX();
170
- const maxX = this.contentArea.getX() + scrollData.availablePositionSize;
170
+ const minX = 1 + this.contentArea.getX(true);
171
+ const maxX = this.contentArea.getX(true) + scrollData.availablePositionSize;
171
172
 
172
173
  this.drag.setMinX(minX);
173
174
  this.drag.setMaxX(maxX);
@@ -0,0 +1,143 @@
1
+ import "./styles/select.css";
2
+ import { IconButton } from "./IconButton.ui";
3
+ import { Menu } from "./menu.ui";
4
+ import { Widget } from "./widget.ui";
5
+ import { SelectItem } from "../types/select.item.type";
6
+ import { normalizeWidget, WidgetProps } from "./widget.builder";
7
+ import { UID } from "../core/uid";
8
+
9
+ export class Select extends Widget {
10
+ menu: Menu;
11
+ text: string;
12
+ title: string;
13
+
14
+ items: SelectItem[];
15
+
16
+ selectedItem: SelectItem | null;
17
+
18
+ constructor(id: string, parent: Widget | null = null) {
19
+ super(id, "div", parent);
20
+ this.menu = new Menu(this.id + ".menu", this.id, null);
21
+ this.text = "";
22
+ this.title = "";
23
+ this.addClass("WUISelect");
24
+ this.items = [];
25
+ this.selectedItem = null;
26
+ this.subscribe({
27
+ event: "click",
28
+ then: () => {
29
+ this.menu.clearOptions();
30
+ this.items.forEach((item) => {
31
+ this.menu.addOption(item.id, item.icon, item.label);
32
+ });
33
+
34
+ this.menu.wakeUp();
35
+
36
+ if (this.getBody().clientWidth > this.menu.getBody().clientWidth) {
37
+ this.menu.setW(this.getBody().clientWidth);
38
+ this.menu.resize();
39
+ }
40
+ },
41
+ });
42
+
43
+ this.menu.subscribe({
44
+ event: "option-clicked",
45
+ then: (_e, clickedOption) => {
46
+ const option = clickedOption as IconButton;
47
+
48
+ const fintOption = this.items.find((item) => item.id === option.id);
49
+
50
+ if (fintOption) {
51
+ this.selectedItem = fintOption;
52
+ }
53
+
54
+ const selectedText = this.selectedItem?.label;
55
+ if (selectedText) {
56
+ this.setValue(selectedText);
57
+ } else {
58
+ this.setValue("");
59
+ }
60
+ },
61
+ });
62
+ }
63
+
64
+ public setValue(value: string) {
65
+ this.text = value;
66
+ }
67
+
68
+ public setTitle(title: string) {
69
+ this.title = title;
70
+ }
71
+
72
+ addItem(id: string, label: string, icon: string) {
73
+ this.items.push(new SelectItem(id, label, icon));
74
+ }
75
+ }
76
+
77
+ export type WSelectProps = WidgetProps & {
78
+ title?: string;
79
+ value?: string;
80
+ children: any;
81
+ };
82
+
83
+ export type WSelectItemProps = {
84
+ id: string;
85
+ label?: string | null;
86
+ icon?: string | null;
87
+ };
88
+
89
+ export const WSelect = (props: WSelectProps) => {
90
+ if (!props.id) {
91
+ props.id = "Select." + UID();
92
+ }
93
+
94
+ return normalizeWidget(
95
+ <div id={props.id} w-select w-title={props.title} w-value={props.value}>
96
+ {props.children}
97
+ </div>,
98
+ props
99
+ );
100
+ };
101
+
102
+ export const WSelectItem = (props: WSelectItemProps) => {
103
+ return <div w-select-item id={props.id} w-label={props.label} w-icon={props.icon}></div>;
104
+ };
105
+
106
+ export function createSelect(id: string, content: any, parent: Widget | null = null): Select {
107
+ let newSelect = new Select(id, parent);
108
+
109
+ const dataTitle = content.getAttribute("w-title");
110
+ const dataValue = content.getAttribute("w-value");
111
+ const dataWidth = content.getAttribute("w-width");
112
+ const dataHeight = content.getAttribute("w-height");
113
+
114
+ if (dataTitle) {
115
+ newSelect.setTitle(dataTitle);
116
+ }
117
+
118
+ if (dataValue) {
119
+ newSelect.setValue(dataValue);
120
+ }
121
+
122
+ if (dataWidth) {
123
+ newSelect.setInitialW(dataWidth);
124
+ }
125
+
126
+ if (dataHeight) {
127
+ newSelect.setInitialH(dataHeight);
128
+ }
129
+
130
+ content.childNodes.forEach((menuItem: HTMLElement, index: number) => {
131
+ if (menuItem.getAttribute("w-select-item") !== null) {
132
+ const itemId = menuItem.getAttribute("id");
133
+ const itemLabel = menuItem.getAttribute("w-label");
134
+ const itemIcon = menuItem.getAttribute("w-icon");
135
+
136
+ if (itemId !== null) {
137
+ newSelect.addItem(itemId, itemLabel || "Unnamed" + index, itemIcon || "");
138
+ }
139
+ }
140
+ });
141
+
142
+ return newSelect;
143
+ }