cedro 0.1.0
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.
- package/LICENSE +21 -0
- package/README.md +5 -0
- package/index.html +13 -0
- package/package.json +18 -0
- package/src/core/application.core.ts +182 -0
- package/src/core/index.ts +8 -0
- package/src/core/jsxsupport.ts +100 -0
- package/src/core/screeen.core.ts +81 -0
- package/src/core/seo.ts +79 -0
- package/src/core/themes.core.ts +237 -0
- package/src/index.ts +16 -0
- package/src/interfaces/application.interface.ts +45 -0
- package/src/interfaces/screen.interface.ts +17 -0
- package/src/interfaces/themes.interface.ts +19 -0
- package/src/interfaces/widget.interface.ts +123 -0
- package/src/types/vector2d.type.ts +4 -0
- package/src/ui/Icon.ui.ts +70 -0
- package/src/ui/IconButton.ui.ts +70 -0
- package/src/ui/button.ui.ts +88 -0
- package/src/ui/colors.ui.ts +7 -0
- package/src/ui/dialog.tsx +398 -0
- package/src/ui/index.ts +24 -0
- package/src/ui/label.ui.ts +61 -0
- package/src/ui/menu.ui.ts +192 -0
- package/src/ui/select.ui.ts +74 -0
- package/src/ui/styles/button.css +237 -0
- package/src/ui/styles/dialog.css +48 -0
- package/src/ui/styles/main.css +93 -0
- package/src/ui/styles/menu.css +56 -0
- package/src/ui/styles/textbox.css +35 -0
- package/src/ui/styles/theme/dark.css +37 -0
- package/src/ui/styles/theme/light.css +37 -0
- package/src/ui/textbox.ui.ts +132 -0
- package/src/ui/widget.builder.ui.tsx +676 -0
- package/src/ui/widget.collection.ts +19 -0
- package/src/ui/widget.ui.ts +832 -0
- package/tsconfig.json +30 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import "./styles/textbox.css";
|
|
2
|
+
import { Widget, WidgetTypes } from "./widget.ui";
|
|
3
|
+
|
|
4
|
+
export type InputTypes =
|
|
5
|
+
| "text"
|
|
6
|
+
| "number"
|
|
7
|
+
| "password"
|
|
8
|
+
| "email"
|
|
9
|
+
| "url"
|
|
10
|
+
| "tel";
|
|
11
|
+
|
|
12
|
+
export class Textbox extends Widget {
|
|
13
|
+
input: Widget;
|
|
14
|
+
label: Widget;
|
|
15
|
+
inputType: string;
|
|
16
|
+
title: string;
|
|
17
|
+
|
|
18
|
+
constructor(id: string, parent: Widget | null = null) {
|
|
19
|
+
super(id, "div", parent);
|
|
20
|
+
|
|
21
|
+
this.addClass("WUIinput");
|
|
22
|
+
|
|
23
|
+
this.title = "";
|
|
24
|
+
this.inputType = "text";
|
|
25
|
+
|
|
26
|
+
const inputId = `WUI.${id}.input.body`;
|
|
27
|
+
|
|
28
|
+
this.label = new Widget(id + ".label", "label", this);
|
|
29
|
+
this.label.setType(WidgetTypes.CUSTOM);
|
|
30
|
+
|
|
31
|
+
this.label.getBody().setAttribute("for", inputId);
|
|
32
|
+
|
|
33
|
+
this.input = new Widget(id + ".input", "input", this);
|
|
34
|
+
this.input.setType(WidgetTypes.CUSTOM);
|
|
35
|
+
this.input.getBody().setAttribute("name", inputId);
|
|
36
|
+
this.input.getBody().setAttribute("type", this.inputType);
|
|
37
|
+
|
|
38
|
+
this.input.getBody().addEventListener("focus", () => {
|
|
39
|
+
this.moveLabelToTop();
|
|
40
|
+
//this.label.setVisible(false);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
this.input.getBody().addEventListener("blur", () => {
|
|
44
|
+
this.label.setVisible(true);
|
|
45
|
+
this.positionLabel();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
this.getBody().style.overflow = "";
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
getValue(): string {
|
|
52
|
+
const value = (this.input.getBody() as HTMLInputElement).value;
|
|
53
|
+
|
|
54
|
+
if (value) return value;
|
|
55
|
+
|
|
56
|
+
return "";
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
setValue(value: string): void {
|
|
60
|
+
(this.input.getBody() as HTMLInputElement).value = value;
|
|
61
|
+
this.positionLabel();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public init(): void {
|
|
65
|
+
super.init();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public moveLabelToTop(): void {
|
|
69
|
+
const labelHeight = this.label.getBody().clientHeight;
|
|
70
|
+
this.label.setY(-labelHeight / 2);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
private positionLabel(): void {
|
|
74
|
+
if (this.getValue() === "") {
|
|
75
|
+
this.moveLabelToCenter();
|
|
76
|
+
} else {
|
|
77
|
+
this.moveLabelToTop();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
public moveLabelToCenter(): void {
|
|
82
|
+
const labelHeight = this.label.getBody().clientHeight;
|
|
83
|
+
const labelTop = this.getH() / 2 - labelHeight / 2;
|
|
84
|
+
|
|
85
|
+
this.label.setY(labelTop);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
public render(): void {
|
|
89
|
+
const parent = this.getParent();
|
|
90
|
+
|
|
91
|
+
if (parent) {
|
|
92
|
+
if (parent.type === WidgetTypes.FREE) {
|
|
93
|
+
this.setWH(this.initialWidth, this.initialHeight);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
this.getBody().style.overflow = "";
|
|
98
|
+
this.label.getBody().style.position = "absolute";
|
|
99
|
+
|
|
100
|
+
this.positionLabel();
|
|
101
|
+
this.input.setWH(this.getW(), this.getH());
|
|
102
|
+
this.input.render();
|
|
103
|
+
|
|
104
|
+
super.render();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
setTitle(title: string): void {
|
|
108
|
+
this.title = title;
|
|
109
|
+
this.label.getBody().innerHTML = this.title;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
setInputType(type: InputTypes): void {
|
|
113
|
+
this.inputType = type;
|
|
114
|
+
this.input.getBody().setAttribute("type", this.inputType);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
getTitle(): string {
|
|
118
|
+
return this.title;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/*getLabel(): Widget {
|
|
122
|
+
return this.label;
|
|
123
|
+
}*/
|
|
124
|
+
|
|
125
|
+
getInput(): Widget {
|
|
126
|
+
return this.input;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
getInputType(): string {
|
|
130
|
+
return this.inputType;
|
|
131
|
+
}
|
|
132
|
+
}
|