@web-atoms/web-controls 2.3.55 → 2.3.57
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/dist/animations/Animations.d.ts +2 -2
- package/dist/animations/Animations.d.ts.map +1 -1
- package/dist/basic/Calendar.d.ts.map +1 -1
- package/dist/basic/Calendar.js +8 -9
- package/dist/basic/Calendar.js.map +1 -1
- package/dist/basic/DateField.d.ts.map +1 -1
- package/dist/basic/DateField.js +13 -40
- package/dist/basic/DateField.js.map +1 -1
- package/dist/basic/Select.d.ts +9 -0
- package/dist/basic/Select.d.ts.map +1 -0
- package/dist/basic/Select.js +78 -0
- package/dist/basic/Select.js.map +1 -0
- package/dist/basic/TimeEditor.d.ts +11 -0
- package/dist/basic/TimeEditor.d.ts.map +1 -0
- package/dist/basic/TimeEditor.js +138 -0
- package/dist/basic/TimeEditor.js.map +1 -0
- package/dist/basic/TitleEditor.d.ts +3 -3
- package/dist/basic/TitleEditor.d.ts.map +1 -1
- package/dist/basic/TitleEditor.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/basic/Calendar.tsx +4 -4
- package/src/basic/DateField.tsx +10 -33
- package/src/basic/Select.tsx +74 -0
- package/src/basic/TimeEditor.tsx +135 -0
- package/src/basic/TitleEditor.tsx +14 -14
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { AtomBinder } from "@web-atoms/core/dist/core/AtomBinder";
|
|
2
|
+
import XNode from "@web-atoms/core/dist/core/XNode";
|
|
3
|
+
import StyleRule from "@web-atoms/core/dist/style/StyleRule";
|
|
4
|
+
import { AtomControl } from "@web-atoms/core/dist/web/controls/AtomControl";
|
|
5
|
+
import { descendentElementIterator } from "@web-atoms/core/dist/web/core/AtomUI";
|
|
6
|
+
import CSS from "@web-atoms/core/dist/web/styles/CSS";
|
|
7
|
+
import TimeSpan from "@web-atoms/date-time/dist/TimeSpan";
|
|
8
|
+
import Select from "./Select";
|
|
9
|
+
import Bind from "@web-atoms/core/dist/core/Bind";
|
|
10
|
+
|
|
11
|
+
function hours() {
|
|
12
|
+
return [
|
|
13
|
+
{ label: "01", value: 1 },
|
|
14
|
+
{ label: "02", value: 2 },
|
|
15
|
+
{ label: "03", value: 3 },
|
|
16
|
+
{ label: "04", value: 4 },
|
|
17
|
+
{ label: "05", value: 5 },
|
|
18
|
+
{ label: "06", value: 6 },
|
|
19
|
+
{ label: "07", value: 7 },
|
|
20
|
+
{ label: "08", value: 8 },
|
|
21
|
+
{ label: "09", value: 9 },
|
|
22
|
+
{ label: "10", value: 10 },
|
|
23
|
+
{ label: "11", value: 11 },
|
|
24
|
+
{ label: "12", value: 12 },
|
|
25
|
+
];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function minutes() {
|
|
29
|
+
const items = [];
|
|
30
|
+
for (let index = 0; index < 10; index++) {
|
|
31
|
+
items.push({ label: "0" + index, value: index });
|
|
32
|
+
}
|
|
33
|
+
for (let index = 10; index < 60; index++) {
|
|
34
|
+
items.push({ label: index.toString(), value: index });
|
|
35
|
+
}
|
|
36
|
+
return items;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
CSS(StyleRule()
|
|
40
|
+
.paddingLeft(5)
|
|
41
|
+
.gridRow("2")
|
|
42
|
+
.flexLayout({ direction: "row", alignItems: "center", justifyContent: "start" as any, gap: 0})
|
|
43
|
+
.child(StyleRule("[data-element=hour]")
|
|
44
|
+
.marginLeft(5)
|
|
45
|
+
.marginRight(5)
|
|
46
|
+
)
|
|
47
|
+
.child(StyleRule("[data-element=minute]")
|
|
48
|
+
.marginRight(5)
|
|
49
|
+
)
|
|
50
|
+
.child(StyleRule("[data-element=pm]")
|
|
51
|
+
.marginRight(5)
|
|
52
|
+
)
|
|
53
|
+
.child(StyleRule("button")
|
|
54
|
+
.borderRadius(9999)
|
|
55
|
+
.outline("none")
|
|
56
|
+
.border("none")
|
|
57
|
+
.backgroundColor("transparent")
|
|
58
|
+
.and(StyleRule("[data-selected=true]")
|
|
59
|
+
.backgroundColor("var(--accent-color, blue)")
|
|
60
|
+
.color("var(--accent-text-color, white)")
|
|
61
|
+
)
|
|
62
|
+
)
|
|
63
|
+
.child(StyleRule("button[data-element=am]")
|
|
64
|
+
.borderTopRightRadius(0)
|
|
65
|
+
.borderBottomRightRadius(0)
|
|
66
|
+
)
|
|
67
|
+
.child(StyleRule("button[data-element=pm]")
|
|
68
|
+
.borderTopLeftRadius(0)
|
|
69
|
+
.borderBottomLeftRadius(0)
|
|
70
|
+
)
|
|
71
|
+
.child(StyleRule("select")
|
|
72
|
+
.border("none")
|
|
73
|
+
.outline("none")
|
|
74
|
+
),"[data-time-editor]");
|
|
75
|
+
|
|
76
|
+
export default class TimeEditor extends AtomControl {
|
|
77
|
+
|
|
78
|
+
// private time: TimeSpan;
|
|
79
|
+
|
|
80
|
+
public get time(): TimeSpan {
|
|
81
|
+
let t = new TimeSpan(0, this.hour, this.minute);
|
|
82
|
+
if (this.isPM) {
|
|
83
|
+
t = t.add(TimeSpan.fromHours(12));
|
|
84
|
+
}
|
|
85
|
+
return t;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
public set time(v: TimeSpan) {
|
|
89
|
+
if(!v) {
|
|
90
|
+
v = TimeSpan.fromSeconds(0);
|
|
91
|
+
}
|
|
92
|
+
let h = v.hours;
|
|
93
|
+
if (h > 12) {
|
|
94
|
+
h -= 12;
|
|
95
|
+
this.isPM = true;
|
|
96
|
+
}
|
|
97
|
+
this.hour = h;
|
|
98
|
+
this.minute = v.minutes;
|
|
99
|
+
AtomBinder.refreshValue(this, "time");
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
public hour: number;
|
|
103
|
+
|
|
104
|
+
public minute: number;
|
|
105
|
+
|
|
106
|
+
public isPM: boolean;
|
|
107
|
+
|
|
108
|
+
protected create(): void {
|
|
109
|
+
this.isPM = false;
|
|
110
|
+
this.hour = 12;
|
|
111
|
+
this.minute = 0;
|
|
112
|
+
this.render(<div
|
|
113
|
+
data-time-editor="time-editor"
|
|
114
|
+
event-change={() => setTimeout(() => AtomBinder.refreshValue(this, "time"), 1)}>
|
|
115
|
+
<Select
|
|
116
|
+
data-element="hour"
|
|
117
|
+
items={hours()}
|
|
118
|
+
value={Bind.twoWays(() => this.hour)}/>
|
|
119
|
+
<Select
|
|
120
|
+
data-element="minute" items={minutes()}
|
|
121
|
+
value={Bind.twoWays(() => this.minute)}/>
|
|
122
|
+
<button
|
|
123
|
+
event-click={() => (this.isPM = false, AtomBinder.refreshValue(this, "time"))}
|
|
124
|
+
data-selected={Bind.oneWay(() => !this.isPM)}
|
|
125
|
+
data-element="am"
|
|
126
|
+
text="AM"/>
|
|
127
|
+
<button
|
|
128
|
+
event-click={() => (this.isPM = true, AtomBinder.refreshValue(this, "time"))}
|
|
129
|
+
data-selected={Bind.oneWay(() => this.isPM)}
|
|
130
|
+
data-element="pm"
|
|
131
|
+
text="PM"/>
|
|
132
|
+
</div>);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
}
|
|
@@ -35,17 +35,17 @@ CSS(StyleRule()
|
|
|
35
35
|
|
|
36
36
|
export type Capitalize = "none" | "off" | "on" | "sentences" | "words" | "characters";
|
|
37
37
|
|
|
38
|
-
export interface
|
|
38
|
+
export interface ITitleEditor extends IElement {
|
|
39
39
|
value?: any;
|
|
40
40
|
type?: any;
|
|
41
41
|
placeholder?: any;
|
|
42
42
|
/**
|
|
43
43
|
* Off - turn off,
|
|
44
|
-
* On - Sentence
|
|
44
|
+
* On - Sentence capitalization
|
|
45
45
|
* Word - Capitalize first character of every word
|
|
46
46
|
* Characters - Capitalize everything
|
|
47
47
|
*/
|
|
48
|
-
capitalize?: Capitalize
|
|
48
|
+
capitalize?: Capitalize;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
const paste = (e: ClipboardEvent) => {
|
|
@@ -57,17 +57,17 @@ const paste = (e: ClipboardEvent) => {
|
|
|
57
57
|
setTimeout(() => {
|
|
58
58
|
const start = input.selectionStart;
|
|
59
59
|
const end = input.selectionEnd;
|
|
60
|
-
formatText(input, capitalize)
|
|
61
|
-
input.setSelectionRange(start, end);
|
|
60
|
+
formatText(input, capitalize);
|
|
61
|
+
input.setSelectionRange(start, end);
|
|
62
62
|
}, 1);
|
|
63
63
|
};
|
|
64
64
|
|
|
65
65
|
const formatText = (input: HTMLInputElement, capitalize: Capitalize, all = true) => {
|
|
66
66
|
let value = input.value;
|
|
67
|
-
if(!value) {
|
|
67
|
+
if (!value) {
|
|
68
68
|
return;
|
|
69
69
|
}
|
|
70
|
-
switch(capitalize) {
|
|
70
|
+
switch (capitalize) {
|
|
71
71
|
case "on":
|
|
72
72
|
case "sentences":
|
|
73
73
|
if (value.length === 1) {
|
|
@@ -86,7 +86,7 @@ const formatText = (input: HTMLInputElement, capitalize: Capitalize, all = true)
|
|
|
86
86
|
break;
|
|
87
87
|
}
|
|
88
88
|
input.value = value;
|
|
89
|
-
}
|
|
89
|
+
};
|
|
90
90
|
|
|
91
91
|
const capitalizeText = /android|iPhone|iOS/i.test(navigator.userAgent)
|
|
92
92
|
? () => undefined
|
|
@@ -100,10 +100,10 @@ const capitalizeText = /android|iPhone|iOS/i.test(navigator.userAgent)
|
|
|
100
100
|
const end = input.selectionEnd;
|
|
101
101
|
formatText(input, capitalize, false);
|
|
102
102
|
input.setSelectionRange(start, end);
|
|
103
|
-
}
|
|
103
|
+
};
|
|
104
104
|
|
|
105
105
|
const toText = (capitalize: Capitalize) => {
|
|
106
|
-
switch(capitalize) {
|
|
106
|
+
switch (capitalize) {
|
|
107
107
|
case "off":
|
|
108
108
|
case "none":
|
|
109
109
|
return "Caps Off";
|
|
@@ -116,7 +116,7 @@ const toText = (capitalize: Capitalize) => {
|
|
|
116
116
|
return "Title Case";
|
|
117
117
|
}
|
|
118
118
|
return "";
|
|
119
|
-
}
|
|
119
|
+
};
|
|
120
120
|
|
|
121
121
|
const changeCase = (e: MouseEvent) => {
|
|
122
122
|
let element = e.target as HTMLElement;
|
|
@@ -126,7 +126,7 @@ const changeCase = (e: MouseEvent) => {
|
|
|
126
126
|
const input = element.previousElementSibling as HTMLInputElement;
|
|
127
127
|
const span = element.nextElementSibling;
|
|
128
128
|
let capitalize = input.autocapitalize as Capitalize;
|
|
129
|
-
switch(capitalize) {
|
|
129
|
+
switch (capitalize) {
|
|
130
130
|
case "sentences":
|
|
131
131
|
capitalize = "words";
|
|
132
132
|
break;
|
|
@@ -151,7 +151,7 @@ export default function TitleEditor({
|
|
|
151
151
|
placeholder,
|
|
152
152
|
capitalize = "on",
|
|
153
153
|
... a
|
|
154
|
-
}:
|
|
154
|
+
}: ITitleEditor) {
|
|
155
155
|
return <div
|
|
156
156
|
data-title-editor="title-editor" { ... a}>
|
|
157
157
|
<input
|
|
@@ -169,4 +169,4 @@ export default function TitleEditor({
|
|
|
169
169
|
text={toText(capitalize)}
|
|
170
170
|
event-click={changeCase}/>
|
|
171
171
|
</div>;
|
|
172
|
-
}
|
|
172
|
+
}
|