godown 3.0.0 → 3.0.1
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/build/godown+lit.iife.js +12 -12
- package/build/godown+lit.iife.js.map +1 -1
- package/build/godown+lit.js +12 -12
- package/build/godown+lit.js.map +1 -1
- package/build/godown+lit.umd.js +12 -12
- package/build/godown+lit.umd.js.map +1 -1
- package/build/godown.iife.js +11 -11
- package/build/godown.js +11 -11
- package/build/godown.js.map +1 -1
- package/build/godown.umd.js +11 -11
- package/build/godown.umd.js.map +1 -1
- package/components/alert.d.ts.map +1 -1
- package/components/alert.js +1 -1
- package/components/alert.js.map +1 -1
- package/components/avatar.d.ts.map +1 -1
- package/components/avatar.js +1 -1
- package/components/avatar.js.map +1 -1
- package/components/badge.d.ts.map +1 -1
- package/components/badge.js +1 -1
- package/components/badge.js.map +1 -1
- package/components/breath.d.ts.map +1 -1
- package/components/breath.js +1 -1
- package/components/breath.js.map +1 -1
- package/components/button.d.ts.map +1 -1
- package/components/button.js +1 -1
- package/components/button.js.map +1 -1
- package/components/card.d.ts.map +1 -1
- package/components/card.js +1 -1
- package/components/card.js.map +1 -1
- package/components/carousel.d.ts.map +1 -1
- package/components/carousel.js +1 -1
- package/components/carousel.js.map +1 -1
- package/components/details.d.ts.map +1 -1
- package/components/details.js +1 -1
- package/components/details.js.map +1 -1
- package/components/dialog.d.ts.map +1 -1
- package/components/dialog.js +1 -1
- package/components/dialog.js.map +1 -1
- package/components/divider.d.ts.map +1 -1
- package/components/divider.js +1 -1
- package/components/divider.js.map +1 -1
- package/components/dragbox.d.ts.map +1 -1
- package/components/dragbox.js +1 -1
- package/components/dragbox.js.map +1 -1
- package/components/flex.d.ts.map +1 -1
- package/components/flex.js.map +1 -1
- package/components/form.d.ts.map +1 -1
- package/components/form.js.map +1 -1
- package/components/grid.d.ts.map +1 -1
- package/components/grid.js.map +1 -1
- package/components/heading.d.ts.map +1 -1
- package/components/heading.js +1 -1
- package/components/heading.js.map +1 -1
- package/components/input.d.ts.map +1 -1
- package/components/input.js +1 -1
- package/components/input.js.map +1 -1
- package/components/layout.d.ts.map +1 -1
- package/components/layout.js +1 -1
- package/components/layout.js.map +1 -1
- package/components/link.js.map +1 -1
- package/components/progress.d.ts.map +1 -1
- package/components/progress.js +1 -1
- package/components/progress.js.map +1 -1
- package/components/range.d.ts.map +1 -1
- package/components/range.js +1 -1
- package/components/range.js.map +1 -1
- package/components/rotate.d.ts.map +1 -1
- package/components/rotate.js +1 -1
- package/components/rotate.js.map +1 -1
- package/components/router.d.ts +20 -25
- package/components/router.d.ts.map +1 -1
- package/components/router.js +1 -1
- package/components/router.js.map +1 -1
- package/components/select.d.ts.map +1 -1
- package/components/select.js +1 -1
- package/components/select.js.map +1 -1
- package/components/skeleton.d.ts.map +1 -1
- package/components/skeleton.js +1 -1
- package/components/skeleton.js.map +1 -1
- package/components/split.d.ts.map +1 -1
- package/components/split.js +1 -1
- package/components/split.js.map +1 -1
- package/components/switch.d.ts.map +1 -1
- package/components/switch.js +1 -1
- package/components/switch.js.map +1 -1
- package/components/text.d.ts.map +1 -1
- package/components/text.js +1 -1
- package/components/text.js.map +1 -1
- package/components/time.d.ts.map +1 -1
- package/components/time.js.map +1 -1
- package/components/tooltip.d.ts.map +1 -1
- package/components/tooltip.js +1 -1
- package/components/tooltip.js.map +1 -1
- package/components/typewriter.d.ts.map +1 -1
- package/components/typewriter.js +1 -1
- package/components/typewriter.js.map +1 -1
- package/core/global-style.d.ts.map +1 -1
- package/core/global-style.js +1 -1
- package/core/global-style.js.map +1 -1
- package/core/super-anchor.d.ts.map +1 -1
- package/core/super-anchor.js +1 -1
- package/core/super-anchor.js.map +1 -1
- package/core/super-input.d.ts.map +1 -1
- package/core/super-input.js +1 -1
- package/core/super-input.js.map +1 -1
- package/core/super-openable.d.ts.map +1 -1
- package/core/super-openable.js.map +1 -1
- package/custom-elements.json +1 -1
- package/dev/components/alert.d.ts.map +1 -1
- package/dev/components/alert.js +82 -69
- package/dev/components/alert.js.map +1 -1
- package/dev/components/avatar.d.ts.map +1 -1
- package/dev/components/avatar.js +52 -36
- package/dev/components/avatar.js.map +1 -1
- package/dev/components/badge.d.ts.map +1 -1
- package/dev/components/badge.js +57 -50
- package/dev/components/badge.js.map +1 -1
- package/dev/components/breath.d.ts.map +1 -1
- package/dev/components/breath.js +20 -14
- package/dev/components/breath.js.map +1 -1
- package/dev/components/button.d.ts.map +1 -1
- package/dev/components/button.js +13 -10
- package/dev/components/button.js.map +1 -1
- package/dev/components/card.d.ts.map +1 -1
- package/dev/components/card.js +40 -35
- package/dev/components/card.js.map +1 -1
- package/dev/components/carousel.d.ts.map +1 -1
- package/dev/components/carousel.js +63 -43
- package/dev/components/carousel.js.map +1 -1
- package/dev/components/details.d.ts.map +1 -1
- package/dev/components/details.js +72 -61
- package/dev/components/details.js.map +1 -1
- package/dev/components/dialog.d.ts.map +1 -1
- package/dev/components/dialog.js +61 -57
- package/dev/components/dialog.js.map +1 -1
- package/dev/components/divider.d.ts.map +1 -1
- package/dev/components/divider.js +28 -23
- package/dev/components/divider.js.map +1 -1
- package/dev/components/dragbox.d.ts.map +1 -1
- package/dev/components/dragbox.js +19 -17
- package/dev/components/dragbox.js.map +1 -1
- package/dev/components/flex.d.ts.map +1 -1
- package/dev/components/flex.js +16 -11
- package/dev/components/flex.js.map +1 -1
- package/dev/components/form.d.ts.map +1 -1
- package/dev/components/form.js +4 -4
- package/dev/components/form.js.map +1 -1
- package/dev/components/grid.d.ts.map +1 -1
- package/dev/components/grid.js +16 -11
- package/dev/components/grid.js.map +1 -1
- package/dev/components/heading.d.ts.map +1 -1
- package/dev/components/heading.js +62 -40
- package/dev/components/heading.js.map +1 -1
- package/dev/components/input.d.ts.map +1 -1
- package/dev/components/input.js +32 -24
- package/dev/components/input.js.map +1 -1
- package/dev/components/layout.d.ts.map +1 -1
- package/dev/components/layout.js +43 -30
- package/dev/components/layout.js.map +1 -1
- package/dev/components/link.js +1 -1
- package/dev/components/link.js.map +1 -1
- package/dev/components/progress.d.ts.map +1 -1
- package/dev/components/progress.js +51 -42
- package/dev/components/progress.js.map +1 -1
- package/dev/components/range.d.ts.map +1 -1
- package/dev/components/range.js +33 -30
- package/dev/components/range.js.map +1 -1
- package/dev/components/rotate.d.ts.map +1 -1
- package/dev/components/rotate.js +12 -5
- package/dev/components/rotate.js.map +1 -1
- package/dev/components/router.d.ts +20 -25
- package/dev/components/router.d.ts.map +1 -1
- package/dev/components/router.js +17 -17
- package/dev/components/router.js.map +1 -1
- package/dev/components/select.d.ts.map +1 -1
- package/dev/components/select.js +65 -57
- package/dev/components/select.js.map +1 -1
- package/dev/components/skeleton.d.ts.map +1 -1
- package/dev/components/skeleton.js +65 -61
- package/dev/components/skeleton.js.map +1 -1
- package/dev/components/split.d.ts.map +1 -1
- package/dev/components/split.js +66 -58
- package/dev/components/split.js.map +1 -1
- package/dev/components/switch.d.ts.map +1 -1
- package/dev/components/switch.js +88 -79
- package/dev/components/switch.js.map +1 -1
- package/dev/components/text.d.ts.map +1 -1
- package/dev/components/text.js +51 -45
- package/dev/components/text.js.map +1 -1
- package/dev/components/time.d.ts.map +1 -1
- package/dev/components/time.js +13 -2
- package/dev/components/time.js.map +1 -1
- package/dev/components/tooltip.d.ts.map +1 -1
- package/dev/components/tooltip.js +31 -23
- package/dev/components/tooltip.js.map +1 -1
- package/dev/components/typewriter.d.ts.map +1 -1
- package/dev/components/typewriter.js +35 -27
- package/dev/components/typewriter.js.map +1 -1
- package/dev/core/global-style.d.ts.map +1 -1
- package/dev/core/global-style.js +9 -9
- package/dev/core/global-style.js.map +1 -1
- package/dev/core/super-anchor.d.ts.map +1 -1
- package/dev/core/super-anchor.js +27 -26
- package/dev/core/super-anchor.js.map +1 -1
- package/dev/core/super-input.d.ts.map +1 -1
- package/dev/core/super-input.js +83 -68
- package/dev/core/super-input.js.map +1 -1
- package/dev/core/super-openable.d.ts.map +1 -1
- package/dev/core/super-openable.js +1 -2
- package/dev/core/super-openable.js.map +1 -1
- package/package.json +5 -5
- package/src/components/alert.ts +84 -75
- package/src/components/avatar.ts +54 -40
- package/src/components/badge.ts +68 -65
- package/src/components/breath.ts +23 -19
- package/src/components/button.ts +14 -11
- package/src/components/card.ts +42 -40
- package/src/components/carousel.ts +65 -47
- package/src/components/details.ts +74 -65
- package/src/components/dialog.ts +64 -62
- package/src/components/divider.ts +33 -30
- package/src/components/dragbox.ts +22 -22
- package/src/components/flex.ts +31 -28
- package/src/components/form.ts +7 -9
- package/src/components/grid.ts +31 -28
- package/src/components/heading.ts +67 -49
- package/src/components/input.ts +37 -31
- package/src/components/layout.ts +45 -34
- package/src/components/link.ts +1 -1
- package/src/components/progress.ts +53 -46
- package/src/components/range.ts +58 -52
- package/src/components/rotate.ts +15 -10
- package/src/components/router.ts +40 -45
- package/src/components/select.ts +74 -70
- package/src/components/skeleton.ts +67 -65
- package/src/components/split.ts +73 -69
- package/src/components/switch.ts +90 -83
- package/src/components/text.ts +53 -49
- package/src/components/time.ts +14 -3
- package/src/components/tooltip.ts +32 -24
- package/src/components/typewriter.ts +37 -31
- package/src/core/global-style.ts +11 -12
- package/src/core/super-anchor.ts +29 -30
- package/src/core/super-input.ts +86 -73
- package/src/core/super-openable.ts +2 -8
- package/web-types.json +1 -1
package/src/components/select.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
import { attr, godown,
|
1
|
+
import { type HandlerEvent, attr, godown, htmlSlot, part, styles } from "@godown/element";
|
2
2
|
import svgCaretDown from "@godown/f7-icon/icons/chevron-down.js";
|
3
|
-
import { css, html, nothing
|
3
|
+
import { type TemplateResult, css, html, nothing } from "lit";
|
4
4
|
import { property, state } from "lit/decorators.js";
|
5
5
|
|
6
6
|
import Input from "./input.js";
|
@@ -46,31 +46,29 @@ const protoName = "select";
|
|
46
46
|
* @category input
|
47
47
|
*/
|
48
48
|
@godown(protoName)
|
49
|
-
@styles(
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
}
|
49
|
+
@styles(css`
|
50
|
+
[part="input"] {
|
51
|
+
text-overflow: ellipsis;
|
52
|
+
}
|
54
53
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
54
|
+
[part="content"] {
|
55
|
+
position: absolute;
|
56
|
+
width: 100%;
|
57
|
+
visibility: hidden;
|
58
|
+
}
|
60
59
|
|
61
|
-
|
62
|
-
|
63
|
-
|
60
|
+
[direction="bottom"] [part="content"] {
|
61
|
+
top: 100%;
|
62
|
+
}
|
64
63
|
|
65
|
-
|
66
|
-
|
67
|
-
|
64
|
+
[direction="top"] [part="content"] {
|
65
|
+
bottom: 100%;
|
66
|
+
}
|
68
67
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
)
|
68
|
+
[visible] [part="content"] {
|
69
|
+
visibility: visible;
|
70
|
+
}
|
71
|
+
`)
|
74
72
|
class Select extends Input {
|
75
73
|
// @ts-ignore
|
76
74
|
value: string | string[];
|
@@ -99,41 +97,54 @@ class Select extends Input {
|
|
99
97
|
protected lastChecked: HTMLElement;
|
100
98
|
protected defaultText: string;
|
101
99
|
protected defaultChecked: HTMLElement[];
|
102
|
-
private _store: { value: string; text: string
|
100
|
+
private _store: { value: string; text: string }[] = [];
|
103
101
|
|
104
102
|
protected render(): TemplateResult<1> {
|
105
|
-
return html
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
103
|
+
return html`
|
104
|
+
<div
|
105
|
+
part="root"
|
106
|
+
${attr({
|
107
|
+
...this.observedRecord,
|
108
|
+
direction: this.direction || this.autoDirection,
|
109
|
+
})}
|
110
|
+
class="input-field"
|
111
|
+
>
|
112
|
+
${[
|
113
|
+
this._renderPrefix(),
|
114
|
+
html`
|
115
|
+
<input
|
116
|
+
part="input"
|
117
|
+
type="${this.type}"
|
118
|
+
.value="${this.text}"
|
119
|
+
?autofocus="${this.autofocus}"
|
120
|
+
?disabled="${this.disabled}"
|
121
|
+
autocapitalize="${this.autocapitalize || nothing}"
|
122
|
+
autocomplete="${this.autocomplete || nothing}"
|
123
|
+
placeholder="${this.placeholder || nothing}"
|
124
|
+
id="${this.makeId}"
|
125
|
+
@focus="${this._handleFocus}"
|
126
|
+
@input="${this._handleInput}"
|
127
|
+
/>
|
128
|
+
`,
|
129
|
+
html`
|
130
|
+
<label
|
131
|
+
for="${this.makeId}"
|
132
|
+
part="suffix"
|
133
|
+
>
|
134
|
+
<i part="icon">${svgCaretDown()}</i>
|
135
|
+
</label>
|
136
|
+
`,
|
137
|
+
html`
|
138
|
+
<label
|
139
|
+
for="${this.makeId}"
|
140
|
+
part="content"
|
141
|
+
>
|
142
|
+
${htmlSlot()}
|
143
|
+
</label>
|
144
|
+
`,
|
145
|
+
]}
|
146
|
+
</div>
|
147
|
+
`;
|
137
148
|
}
|
138
149
|
|
139
150
|
protected _handleFocus(): void {
|
@@ -177,11 +188,7 @@ class Select extends Input {
|
|
177
188
|
protected _connectedInit(): void {
|
178
189
|
if (!this.value) {
|
179
190
|
const checked = [...this.querySelectorAll<HTMLElement>("[checked]")];
|
180
|
-
const list = this.multiple
|
181
|
-
? checked
|
182
|
-
: checked.length
|
183
|
-
? [this.lastChecked = checked[0]]
|
184
|
-
: [];
|
191
|
+
const list = this.multiple ? checked : checked.length ? [(this.lastChecked = checked[0])] : [];
|
185
192
|
list.forEach((element: HTMLElement) => {
|
186
193
|
const operation = this.select(this.optionValue(element), element.textContent);
|
187
194
|
updateChecked(element, operation);
|
@@ -199,23 +206,23 @@ class Select extends Input {
|
|
199
206
|
reset(): void {
|
200
207
|
this.value = this.default;
|
201
208
|
this.text = this.defaultText;
|
202
|
-
this.querySelectorAll<HTMLElement>("[checked]").forEach(element => updateChecked(element, 0));
|
203
|
-
this.defaultChecked.forEach(element => updateChecked(element, 1));
|
209
|
+
this.querySelectorAll<HTMLElement>("[checked]").forEach((element) => updateChecked(element, 0));
|
210
|
+
this.defaultChecked.forEach((element) => updateChecked(element, 1));
|
204
211
|
}
|
205
212
|
|
206
213
|
select(value: string, text?: string): 0 | 1 {
|
207
214
|
text ||= value;
|
208
215
|
let operation: 0 | 1 = 0;
|
209
216
|
if (this.multiple) {
|
210
|
-
const i = this._store.findIndex(s => s.value === value);
|
217
|
+
const i = this._store.findIndex((s) => s.value === value);
|
211
218
|
if (i > -1) {
|
212
219
|
this._store.splice(i, 1);
|
213
220
|
} else {
|
214
221
|
this._store.push({ value, text });
|
215
222
|
operation = 1;
|
216
223
|
}
|
217
|
-
this.value = this._store.map(s => s.value);
|
218
|
-
this.text = this._store.map(s => s.text).join(", ");
|
224
|
+
this.value = this._store.map((s) => s.value);
|
225
|
+
this.text = this._store.map((s) => s.text).join(", ");
|
219
226
|
} else {
|
220
227
|
if (this.value === value) {
|
221
228
|
this.value = "";
|
@@ -236,15 +243,12 @@ class Select extends Input {
|
|
236
243
|
[...this.children].forEach((element: HTMLElement) => {
|
237
244
|
this.filterCallback(
|
238
245
|
element,
|
239
|
-
!query
|
240
|
-
|| contain(this.optionValue(element), query)
|
241
|
-
|| contain(element.textContent, query),
|
246
|
+
!query || contain(this.optionValue(element), query) || contain(element.textContent, query),
|
242
247
|
query,
|
243
248
|
);
|
244
249
|
});
|
245
250
|
}
|
246
251
|
|
247
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
248
252
|
filterCallback(element: HTMLElement, match: boolean, query: string): void {
|
249
253
|
element.style.display = match ? "" : "none";
|
250
254
|
}
|
@@ -1,9 +1,9 @@
|
|
1
1
|
import { attr, godown, htmlSlot, styles } from "@godown/element";
|
2
2
|
import iconPhoto from "@godown/f7-icon/icons/photo.js";
|
3
|
-
import { css, html
|
3
|
+
import { type TemplateResult, css, html } from "lit";
|
4
4
|
import { property, state } from "lit/decorators.js";
|
5
5
|
|
6
|
-
import {
|
6
|
+
import { GlobalStyle, cssGlobalVars, scopePrefix } from "../core/global-style.js";
|
7
7
|
|
8
8
|
const protoName = "skeleton";
|
9
9
|
const cssScope = scopePrefix(protoName);
|
@@ -16,73 +16,71 @@ const cssScope = scopePrefix(protoName);
|
|
16
16
|
* @category feedback
|
17
17
|
*/
|
18
18
|
@godown(protoName)
|
19
|
-
@styles(
|
20
|
-
|
21
|
-
:
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
}
|
19
|
+
@styles(css`
|
20
|
+
:host {
|
21
|
+
${cssScope}--from: var(${cssGlobalVars._colors.darkgray[9]});
|
22
|
+
${cssScope}--to: var(${cssGlobalVars._colors.darkgray[7]});
|
23
|
+
${cssScope}--deg: 95deg;
|
24
|
+
${cssScope}--duration: 1.5s;
|
25
|
+
${cssScope}--icon-size: 5em;
|
26
|
+
${cssScope}--icon-margin: .25em;
|
27
|
+
color: var(${cssGlobalVars._colors.darkgray[5]});
|
28
|
+
background: var(${cssScope}--from);
|
29
|
+
min-height: 1.5em;
|
30
|
+
width: 100%;
|
31
|
+
flex-shrink: 0;
|
32
|
+
display: block;
|
33
|
+
overflow: hidden;
|
34
|
+
}
|
36
35
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
36
|
+
[part="root"] {
|
37
|
+
height: 100%;
|
38
|
+
min-height: inherit;
|
39
|
+
text-align: center;
|
40
|
+
animation: var(${cssScope}--duration) ease-in-out 0s infinite none running;
|
41
|
+
}
|
43
42
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
43
|
+
svg {
|
44
|
+
--size: var(${cssScope}--icon-size);
|
45
|
+
font-size: var(--size);
|
46
|
+
margin: calc(var(--size) * 0.05);
|
47
|
+
}
|
49
48
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
49
|
+
[animation="position"] {
|
50
|
+
background-image: linear-gradient(
|
51
|
+
var(${cssScope}--deg),
|
52
|
+
var(${cssScope}--from) 36%,
|
53
|
+
var(${cssScope}--to) 50%,
|
54
|
+
var(${cssScope}--from) 64%
|
55
|
+
);
|
56
|
+
background-color: transparent;
|
57
|
+
background-size: 200% 100%;
|
58
|
+
animation-name: po;
|
59
|
+
}
|
61
60
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
}
|
66
|
-
to {
|
67
|
-
background-position: -50% center;
|
68
|
-
}
|
61
|
+
@keyframes po {
|
62
|
+
from {
|
63
|
+
background-position: 150% center;
|
69
64
|
}
|
70
|
-
|
71
|
-
|
72
|
-
animation-name: op;
|
73
|
-
animation-direction: alternate;
|
65
|
+
to {
|
66
|
+
background-position: -50% center;
|
74
67
|
}
|
68
|
+
}
|
75
69
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
70
|
+
[animation="opacity"] {
|
71
|
+
animation-name: op;
|
72
|
+
animation-direction: alternate;
|
73
|
+
}
|
74
|
+
|
75
|
+
@keyframes op {
|
76
|
+
50% {
|
77
|
+
opacity: 0.25;
|
78
|
+
}
|
79
|
+
to {
|
80
|
+
opacity: 1;
|
83
81
|
}
|
84
|
-
|
85
|
-
)
|
82
|
+
}
|
83
|
+
`)
|
86
84
|
class Skeleton extends GlobalStyle {
|
87
85
|
/**
|
88
86
|
* If "image", render a image placeholder.
|
@@ -107,10 +105,14 @@ class Skeleton extends GlobalStyle {
|
|
107
105
|
if (!this.loading) {
|
108
106
|
return htmlSlot();
|
109
107
|
}
|
110
|
-
return html
|
111
|
-
|
112
|
-
|
113
|
-
|
108
|
+
return html`
|
109
|
+
<div
|
110
|
+
part="root"
|
111
|
+
${attr(this.observedRecord)}
|
112
|
+
>
|
113
|
+
${this.type === "image" ? iconPhoto() : ""} ${htmlSlot("loading")}
|
114
|
+
</div>
|
115
|
+
`;
|
114
116
|
}
|
115
117
|
}
|
116
118
|
|
package/src/components/split.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import { attr, classList, godown,
|
2
|
-
import { css, html, nothing
|
1
|
+
import { type HandlerEvent, attr, classList, godown, styles } from "@godown/element";
|
2
|
+
import { type TemplateResult, css, html, nothing } from "lit";
|
3
3
|
import { property, state } from "lit/decorators.js";
|
4
4
|
|
5
5
|
import { cssGlobalVars, scopePrefix } from "../core/global-style.js";
|
@@ -30,54 +30,52 @@ const loop = <T>(len: number, fn: (index?: number) => T) => {
|
|
30
30
|
* @category input
|
31
31
|
*/
|
32
32
|
@godown(protoName)
|
33
|
-
@styles(
|
34
|
-
|
35
|
-
:
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
}
|
33
|
+
@styles(css`
|
34
|
+
:host {
|
35
|
+
color: var(${cssGlobalVars.foreground});
|
36
|
+
display: block;
|
37
|
+
border-radius: 1px;
|
38
|
+
width: fit-content;
|
39
|
+
${cssScope}--size: 1.45em;
|
40
|
+
${cssScope}--gap: .25em;
|
41
|
+
}
|
43
42
|
|
44
|
-
|
45
|
-
|
46
|
-
|
43
|
+
:host([contents]) [part="root"] {
|
44
|
+
width: fit-content;
|
45
|
+
}
|
47
46
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
47
|
+
[part="root"] {
|
48
|
+
gap: var(${cssScope}--gap);
|
49
|
+
width: 100%;
|
50
|
+
position: relative;
|
51
|
+
vertical-align: top;
|
52
|
+
display: flex;
|
53
|
+
justify-content: space-between;
|
54
|
+
border-radius: inherit;
|
55
|
+
}
|
57
56
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
57
|
+
[part="input-box"] {
|
58
|
+
width: var(${cssScope}--size);
|
59
|
+
height: var(${cssScope}--size);
|
60
|
+
vertical-align: top;
|
61
|
+
text-align: center;
|
62
|
+
background-color: var(${cssGlobalVars.input}-background);
|
63
|
+
border-radius: inherit;
|
64
|
+
}
|
66
65
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
66
|
+
[part="input"] {
|
67
|
+
width: 100%;
|
68
|
+
height: 100%;
|
69
|
+
opacity: 0;
|
70
|
+
background: none;
|
71
|
+
position: absolute;
|
72
|
+
z-index: -1;
|
73
|
+
}
|
75
74
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
)
|
75
|
+
.focus {
|
76
|
+
box-shadow: var(${cssGlobalVars.input}-box-shadow);
|
77
|
+
}
|
78
|
+
`)
|
81
79
|
class Split extends SuperInput {
|
82
80
|
/**
|
83
81
|
* The number of input boxes.
|
@@ -98,29 +96,35 @@ class Split extends SuperInput {
|
|
98
96
|
currentValue: (string | void)[] = [];
|
99
97
|
|
100
98
|
protected render(): TemplateResult<1> {
|
101
|
-
return html
|
102
|
-
|
103
|
-
|
104
|
-
this.
|
105
|
-
(index: number) =>
|
106
|
-
html`<span
|
107
|
-
part="input-box"
|
108
|
-
@click="${this.disabled ? null : () => this.focusAt(index)}"
|
109
|
-
class="${classList({ focus: this.current === index }) || nothing}"
|
110
|
-
>${this.currentValue[index]}</span
|
111
|
-
>`,
|
112
|
-
)
|
113
|
-
}
|
114
|
-
<input
|
115
|
-
part="input"
|
116
|
-
id="${this.makeId}"
|
117
|
-
@blur=${this.blur}
|
118
|
-
@input="${this._handleInput}"
|
119
|
-
.value="${
|
120
|
-
/* Ensure that input always has a value of length this.len */
|
121
|
-
this.value.padStart(this.len, " ")}"
|
99
|
+
return html`
|
100
|
+
<div
|
101
|
+
part="root"
|
102
|
+
${attr(this.observedRecord)}
|
122
103
|
>
|
123
|
-
|
104
|
+
${loop(
|
105
|
+
this.len,
|
106
|
+
(index: number) => html`
|
107
|
+
<span
|
108
|
+
part="input-box"
|
109
|
+
class="${classList({ focus: this.current === index })}"
|
110
|
+
@click="${this.disabled ? null : () => this.focusAt(index)}"
|
111
|
+
>
|
112
|
+
${this.currentValue[index]}
|
113
|
+
</span>
|
114
|
+
`,
|
115
|
+
)}
|
116
|
+
<input
|
117
|
+
part="input"
|
118
|
+
id="${this.makeId}"
|
119
|
+
@blur=${this.blur}
|
120
|
+
@input="${this._handleInput}"
|
121
|
+
.value="${
|
122
|
+
/* Ensure that input always has a value of length this.len */
|
123
|
+
this.value.padStart(this.len, " ")
|
124
|
+
}"
|
125
|
+
/>
|
126
|
+
</div>
|
127
|
+
`;
|
124
128
|
}
|
125
129
|
|
126
130
|
connectedCallback(): void {
|
@@ -168,8 +172,8 @@ class Split extends SuperInput {
|
|
168
172
|
// go to before
|
169
173
|
|
170
174
|
this.currentValue[this.current - 1] = null;
|
171
|
-
const lastNotNull = this.currentValue.findLastIndex(a => a !== null);
|
172
|
-
this.current = this.current - 1 < 0 ? lastNotNull < 0 ? 0 : lastNotNull : this.current - 1;
|
175
|
+
const lastNotNull = this.currentValue.findLastIndex((a) => a !== null);
|
176
|
+
this.current = this.current - 1 < 0 ? (lastNotNull < 0 ? 0 : lastNotNull) : this.current - 1;
|
173
177
|
}
|
174
178
|
return;
|
175
179
|
}
|