godown 3.0.0-canary.7 → 3.0.0-canary.8
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/components/alert.d.ts.map +1 -1
- package/components/alert.js +3 -2
- package/components/alert.js.map +1 -1
- package/components/breath.js +2 -2
- package/components/breath.js.map +1 -1
- package/components/card.d.ts +1 -1
- package/components/card.d.ts.map +1 -1
- package/components/card.js +3 -4
- package/components/card.js.map +1 -1
- package/components/carousel.js +1 -1
- package/components/carousel.js.map +1 -1
- package/components/input.d.ts +0 -1
- package/components/input.d.ts.map +1 -1
- package/components/input.js +0 -3
- package/components/input.js.map +1 -1
- package/components/layout.d.ts +1 -1
- package/components/layout.d.ts.map +1 -1
- package/components/layout.js +5 -6
- package/components/layout.js.map +1 -1
- package/components/router.js +1 -1
- package/components/router.js.map +1 -1
- package/components/select.d.ts +0 -4
- package/components/select.d.ts.map +1 -1
- package/components/select.js +0 -7
- package/components/select.js.map +1 -1
- package/components/skeleton.d.ts.map +1 -1
- package/components/skeleton.js +1 -2
- package/components/skeleton.js.map +1 -1
- package/components/split.d.ts +1 -1
- package/components/split.d.ts.map +1 -1
- package/components/split.js +8 -2
- package/components/split.js.map +1 -1
- package/components/text.js +1 -1
- package/components/text.js.map +1 -1
- package/core/super-input.d.ts +0 -1
- package/core/super-input.d.ts.map +1 -1
- package/core/super-input.js +0 -3
- package/core/super-input.js.map +1 -1
- package/custom-elements.json +1 -1
- package/dev/components/alert.d.ts.map +1 -1
- package/dev/components/alert.js +3 -2
- package/dev/components/alert.js.map +1 -1
- package/dev/components/breath.d.ts.map +1 -1
- package/dev/components/breath.js +2 -1
- package/dev/components/breath.js.map +1 -1
- package/dev/components/card.d.ts +1 -1
- package/dev/components/card.d.ts.map +1 -1
- package/dev/components/card.js +3 -4
- package/dev/components/card.js.map +1 -1
- package/dev/components/carousel.d.ts.map +1 -1
- package/dev/components/carousel.js +1 -0
- package/dev/components/carousel.js.map +1 -1
- package/dev/components/input.d.ts +0 -1
- package/dev/components/input.d.ts.map +1 -1
- package/dev/components/input.js +0 -3
- package/dev/components/input.js.map +1 -1
- package/dev/components/layout.d.ts +1 -1
- package/dev/components/layout.d.ts.map +1 -1
- package/dev/components/layout.js +7 -6
- package/dev/components/layout.js.map +1 -1
- package/dev/components/router.js +1 -1
- package/dev/components/router.js.map +1 -1
- package/dev/components/select.d.ts +0 -4
- package/dev/components/select.d.ts.map +1 -1
- package/dev/components/select.js +0 -7
- package/dev/components/select.js.map +1 -1
- package/dev/components/skeleton.d.ts.map +1 -1
- package/dev/components/skeleton.js +1 -2
- package/dev/components/skeleton.js.map +1 -1
- package/dev/components/split.d.ts +1 -1
- package/dev/components/split.d.ts.map +1 -1
- package/dev/components/split.js +9 -3
- package/dev/components/split.js.map +1 -1
- package/dev/components/text.js +3 -3
- package/dev/core/super-input.d.ts +0 -1
- package/dev/core/super-input.d.ts.map +1 -1
- package/dev/core/super-input.js +0 -3
- package/dev/core/super-input.js.map +1 -1
- package/package.json +7 -6
- package/src/alert.ts +11 -0
- package/src/avatar.ts +11 -0
- package/src/breath.ts +13 -0
- package/src/button.ts +11 -0
- package/src/card.ts +11 -0
- package/src/carousel.ts +11 -0
- package/src/components/alert.ts +282 -0
- package/src/components/avatar.ts +93 -0
- package/src/components/breath.ts +151 -0
- package/src/components/button.ts +276 -0
- package/src/components/card.ts +85 -0
- package/src/components/carousel.ts +166 -0
- package/src/components/details.ts +112 -0
- package/src/components/dialog.ts +160 -0
- package/src/components/divider.ts +44 -0
- package/src/components/dragbox.ts +126 -0
- package/src/components/flex.ts +65 -0
- package/src/components/form.ts +83 -0
- package/src/components/grid.ts +66 -0
- package/src/components/input.ts +71 -0
- package/src/components/layout.ts +84 -0
- package/src/components/link.ts +36 -0
- package/src/components/progress.ts +101 -0
- package/src/components/range.ts +409 -0
- package/src/components/rotate.ts +92 -0
- package/src/components/router.ts +264 -0
- package/src/components/select.ts +268 -0
- package/src/components/skeleton.ts +116 -0
- package/src/components/split.ts +190 -0
- package/src/components/switch.ts +176 -0
- package/src/components/text.ts +95 -0
- package/src/components/time.ts +77 -0
- package/src/components/tooltip.ts +118 -0
- package/src/components/typewriter.ts +147 -0
- package/src/core/global-style.ts +86 -0
- package/src/core/super-anchor.ts +52 -0
- package/src/core/super-input.ts +230 -0
- package/src/core/super-openable.ts +51 -0
- package/src/details.ts +11 -0
- package/src/dialog.ts +11 -0
- package/src/divider.ts +11 -0
- package/src/dragbox.ts +11 -0
- package/src/flex.ts +11 -0
- package/src/form.ts +11 -0
- package/src/grid.ts +11 -0
- package/src/index.ts +28 -0
- package/src/input.ts +13 -0
- package/src/layout.ts +12 -0
- package/src/link.ts +13 -0
- package/src/progress.ts +12 -0
- package/src/range.ts +13 -0
- package/src/rotate.ts +13 -0
- package/src/router.ts +12 -0
- package/src/select.ts +13 -0
- package/src/skeleton.ts +13 -0
- package/src/split.ts +13 -0
- package/src/switch.ts +13 -0
- package/src/text.ts +13 -0
- package/src/time.ts +13 -0
- package/src/tooltip.ts +13 -0
- package/src/typewriter.ts +11 -0
- package/vscode.html-custom-data.json +1 -1
- package/web-types.json +1 -1
@@ -0,0 +1,190 @@
|
|
1
|
+
import { godown } from "@godown/element/decorators/godown.js";
|
2
|
+
import { styles } from "@godown/element/decorators/styles.js";
|
3
|
+
import { classList } from "@godown/element/directives/class-list.js";
|
4
|
+
import { type HandlerEvent } from "@godown/element/element.js";
|
5
|
+
import { css, html, nothing } from "lit";
|
6
|
+
import { property, state } from "lit/decorators.js";
|
7
|
+
|
8
|
+
import { cssGlobalVars, scopePrefix } from "../core/global-style.js";
|
9
|
+
import SuperInput from "../core/super-input.js";
|
10
|
+
|
11
|
+
const protoName = "split";
|
12
|
+
const cssScope = scopePrefix(protoName);
|
13
|
+
|
14
|
+
const loop = <T>(len: number, fn: (index?: number) => T) => {
|
15
|
+
const result: T[] = new Array(len);
|
16
|
+
for (let index = 0; index < len; index++) {
|
17
|
+
result[index] = fn(index);
|
18
|
+
}
|
19
|
+
return result;
|
20
|
+
};
|
21
|
+
|
22
|
+
/**
|
23
|
+
* {@linkcode Split} renders multiple input boxes.
|
24
|
+
*
|
25
|
+
* Input: will move the focus box backward until the complete input from start to end.
|
26
|
+
*
|
27
|
+
* Delete: will move the focus box forward until the first and no inputs for each.
|
28
|
+
*
|
29
|
+
* @category input
|
30
|
+
*/
|
31
|
+
@godown(protoName)
|
32
|
+
@styles(
|
33
|
+
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
|
+
}
|
42
|
+
|
43
|
+
[part="root"] {
|
44
|
+
gap: var(${cssScope}--gap);
|
45
|
+
width: 100%;
|
46
|
+
position: relative;
|
47
|
+
vertical-align: top;
|
48
|
+
display: inline-flex;
|
49
|
+
justify-content: space-between;
|
50
|
+
border-radius: inherit;
|
51
|
+
}
|
52
|
+
|
53
|
+
[part="input-box"] {
|
54
|
+
width: var(${cssScope}--size);
|
55
|
+
height: var(${cssScope}--size);
|
56
|
+
vertical-align: top;
|
57
|
+
text-align: center;
|
58
|
+
background-color: var(${cssGlobalVars.input}-background);
|
59
|
+
border-radius: inherit;
|
60
|
+
}
|
61
|
+
|
62
|
+
[part="input"] {
|
63
|
+
width: 100%;
|
64
|
+
height: 100%;
|
65
|
+
opacity: 0;
|
66
|
+
background: none;
|
67
|
+
position: absolute;
|
68
|
+
z-index: -1;
|
69
|
+
}
|
70
|
+
|
71
|
+
.focus {
|
72
|
+
box-shadow: var(${cssGlobalVars.input}-box-shadow);
|
73
|
+
}
|
74
|
+
`,
|
75
|
+
)
|
76
|
+
class Split extends SuperInput {
|
77
|
+
/**
|
78
|
+
* The number of input boxes.
|
79
|
+
*/
|
80
|
+
@property({ type: Number })
|
81
|
+
len = 6;
|
82
|
+
/**
|
83
|
+
* Focus index.
|
84
|
+
*/
|
85
|
+
@property({ type: Number })
|
86
|
+
index = -1;
|
87
|
+
|
88
|
+
@state()
|
89
|
+
current = -1;
|
90
|
+
@state()
|
91
|
+
currentValue: (string | void)[] = [];
|
92
|
+
|
93
|
+
protected render() {
|
94
|
+
return html`
|
95
|
+
<div part="root">
|
96
|
+
${
|
97
|
+
loop(this.len, (index: number) =>
|
98
|
+
html`<span part="input-box"
|
99
|
+
@click="${this.disabled ? null : () => this.focusAt(index)}"
|
100
|
+
class="${classList({ focus: this.current === index }) || nothing}"
|
101
|
+
>${this.currentValue[index]}</span>`)
|
102
|
+
}
|
103
|
+
<input
|
104
|
+
part="input"
|
105
|
+
id="${this.makeId}"
|
106
|
+
@blur=${this.blur}
|
107
|
+
@input="${this._handleInput}"
|
108
|
+
.value="${
|
109
|
+
/* Ensure that input always has a value of length this.len */
|
110
|
+
this.value.padStart(this.len, " ")}"
|
111
|
+
>
|
112
|
+
</div>
|
113
|
+
`;
|
114
|
+
}
|
115
|
+
|
116
|
+
connectedCallback(): void {
|
117
|
+
super.connectedCallback();
|
118
|
+
this.reset();
|
119
|
+
}
|
120
|
+
|
121
|
+
protected _handleInput(e: HandlerEvent<HTMLInputElement, InputEvent>) {
|
122
|
+
e.stopPropagation();
|
123
|
+
if (this.compositing) {
|
124
|
+
return;
|
125
|
+
}
|
126
|
+
if (e.data === null) {
|
127
|
+
// delete
|
128
|
+
|
129
|
+
if (this.currentValue[this.current] !== null) {
|
130
|
+
// delete exist value
|
131
|
+
|
132
|
+
this.currentValue[this.current] = null;
|
133
|
+
} else {
|
134
|
+
// go to before
|
135
|
+
|
136
|
+
this.currentValue[this.current - 1] = null;
|
137
|
+
const lastNotNull = this.currentValue.findLastIndex(a => a !== null);
|
138
|
+
this.current = this.current - 1 < 0 ? lastNotNull < 0 ? 0 : lastNotNull : this.current - 1;
|
139
|
+
}
|
140
|
+
} else {
|
141
|
+
// input
|
142
|
+
|
143
|
+
this.currentValue[this.current] = e.data;
|
144
|
+
if (this.current + 1 >= this.len) {
|
145
|
+
// index overflow
|
146
|
+
|
147
|
+
this.current = this.currentValue.indexOf(null);
|
148
|
+
if (this.current === -1) {
|
149
|
+
this.blur();
|
150
|
+
}
|
151
|
+
} else {
|
152
|
+
// go to after
|
153
|
+
|
154
|
+
this.current += 1;
|
155
|
+
}
|
156
|
+
}
|
157
|
+
|
158
|
+
this.value = this.currentValue.join("");
|
159
|
+
|
160
|
+
this.dispatchEvent(new CustomEvent("input", { detail: this.value, bubbles: true, composed: true }));
|
161
|
+
this.dispatchEvent(new CustomEvent("change", { detail: this.value, composed: true }));
|
162
|
+
}
|
163
|
+
|
164
|
+
focus() {
|
165
|
+
this.focusAt(this.current);
|
166
|
+
super.focus();
|
167
|
+
}
|
168
|
+
|
169
|
+
focusAt(i: number) {
|
170
|
+
this.current = i;
|
171
|
+
this._input.focus();
|
172
|
+
}
|
173
|
+
|
174
|
+
blur() {
|
175
|
+
this._input.blur();
|
176
|
+
this.current = -1;
|
177
|
+
super.blur();
|
178
|
+
}
|
179
|
+
|
180
|
+
reset() {
|
181
|
+
this.current = -1;
|
182
|
+
this.value = this.default;
|
183
|
+
this.currentValue = this.value.split("").concat(Array(this.len - this.value.length).fill(null));
|
184
|
+
if (this.index > -1) {
|
185
|
+
this.current = this.index;
|
186
|
+
}
|
187
|
+
}
|
188
|
+
}
|
189
|
+
|
190
|
+
export default Split;
|
@@ -0,0 +1,176 @@
|
|
1
|
+
import { godown } from "@godown/element/decorators/godown.js";
|
2
|
+
import { styles } from "@godown/element/decorators/styles.js";
|
3
|
+
import { css, html } from "lit";
|
4
|
+
import { property, query } from "lit/decorators.js";
|
5
|
+
|
6
|
+
import { cssGlobalVars, scopePrefix } from "../core/global-style.js";
|
7
|
+
import SuperInput from "../core/super-input.js";
|
8
|
+
|
9
|
+
const protoName = "switch";
|
10
|
+
const cssScope = scopePrefix(protoName);
|
11
|
+
|
12
|
+
/**
|
13
|
+
* {@linkcode Switch} renders a switch.
|
14
|
+
*
|
15
|
+
* The switch is rectangular by default,
|
16
|
+
* set the round property to rounded switch.
|
17
|
+
*
|
18
|
+
* @category input
|
19
|
+
*/
|
20
|
+
@godown(protoName)
|
21
|
+
@styles(
|
22
|
+
css`
|
23
|
+
:host {
|
24
|
+
${cssScope}-width: 3em;
|
25
|
+
${cssScope}-height: calc(var(${cssScope}-width) / 2);
|
26
|
+
${cssScope}-handle-size: 1.25em;
|
27
|
+
${cssScope}-transition: .2s ease-in-out;
|
28
|
+
background: var(${cssGlobalVars.input}-background);
|
29
|
+
width: var(${cssScope}-width);
|
30
|
+
height: var(${cssScope}-height);
|
31
|
+
display: inline-block;
|
32
|
+
vertical-align: bottom;
|
33
|
+
border-radius: 0;
|
34
|
+
}
|
35
|
+
|
36
|
+
[part="root"],
|
37
|
+
span {
|
38
|
+
transition: var(${cssScope}-transition);
|
39
|
+
}
|
40
|
+
|
41
|
+
[part="root"] {
|
42
|
+
border-radius: inherit;
|
43
|
+
position: relative;
|
44
|
+
height: inherit;
|
45
|
+
}
|
46
|
+
|
47
|
+
[part="root"],
|
48
|
+
input {
|
49
|
+
width: 100%;
|
50
|
+
}
|
51
|
+
|
52
|
+
input {
|
53
|
+
opacity: 0;
|
54
|
+
height: 100%;
|
55
|
+
appearance: none;
|
56
|
+
}
|
57
|
+
|
58
|
+
span {
|
59
|
+
height: 100%;
|
60
|
+
display: inline-flex;
|
61
|
+
align-items: center;
|
62
|
+
justify-content: center;
|
63
|
+
position: absolute;
|
64
|
+
left: 0;
|
65
|
+
width: 50%;
|
66
|
+
pointer-events: none;
|
67
|
+
border-radius: inherit;
|
68
|
+
}
|
69
|
+
|
70
|
+
:host([round]) {
|
71
|
+
border-radius: calc(var(${cssScope}-height) / 2);
|
72
|
+
}
|
73
|
+
|
74
|
+
:host([checked]) span {
|
75
|
+
transform: translateX(100%);
|
76
|
+
}
|
77
|
+
|
78
|
+
.rect .true {
|
79
|
+
background: var(${cssGlobalVars.active});
|
80
|
+
}
|
81
|
+
|
82
|
+
.rect .false {
|
83
|
+
background: var(${cssGlobalVars.passive});
|
84
|
+
}
|
85
|
+
|
86
|
+
.round span::after{
|
87
|
+
--size: var(${cssScope}-handle-size);
|
88
|
+
content:"";
|
89
|
+
border-radius: 100%;
|
90
|
+
background: var(--godown--input-control);
|
91
|
+
width: var(--size);
|
92
|
+
height: var(--size);
|
93
|
+
}
|
94
|
+
|
95
|
+
.round {
|
96
|
+
background: var(${cssGlobalVars.passive});
|
97
|
+
}
|
98
|
+
|
99
|
+
:host([checked]) .round {
|
100
|
+
background: var(${cssGlobalVars.active});
|
101
|
+
}
|
102
|
+
`,
|
103
|
+
)
|
104
|
+
class Switch extends SuperInput {
|
105
|
+
/**
|
106
|
+
* Border style.
|
107
|
+
*/
|
108
|
+
@property({ type: Boolean, reflect: true })
|
109
|
+
round = false;
|
110
|
+
/**
|
111
|
+
* Whether this element is selected or not.
|
112
|
+
*/
|
113
|
+
@property({ type: Boolean, reflect: true })
|
114
|
+
checked = false;
|
115
|
+
/**
|
116
|
+
* Whether this element is disabled or not.
|
117
|
+
*/
|
118
|
+
@property({ type: Boolean, reflect: true })
|
119
|
+
disabled = false;
|
120
|
+
/**
|
121
|
+
* Parsed by JSON.parse to checked.
|
122
|
+
*/
|
123
|
+
@property()
|
124
|
+
default = "false";
|
125
|
+
/**
|
126
|
+
* Input value.
|
127
|
+
*/
|
128
|
+
@property()
|
129
|
+
value = "on";
|
130
|
+
|
131
|
+
@query("input")
|
132
|
+
_input: HTMLInputElement;
|
133
|
+
|
134
|
+
protected render() {
|
135
|
+
return html`<div part="root" class="${this.round ? "round" : "rect"}">
|
136
|
+
<input
|
137
|
+
part="input"
|
138
|
+
@change="${this._handleChange}"
|
139
|
+
?disabled="${this.disabled}"
|
140
|
+
?checked="${this.checked}"
|
141
|
+
name="${this.name}"
|
142
|
+
id="${this.makeId}"
|
143
|
+
type="checkbox"
|
144
|
+
>
|
145
|
+
<span class="${this.checked}">
|
146
|
+
</span>
|
147
|
+
</div>`;
|
148
|
+
}
|
149
|
+
|
150
|
+
reset() {
|
151
|
+
this.checked = this.default === "true";
|
152
|
+
this._input.checked = this.checked;
|
153
|
+
}
|
154
|
+
|
155
|
+
connectedCallback() {
|
156
|
+
super.connectedCallback();
|
157
|
+
if (this.checked) {
|
158
|
+
this.default = "true";
|
159
|
+
}
|
160
|
+
if (this.default === "true") {
|
161
|
+
this.checked = true;
|
162
|
+
}
|
163
|
+
}
|
164
|
+
|
165
|
+
protected _handleChange() {
|
166
|
+
this.checked = this._input.checked;
|
167
|
+
this.dispatchEvent(new CustomEvent("input", { detail: this.checked, bubbles: true, composed: true }));
|
168
|
+
this.dispatchEvent(new CustomEvent("change", { detail: this.checked, composed: true }));
|
169
|
+
}
|
170
|
+
|
171
|
+
namevalue(): [string, boolean] {
|
172
|
+
return [this.name, this.checked];
|
173
|
+
}
|
174
|
+
}
|
175
|
+
|
176
|
+
export default Switch;
|
@@ -0,0 +1,95 @@
|
|
1
|
+
import { godown } from "@godown/element/decorators/godown.js";
|
2
|
+
import { styles } from "@godown/element/decorators/styles.js";
|
3
|
+
import { classList } from "@godown/element/directives/class-list.js";
|
4
|
+
import { htmlSlot } from "@godown/element/directives/html-slot.js";
|
5
|
+
import { css, html } from "lit";
|
6
|
+
import { property } from "lit/decorators.js";
|
7
|
+
|
8
|
+
import { cssGlobalVars, GlobalStyle, scopePrefix } from "../core/global-style.js";
|
9
|
+
|
10
|
+
const protoName = "text";
|
11
|
+
|
12
|
+
const cssScope = scopePrefix(protoName);
|
13
|
+
|
14
|
+
/**
|
15
|
+
* {@linkcode Text} renders nowrap text.
|
16
|
+
*
|
17
|
+
* @category display
|
18
|
+
*/
|
19
|
+
@godown(protoName)
|
20
|
+
@styles(css`
|
21
|
+
:host {
|
22
|
+
${cssScope}--color: currentColor;
|
23
|
+
${cssScope}--color-hover: currentColor;
|
24
|
+
${cssScope}--color-active: currentColor;
|
25
|
+
display: inline-block;
|
26
|
+
text-overflow: ellipsis;
|
27
|
+
overflow-wrap: break-word;
|
28
|
+
}
|
29
|
+
|
30
|
+
[part="root"] {
|
31
|
+
white-space: nowrap;
|
32
|
+
width: 100%;
|
33
|
+
vertical-align: bottom;
|
34
|
+
display: inline-block;
|
35
|
+
text-overflow: inherit;
|
36
|
+
overflow-wrap: inherit;
|
37
|
+
overflow: hidden;
|
38
|
+
color: var(${cssScope}--color);
|
39
|
+
}
|
40
|
+
|
41
|
+
[part="root"]:hover {
|
42
|
+
color: var(${cssScope}--color-hover, var(${cssScope}--color));
|
43
|
+
}
|
44
|
+
|
45
|
+
[part="root"]:active {
|
46
|
+
color: var(${cssScope}--color-active, var(${cssScope}--color));
|
47
|
+
}
|
48
|
+
|
49
|
+
.hover:hover,
|
50
|
+
.active:active,
|
51
|
+
.always {
|
52
|
+
text-decoration: underline;
|
53
|
+
}
|
54
|
+
|
55
|
+
.none {
|
56
|
+
text-decoration: none;
|
57
|
+
}
|
58
|
+
|
59
|
+
.clip{
|
60
|
+
background: var(${cssGlobalVars.clipBackground});
|
61
|
+
display: inline-block;
|
62
|
+
color: transparent;
|
63
|
+
-webkit-text-fill-color: transparent;
|
64
|
+
background-clip: text;
|
65
|
+
-webkit-background-clip: text;
|
66
|
+
}
|
67
|
+
`)
|
68
|
+
class Text extends GlobalStyle {
|
69
|
+
/**
|
70
|
+
* Underline behavior.
|
71
|
+
*/
|
72
|
+
@property()
|
73
|
+
underline: "none" | "hover" | "active" | "always" = "none";
|
74
|
+
|
75
|
+
/**
|
76
|
+
* Set background-clip to text.
|
77
|
+
*/
|
78
|
+
@property({ type: Boolean })
|
79
|
+
clip: boolean;
|
80
|
+
|
81
|
+
protected render() {
|
82
|
+
return html`<span
|
83
|
+
part="root"
|
84
|
+
class="${
|
85
|
+
classList(this.underline, {
|
86
|
+
clip: this.clip,
|
87
|
+
})
|
88
|
+
}"
|
89
|
+
>
|
90
|
+
${htmlSlot()}
|
91
|
+
</span>`;
|
92
|
+
}
|
93
|
+
}
|
94
|
+
|
95
|
+
export default Text;
|
@@ -0,0 +1,77 @@
|
|
1
|
+
import { godown } from "@godown/element/decorators/godown.js";
|
2
|
+
import { styles } from "@godown/element/decorators/styles.js";
|
3
|
+
import fmtime from "fmtime";
|
4
|
+
import { css, type PropertyValues } from "lit";
|
5
|
+
import { property } from "lit/decorators.js";
|
6
|
+
|
7
|
+
import { GlobalStyle } from "../core/global-style.js";
|
8
|
+
|
9
|
+
const protoName = "time";
|
10
|
+
|
11
|
+
/**
|
12
|
+
* {@linkcode Time} renders a formatting time.
|
13
|
+
*
|
14
|
+
* @category display
|
15
|
+
*/
|
16
|
+
@godown(protoName)
|
17
|
+
@styles(css`:host{text-align: center;}`)
|
18
|
+
class Time extends GlobalStyle {
|
19
|
+
/**
|
20
|
+
* Cancels the next character formatting.
|
21
|
+
*/
|
22
|
+
@property()
|
23
|
+
escape = "%";
|
24
|
+
/**
|
25
|
+
* Format strings.
|
26
|
+
*/
|
27
|
+
@property()
|
28
|
+
format = "YYYY-MM-DD hh:mm:ss UTFZ";
|
29
|
+
/**
|
30
|
+
* Time.
|
31
|
+
*/
|
32
|
+
@property({ type: Object })
|
33
|
+
time = new Date();
|
34
|
+
/**
|
35
|
+
* If there is a value, update every gap or timeout.
|
36
|
+
*/
|
37
|
+
@property({ type: Number })
|
38
|
+
timeout = 0;
|
39
|
+
/**
|
40
|
+
* The number of milliseconds that change with each update.
|
41
|
+
*/
|
42
|
+
@property({ type: Number })
|
43
|
+
gap = 0;
|
44
|
+
|
45
|
+
timeoutId: number;
|
46
|
+
|
47
|
+
protected render(): string {
|
48
|
+
return fmtime(this.format, this.time, this.escape);
|
49
|
+
}
|
50
|
+
|
51
|
+
protected firstUpdated() {
|
52
|
+
if (this.timeout) {
|
53
|
+
this.timeoutId = this.startTimeout();
|
54
|
+
}
|
55
|
+
}
|
56
|
+
|
57
|
+
protected updated(changedProperties: PropertyValues): void {
|
58
|
+
if (changedProperties.has("timeout")) {
|
59
|
+
clearInterval(this.timeoutId);
|
60
|
+
if (this.timeout) {
|
61
|
+
this.timeoutId = this.startTimeout();
|
62
|
+
}
|
63
|
+
}
|
64
|
+
}
|
65
|
+
|
66
|
+
disconnectedCallback() {
|
67
|
+
clearInterval(this.timeoutId);
|
68
|
+
}
|
69
|
+
|
70
|
+
startTimeout() {
|
71
|
+
return window.setInterval(() => {
|
72
|
+
this.time = new Date(this.time.getTime() + (this.gap || this.timeout));
|
73
|
+
}, Math.abs(this.timeout));
|
74
|
+
}
|
75
|
+
}
|
76
|
+
|
77
|
+
export default Time;
|
@@ -0,0 +1,118 @@
|
|
1
|
+
import { godown } from "@godown/element/decorators/godown.js";
|
2
|
+
import { styles } from "@godown/element/decorators/styles.js";
|
3
|
+
import { htmlSlot } from "@godown/element/directives/html-slot.js";
|
4
|
+
import { css, html } from "lit";
|
5
|
+
import { property } from "lit/decorators.js";
|
6
|
+
|
7
|
+
import { cssGlobalVars, scopePrefix } from "../core/global-style.js";
|
8
|
+
import SuperOpenable, { type Direction8 } from "../core/super-openable.js";
|
9
|
+
|
10
|
+
const protoName = "tooltip";
|
11
|
+
const cssScope = scopePrefix(protoName);
|
12
|
+
|
13
|
+
/**
|
14
|
+
* {@linkcode Tooltip} provide tooltip for slot elements.
|
15
|
+
*
|
16
|
+
* If it has the tip property, ignore the slot tip.
|
17
|
+
*
|
18
|
+
* @slot tip - Tip element.
|
19
|
+
* @slot - Content.
|
20
|
+
* @category feedback
|
21
|
+
*/
|
22
|
+
@godown(protoName)
|
23
|
+
@styles(
|
24
|
+
css`
|
25
|
+
:host {
|
26
|
+
${cssScope}--tip-background: var(${cssGlobalVars.background});
|
27
|
+
display: inline-block;
|
28
|
+
width: fit-content;
|
29
|
+
}
|
30
|
+
|
31
|
+
[part="root"] {
|
32
|
+
display: flex;
|
33
|
+
position: relative;
|
34
|
+
transition: inherit;
|
35
|
+
border-radius: inherit;
|
36
|
+
}
|
37
|
+
|
38
|
+
[part="tip"] {
|
39
|
+
width: fit-content;
|
40
|
+
height: fit-content;
|
41
|
+
position: absolute;
|
42
|
+
visibility: hidden;
|
43
|
+
transition: inherit;
|
44
|
+
user-select: none;
|
45
|
+
}
|
46
|
+
|
47
|
+
:host([open]) [part="tip"],
|
48
|
+
:host(:hover) [part="tip"],
|
49
|
+
[part="tip"]:hover {
|
50
|
+
visibility: visible;
|
51
|
+
}
|
52
|
+
|
53
|
+
.passive{
|
54
|
+
background: var(${cssScope}--tip-background);
|
55
|
+
padding: 0 .5em;
|
56
|
+
}
|
57
|
+
`,
|
58
|
+
css`
|
59
|
+
[direction^="top"] {
|
60
|
+
bottom: 100%;
|
61
|
+
}
|
62
|
+
[direction^="bottom"] {
|
63
|
+
top: 100%;
|
64
|
+
}
|
65
|
+
[direction$="right"] {
|
66
|
+
left: 100%;
|
67
|
+
}
|
68
|
+
[direction$="left"] {
|
69
|
+
right: 100%;
|
70
|
+
}
|
71
|
+
`,
|
72
|
+
)
|
73
|
+
class Tooltip extends SuperOpenable {
|
74
|
+
/**
|
75
|
+
* Tip text, if there is a value, the slot will be ignored.
|
76
|
+
*/
|
77
|
+
@property()
|
78
|
+
tip: string;
|
79
|
+
/**
|
80
|
+
* Direction of opening the tip.
|
81
|
+
*/
|
82
|
+
@property()
|
83
|
+
direction: Direction8 = "top";
|
84
|
+
/**
|
85
|
+
* Content alignment.
|
86
|
+
*/
|
87
|
+
@property()
|
88
|
+
align: "center" | "flex-start" | "flex-end" | "start" | "end" = "center";
|
89
|
+
|
90
|
+
/**
|
91
|
+
* If true, allow penetration of the tip.
|
92
|
+
*/
|
93
|
+
@property({ type: Boolean })
|
94
|
+
propagation: boolean;
|
95
|
+
|
96
|
+
static aligns = {
|
97
|
+
start: "flex-start",
|
98
|
+
end: "flex-end",
|
99
|
+
center: "center",
|
100
|
+
"flex-start": "flex-start",
|
101
|
+
"flex-end": "flex-end",
|
102
|
+
};
|
103
|
+
|
104
|
+
protected render() {
|
105
|
+
const align = Tooltip.aligns[this.align] || "inherit";
|
106
|
+
return html`<div part="root" style="justify-content:${align};align-items:${align}">
|
107
|
+
${htmlSlot()}
|
108
|
+
<div part="tip" direction="${this.direction}" style="pointer-events:${this.propagation ? "none" : "all"}">
|
109
|
+
${
|
110
|
+
this.tip
|
111
|
+
? html`<span class="passive">${this.tip}</span>`
|
112
|
+
: htmlSlot("tip")
|
113
|
+
}</div>
|
114
|
+
</div>`;
|
115
|
+
}
|
116
|
+
}
|
117
|
+
|
118
|
+
export default Tooltip;
|