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,160 @@
|
|
1
|
+
import { type HandlerEvent } from "@godown/element";
|
2
|
+
import { godown } from "@godown/element/decorators/godown.js";
|
3
|
+
import { styles } from "@godown/element/decorators/styles.js";
|
4
|
+
import { htmlSlot } from "@godown/element/directives/html-slot.js";
|
5
|
+
import { css, html, type PropertyValues } from "lit";
|
6
|
+
import { property } from "lit/decorators.js";
|
7
|
+
|
8
|
+
import { cssGlobalVars, scopePrefix } from "../core/global-style.js";
|
9
|
+
import SuperOpenable, { type Direction9 } from "../core/super-openable.js";
|
10
|
+
|
11
|
+
const protoName = "dialog";
|
12
|
+
const cssScope = scopePrefix(protoName);
|
13
|
+
|
14
|
+
/**
|
15
|
+
* {@linkcode Dialog} similar to `<dialog>`.
|
16
|
+
*
|
17
|
+
* Like dialog, it listens for submit events and closes itself when the target method is "dialog".
|
18
|
+
*
|
19
|
+
* It listens for the keydown event and also closes itself when the {@linkcode key} contained in the key is pressed
|
20
|
+
*
|
21
|
+
* @category feedback
|
22
|
+
*/
|
23
|
+
@godown(protoName)
|
24
|
+
@styles(
|
25
|
+
css`
|
26
|
+
:host {
|
27
|
+
${cssScope}--background: none;
|
28
|
+
${cssScope}--background-modal: var(${cssGlobalVars.background});
|
29
|
+
${cssScope}--opacity-modal: 0.2;
|
30
|
+
background: var(${cssScope}--background);
|
31
|
+
pointer-events: none;
|
32
|
+
visibility: hidden;
|
33
|
+
position: fixed;
|
34
|
+
z-index: 1;
|
35
|
+
inset:0;
|
36
|
+
}
|
37
|
+
|
38
|
+
:host([open]) {
|
39
|
+
visibility: visible;
|
40
|
+
}
|
41
|
+
|
42
|
+
:host([open][modal]) [part="modal"] {
|
43
|
+
pointer-events: all;
|
44
|
+
visibility: visible;
|
45
|
+
opacity: var(${cssScope}--opacity-modal);
|
46
|
+
|
47
|
+
}
|
48
|
+
|
49
|
+
[part="modal"] {
|
50
|
+
visibility: hidden;
|
51
|
+
opacity: 0;
|
52
|
+
width: 100%;
|
53
|
+
height: 100%;
|
54
|
+
position: absolute;
|
55
|
+
background: var(${cssScope}--background-modal);
|
56
|
+
}
|
57
|
+
|
58
|
+
[part="root"] {
|
59
|
+
width: 100%;
|
60
|
+
height: 100%;
|
61
|
+
display: flex;
|
62
|
+
position: relative;
|
63
|
+
align-items: center;
|
64
|
+
justify-content: center;
|
65
|
+
}
|
66
|
+
|
67
|
+
[direction] {
|
68
|
+
pointer-events: all;
|
69
|
+
position: absolute;
|
70
|
+
}
|
71
|
+
|
72
|
+
[direction^="top"] {
|
73
|
+
top: 0;
|
74
|
+
}
|
75
|
+
|
76
|
+
[direction^="bottom"] {
|
77
|
+
bottom: 0;
|
78
|
+
}
|
79
|
+
|
80
|
+
[direction$="right"] {
|
81
|
+
right: 0%;
|
82
|
+
}
|
83
|
+
|
84
|
+
[direction$="left"] {
|
85
|
+
left: 0%;
|
86
|
+
}
|
87
|
+
`,
|
88
|
+
)
|
89
|
+
class Dialog extends SuperOpenable {
|
90
|
+
@property()
|
91
|
+
direction: Direction9 = "center";
|
92
|
+
/**
|
93
|
+
* Enable modal, blocking event penetration.
|
94
|
+
*/
|
95
|
+
@property({ type: Boolean, reflect: true })
|
96
|
+
modal = false;
|
97
|
+
/**
|
98
|
+
* Close key.
|
99
|
+
*/
|
100
|
+
@property()
|
101
|
+
key = "Escape";
|
102
|
+
|
103
|
+
private _modalInvoke: boolean;
|
104
|
+
|
105
|
+
protected render() {
|
106
|
+
return html`<div part="root">
|
107
|
+
<div part="modal"></div>
|
108
|
+
<div part="container" direction="${this.direction}">${htmlSlot()}</div>
|
109
|
+
</div>`;
|
110
|
+
}
|
111
|
+
|
112
|
+
showModal() {
|
113
|
+
if (!this.modal) {
|
114
|
+
this.modal = true;
|
115
|
+
this._modalInvoke = true;
|
116
|
+
}
|
117
|
+
this.show();
|
118
|
+
}
|
119
|
+
|
120
|
+
private _submitEvent: EventListenerOrEventListenerObject;
|
121
|
+
private _keydownEvent: EventListenerOrEventListenerObject;
|
122
|
+
|
123
|
+
protected updated(changedProperties: PropertyValues) {
|
124
|
+
if (changedProperties.has("open")) {
|
125
|
+
if (this.open) {
|
126
|
+
this._submitEvent = this.events.add(this, "submit", this._handelSubmit);
|
127
|
+
if (this.key) {
|
128
|
+
this._keydownEvent = this.events.add(document, "keydown", this._handleKeydown.bind(this));
|
129
|
+
}
|
130
|
+
} else {
|
131
|
+
this.events.remove(this, "submit", this._submitEvent);
|
132
|
+
this.events.remove(document, "keydown", this._keydownEvent);
|
133
|
+
}
|
134
|
+
}
|
135
|
+
}
|
136
|
+
|
137
|
+
protected _handleKeydown(e: KeyboardEvent) {
|
138
|
+
e.preventDefault();
|
139
|
+
const keys = this.key.split(/[\s,]/);
|
140
|
+
if (keys.includes(e.key) || keys.includes(e.code)) {
|
141
|
+
this.close();
|
142
|
+
}
|
143
|
+
}
|
144
|
+
|
145
|
+
protected _handelSubmit(e: HandlerEvent<HTMLFormElement>) {
|
146
|
+
if (e.target.method === "dialog") {
|
147
|
+
this.close();
|
148
|
+
}
|
149
|
+
}
|
150
|
+
|
151
|
+
close() {
|
152
|
+
if (this._modalInvoke) {
|
153
|
+
this.modal = false;
|
154
|
+
this._modalInvoke = false;
|
155
|
+
}
|
156
|
+
this.open = false;
|
157
|
+
}
|
158
|
+
}
|
159
|
+
|
160
|
+
export default Dialog;
|
@@ -0,0 +1,44 @@
|
|
1
|
+
import { godown, styles } from "@godown/element/decorators/index.js";
|
2
|
+
import { css } from "lit";
|
3
|
+
import { property } from "lit/decorators.js";
|
4
|
+
|
5
|
+
import { GlobalStyle } from "../core/global-style.js";
|
6
|
+
|
7
|
+
const protoName = "divider";
|
8
|
+
|
9
|
+
/**
|
10
|
+
* {@linkcode Divider} similar to `<hr>`.
|
11
|
+
*
|
12
|
+
* This component does not render content.
|
13
|
+
*
|
14
|
+
* @category layout
|
15
|
+
*/
|
16
|
+
@godown(protoName)
|
17
|
+
@styles(
|
18
|
+
css`
|
19
|
+
:host{
|
20
|
+
width: 100%;
|
21
|
+
height: .05em;
|
22
|
+
margin: auto;
|
23
|
+
display: block;
|
24
|
+
background: currentColor;
|
25
|
+
}
|
26
|
+
:host([vertical]) {
|
27
|
+
width: .05em;
|
28
|
+
height: max(1em, 100%);
|
29
|
+
}
|
30
|
+
`,
|
31
|
+
)
|
32
|
+
class Divider extends GlobalStyle {
|
33
|
+
/**
|
34
|
+
* Vertical display.
|
35
|
+
*/
|
36
|
+
@property({ type: Boolean, reflect: true })
|
37
|
+
vertical = false;
|
38
|
+
|
39
|
+
connectedCallback() {
|
40
|
+
this.createRenderRoot();
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
export default Divider;
|
@@ -0,0 +1,126 @@
|
|
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 { EventListenerFunc } from "@godown/element/tools/events.js";
|
5
|
+
import { css, html } from "lit";
|
6
|
+
import { property } from "lit/decorators.js";
|
7
|
+
|
8
|
+
import { GlobalStyle } from "../core/global-style.js";
|
9
|
+
|
10
|
+
const protoName = "dragbox";
|
11
|
+
|
12
|
+
/**
|
13
|
+
* {@linkcode Dragbox} does not extend beyond the range of {@linkcode Dragbox.offsetsWidth} and {@linkcode Dragbox.offsetsHeight}.
|
14
|
+
*
|
15
|
+
* @category wrapper
|
16
|
+
*/
|
17
|
+
@godown(protoName)
|
18
|
+
@styles(
|
19
|
+
css`
|
20
|
+
:host {
|
21
|
+
position: absolute;
|
22
|
+
display: block;
|
23
|
+
}
|
24
|
+
|
25
|
+
:host(:active) {
|
26
|
+
-webkit-user-select: none;
|
27
|
+
user-select: none;
|
28
|
+
}
|
29
|
+
`,
|
30
|
+
)
|
31
|
+
class Dragbox extends GlobalStyle {
|
32
|
+
/**
|
33
|
+
* Width of (`this.offsetParent` or `document.body`).
|
34
|
+
*/
|
35
|
+
get offsetsWidth(): number {
|
36
|
+
return this.offsetParent?.clientWidth ?? document.body.offsetWidth;
|
37
|
+
}
|
38
|
+
|
39
|
+
/**
|
40
|
+
* Height of (`this.offsetParent` or `document.body`).
|
41
|
+
*/
|
42
|
+
get offsetsHeight(): number {
|
43
|
+
return this.offsetParent?.clientHeight ?? document.body.offsetHeight;
|
44
|
+
}
|
45
|
+
|
46
|
+
drag: boolean;
|
47
|
+
t: number;
|
48
|
+
l: number;
|
49
|
+
cx: number;
|
50
|
+
cy: number;
|
51
|
+
|
52
|
+
/**
|
53
|
+
* Position x.
|
54
|
+
*/
|
55
|
+
@property()
|
56
|
+
x = "auto";
|
57
|
+
/**
|
58
|
+
* Position y.
|
59
|
+
*/
|
60
|
+
@property()
|
61
|
+
y = "auto";
|
62
|
+
|
63
|
+
protected render() {
|
64
|
+
return html`<div @mousedown="${this._handleDragStart}" @mouseup="${this._handleDragEnd}">${htmlSlot()}</div>`;
|
65
|
+
}
|
66
|
+
|
67
|
+
protected firstUpdated() {
|
68
|
+
this.reset();
|
69
|
+
}
|
70
|
+
|
71
|
+
protected _handleDragStart(e: MouseEvent) {
|
72
|
+
this.cx = e.clientX;
|
73
|
+
this.cy = e.clientY;
|
74
|
+
this.t = this.offsetTop;
|
75
|
+
this.l = this.offsetLeft;
|
76
|
+
this.drag = true;
|
77
|
+
this._handleMouseMove = this.events.add(document, "mousemove", this._handleDrag.bind(this));
|
78
|
+
this._handleMouseLeave = this.events.add(document, "mouseleave", this._handleDragEnd.bind(this));
|
79
|
+
}
|
80
|
+
|
81
|
+
_handleMouseMove: EventListenerFunc;
|
82
|
+
_handleMouseLeave: EventListenerFunc;
|
83
|
+
|
84
|
+
protected _handleDragEnd() {
|
85
|
+
this.drag = false;
|
86
|
+
this.events.remove(document, "mousemove", this._handleMouseMove);
|
87
|
+
this.events.remove(document, "mouseleave", this._handleMouseLeave);
|
88
|
+
}
|
89
|
+
|
90
|
+
protected _handleDrag(e: MouseEvent) {
|
91
|
+
if (!this.drag) {
|
92
|
+
return;
|
93
|
+
}
|
94
|
+
const nl = e.clientX - (this.cx - this.l);
|
95
|
+
const nt = e.clientY - (this.cy - this.t);
|
96
|
+
const { style, offsetsWidth, offsetsHeight, offsetWidth, offsetHeight } = this;
|
97
|
+
if (nl < 0) {
|
98
|
+
style.left = "0";
|
99
|
+
} else if (nl < offsetsWidth - offsetWidth) {
|
100
|
+
style.left = `${nl}px`;
|
101
|
+
} else {
|
102
|
+
style.left = `${offsetsWidth - offsetWidth}"px"`;
|
103
|
+
}
|
104
|
+
if (nt < 0) {
|
105
|
+
style.top = "0";
|
106
|
+
} else if (nt < offsetsHeight - offsetHeight) {
|
107
|
+
style.top = `${nt}px`;
|
108
|
+
} else {
|
109
|
+
style.top = `${offsetsHeight - offsetHeight}px`;
|
110
|
+
}
|
111
|
+
}
|
112
|
+
|
113
|
+
reset() {
|
114
|
+
const { x, y, style, offsetsWidth, offsetsHeight, offsetWidth, offsetHeight, offsetLeft, offsetTop } = this;
|
115
|
+
style.left = x || "0";
|
116
|
+
style.top = y || "0";
|
117
|
+
if (offsetLeft > offsetsWidth - offsetWidth) {
|
118
|
+
style.left = `${offsetsWidth - offsetWidth}px`;
|
119
|
+
}
|
120
|
+
if (offsetTop > offsetsHeight - offsetHeight) {
|
121
|
+
style.top = `${offsetsHeight - offsetHeight}px`;
|
122
|
+
}
|
123
|
+
}
|
124
|
+
}
|
125
|
+
|
126
|
+
export default Dragbox;
|
@@ -0,0 +1,65 @@
|
|
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 { htmlStyle } from "@godown/element/directives/html-style.js";
|
5
|
+
import { joinRules } from "@godown/element/tools/css.js";
|
6
|
+
import { css } from "lit";
|
7
|
+
import { property } from "lit/decorators.js";
|
8
|
+
|
9
|
+
import { GlobalStyle } from "../core/global-style.js";
|
10
|
+
|
11
|
+
const protoName = "flex";
|
12
|
+
|
13
|
+
/**
|
14
|
+
* {@linkcode Flex} provides flex layout.
|
15
|
+
*
|
16
|
+
* @category layout
|
17
|
+
*/
|
18
|
+
@godown(protoName)
|
19
|
+
@styles(css`:host {display:flex;}`)
|
20
|
+
class Flex extends GlobalStyle {
|
21
|
+
/**
|
22
|
+
* CSS property `flex-flow` (`flex-direction flex-wrap`).
|
23
|
+
*/
|
24
|
+
@property({ attribute: "flex-flow" })
|
25
|
+
flexFlow: string;
|
26
|
+
/**
|
27
|
+
* CSS property `gap`.
|
28
|
+
*/
|
29
|
+
@property()
|
30
|
+
gap: string;
|
31
|
+
/**
|
32
|
+
* CSS property `justify-content`.
|
33
|
+
*/
|
34
|
+
@property()
|
35
|
+
content: string;
|
36
|
+
/**
|
37
|
+
* CSS property `align-items`.
|
38
|
+
*/
|
39
|
+
@property()
|
40
|
+
items: string;
|
41
|
+
/**
|
42
|
+
* If true, set flex-direction to "column".
|
43
|
+
*/
|
44
|
+
@property({ type: Boolean })
|
45
|
+
vertical: boolean;
|
46
|
+
|
47
|
+
protected render() {
|
48
|
+
return [
|
49
|
+
htmlSlot(),
|
50
|
+
htmlStyle(
|
51
|
+
joinRules({
|
52
|
+
":host": {
|
53
|
+
gap: this.gap,
|
54
|
+
"flex-flow": this.flexFlow,
|
55
|
+
"flex-direction": this.vertical && "column",
|
56
|
+
"align-items": this.items,
|
57
|
+
"justify-content": this.content,
|
58
|
+
},
|
59
|
+
}),
|
60
|
+
),
|
61
|
+
];
|
62
|
+
}
|
63
|
+
}
|
64
|
+
|
65
|
+
export default Flex;
|
@@ -0,0 +1,83 @@
|
|
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 } from "lit";
|
5
|
+
import { property } from "lit/decorators.js";
|
6
|
+
|
7
|
+
import { GlobalStyle } from "../core/global-style.js";
|
8
|
+
|
9
|
+
const protoName = "form";
|
10
|
+
|
11
|
+
/**
|
12
|
+
* {@linkcode Form} Gets child element key-value object,
|
13
|
+
* which will be nested if the child element is the same as this element.
|
14
|
+
*
|
15
|
+
* @slot - Child elements.
|
16
|
+
*
|
17
|
+
* @category form
|
18
|
+
*/
|
19
|
+
@godown(protoName)
|
20
|
+
@styles(
|
21
|
+
css`
|
22
|
+
:host {
|
23
|
+
display: block;
|
24
|
+
}
|
25
|
+
`,
|
26
|
+
)
|
27
|
+
class Form<T = object> extends GlobalStyle {
|
28
|
+
@property()
|
29
|
+
name = "";
|
30
|
+
get value(): T {
|
31
|
+
return Form.buildValue(this._slot.assignedElements()) as T;
|
32
|
+
}
|
33
|
+
|
34
|
+
nameValue = this.namevalue;
|
35
|
+
|
36
|
+
protected render() {
|
37
|
+
return htmlSlot();
|
38
|
+
}
|
39
|
+
|
40
|
+
reset() {
|
41
|
+
this.deepQuerySelectorAll<HTMLElement & { reset?: () => void; }>("*").forEach((el) => {
|
42
|
+
if (el.tagName === this.tagName) {
|
43
|
+
return;
|
44
|
+
}
|
45
|
+
if (el.reset) {
|
46
|
+
el.reset();
|
47
|
+
}
|
48
|
+
});
|
49
|
+
}
|
50
|
+
|
51
|
+
namevalue(): [string, T] {
|
52
|
+
return [this.name, this.value];
|
53
|
+
}
|
54
|
+
|
55
|
+
static buildValue(
|
56
|
+
elements: (Element & {
|
57
|
+
name?: string;
|
58
|
+
value?: unknown;
|
59
|
+
namevalue?: () => [string, unknown];
|
60
|
+
})[],
|
61
|
+
): Record<string, any> {
|
62
|
+
const result = {};
|
63
|
+
for (const el of elements) {
|
64
|
+
if (el.tagName === "FORM") {
|
65
|
+
Object.assign(result, Object.fromEntries(new FormData(el as HTMLFormElement).entries()));
|
66
|
+
} else if (el.namevalue) {
|
67
|
+
const [name, value] = el.namevalue();
|
68
|
+
if (name) {
|
69
|
+
result[name] = value;
|
70
|
+
}
|
71
|
+
} else if (el.name && el.value !== undefined) {
|
72
|
+
result[el.name] = el.value;
|
73
|
+
} else if (el.shadowRoot) {
|
74
|
+
for (const slot of el.shadowRoot.querySelectorAll("slot")) {
|
75
|
+
Object.assign(result, this.buildValue(slot.assignedElements()));
|
76
|
+
}
|
77
|
+
}
|
78
|
+
}
|
79
|
+
return result;
|
80
|
+
}
|
81
|
+
}
|
82
|
+
|
83
|
+
export default Form;
|
@@ -0,0 +1,66 @@
|
|
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 { htmlStyle } from "@godown/element/directives/html-style.js";
|
5
|
+
import { joinRules } from "@godown/element/tools/css.js";
|
6
|
+
import { isNumerical } from "@godown/element/tools/lib.js";
|
7
|
+
import { css } from "lit";
|
8
|
+
import { property } from "lit/decorators.js";
|
9
|
+
|
10
|
+
import { GlobalStyle } from "../core/global-style.js";
|
11
|
+
|
12
|
+
const protoName = "grid";
|
13
|
+
|
14
|
+
/**
|
15
|
+
* {@linkcode Grid} provides gird layout.
|
16
|
+
*
|
17
|
+
* @category layout
|
18
|
+
*/
|
19
|
+
@godown(protoName)
|
20
|
+
@styles(css`:host{display:grid;}`)
|
21
|
+
class Grid extends GlobalStyle {
|
22
|
+
/**
|
23
|
+
* CSS property `gap`.
|
24
|
+
*/
|
25
|
+
@property()
|
26
|
+
gap: string;
|
27
|
+
/**
|
28
|
+
* CSS property `grid-template-columns`, if {@linkcode isNumerical} divide equally.
|
29
|
+
*/
|
30
|
+
@property()
|
31
|
+
columns: string | number;
|
32
|
+
/**
|
33
|
+
* CSS property `grid-template-rows`, if {@linkcode isNumerical} divide equally.
|
34
|
+
*/
|
35
|
+
@property()
|
36
|
+
rows: string | number;
|
37
|
+
/**
|
38
|
+
* CSS property `place-content` (`align-content justify-content`).
|
39
|
+
*/
|
40
|
+
@property()
|
41
|
+
content: string;
|
42
|
+
/**
|
43
|
+
* CSS property `place-items` (`align-items justify-items`).
|
44
|
+
*/
|
45
|
+
@property()
|
46
|
+
items: string;
|
47
|
+
|
48
|
+
protected render() {
|
49
|
+
return [
|
50
|
+
htmlSlot(),
|
51
|
+
htmlStyle(
|
52
|
+
joinRules({
|
53
|
+
":host": {
|
54
|
+
gap: this.gap,
|
55
|
+
"grid-template-columns": isNumerical(this.columns) ? `repeat(${this.columns},1fr)` : this.columns,
|
56
|
+
"grid-template-rows": isNumerical(this.rows) ? `repeat(${this.rows},1fr)` : this.rows,
|
57
|
+
"place-content": this.content,
|
58
|
+
"place-items": this.items,
|
59
|
+
},
|
60
|
+
}),
|
61
|
+
),
|
62
|
+
];
|
63
|
+
}
|
64
|
+
}
|
65
|
+
|
66
|
+
export default Grid;
|
@@ -0,0 +1,71 @@
|
|
1
|
+
import { godown } from "@godown/element/decorators/godown.js";
|
2
|
+
import { part } from "@godown/element/decorators/part.js";
|
3
|
+
import { styles } from "@godown/element/decorators/styles.js";
|
4
|
+
import { classList } from "@godown/element/directives/class-list.js";
|
5
|
+
import { css, html, nothing } from "lit";
|
6
|
+
import { property } from "lit/decorators.js";
|
7
|
+
|
8
|
+
import { cssGlobalVars } from "../core/global-style.js";
|
9
|
+
import SuperInput from "../core/super-input.js";
|
10
|
+
|
11
|
+
const protoName = "input";
|
12
|
+
|
13
|
+
/**
|
14
|
+
* {@linkcode Input} used for text input.
|
15
|
+
*
|
16
|
+
* @category input
|
17
|
+
*/
|
18
|
+
@godown(protoName)
|
19
|
+
@styles(
|
20
|
+
css`
|
21
|
+
:host {
|
22
|
+
width: var(${cssGlobalVars.input}-width);
|
23
|
+
height: var(${cssGlobalVars.input}-height);
|
24
|
+
color: var(${cssGlobalVars.foreground});
|
25
|
+
background: var(${cssGlobalVars.input}-background);
|
26
|
+
border-radius: var(${cssGlobalVars.input}-radius);
|
27
|
+
display: block;
|
28
|
+
}
|
29
|
+
`,
|
30
|
+
)
|
31
|
+
class Input extends SuperInput {
|
32
|
+
type: "text" | "search" | "tel" | "url" | "email" | "password" = "text";
|
33
|
+
value: string;
|
34
|
+
|
35
|
+
/**
|
36
|
+
* If outline, the outline is always present.
|
37
|
+
*/
|
38
|
+
@property()
|
39
|
+
variant: "default" | "outline" = "default";
|
40
|
+
|
41
|
+
@part("input")
|
42
|
+
_input: HTMLInputElement;
|
43
|
+
|
44
|
+
protected render() {
|
45
|
+
return html`<div part="root" class="${classList("input-field", this.variant)}">
|
46
|
+
${[
|
47
|
+
this._renderPrefix(),
|
48
|
+
html`<input
|
49
|
+
part="input"
|
50
|
+
type="${this.type}"
|
51
|
+
id="${this.makeId}"
|
52
|
+
.value="${this.value}"
|
53
|
+
placeholder="${this.placeholder || nothing}"
|
54
|
+
?autofocus="${this.autofocus}"
|
55
|
+
autocapitalize="${this.autocapitalize || nothing}"
|
56
|
+
autocomplete="${this.autocomplete || nothing}"
|
57
|
+
?disabled="${this.disabled}"
|
58
|
+
@input="${this._handleInput}"
|
59
|
+
>`,
|
60
|
+
this._renderSuffix(),
|
61
|
+
]}
|
62
|
+
</div>`;
|
63
|
+
}
|
64
|
+
|
65
|
+
reset() {
|
66
|
+
this._input.value = this.default;
|
67
|
+
this.value = this.default;
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
export default Input;
|
@@ -0,0 +1,84 @@
|
|
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 { GlobalStyle } from "../core/global-style.js";
|
9
|
+
|
10
|
+
const protoName = "layout";
|
11
|
+
|
12
|
+
/**
|
13
|
+
* {@linkcode NavLayout} renders slot and optional top header, bottom footer.
|
14
|
+
*
|
15
|
+
* @slot - The main content of the layout.
|
16
|
+
*
|
17
|
+
* @slot header - The header of the layout.
|
18
|
+
*
|
19
|
+
* @slot footer - The footer of the layout.
|
20
|
+
*
|
21
|
+
* @category layout
|
22
|
+
*/
|
23
|
+
@godown(protoName)
|
24
|
+
@styles(
|
25
|
+
css`
|
26
|
+
:host {
|
27
|
+
min-height: 100%;
|
28
|
+
display: flex;
|
29
|
+
flex-direction: column;
|
30
|
+
}
|
31
|
+
|
32
|
+
.sticky {
|
33
|
+
position: sticky;
|
34
|
+
top: 0;
|
35
|
+
z-index: 1;
|
36
|
+
}
|
37
|
+
|
38
|
+
[part="main"] {
|
39
|
+
position: relative;
|
40
|
+
flex: 1;
|
41
|
+
width: 100%;
|
42
|
+
}
|
43
|
+
|
44
|
+
header,
|
45
|
+
main,
|
46
|
+
footer {
|
47
|
+
width: 100%;
|
48
|
+
}
|
49
|
+
`,
|
50
|
+
)
|
51
|
+
class NavLayout extends GlobalStyle {
|
52
|
+
/**
|
53
|
+
* If true, hide the header slot.
|
54
|
+
*/
|
55
|
+
@property({ type: Boolean })
|
56
|
+
noHeader: boolean;
|
57
|
+
/**
|
58
|
+
* If true, hide the footer slot.
|
59
|
+
*/
|
60
|
+
@property({ type: Boolean })
|
61
|
+
noFooter: boolean;
|
62
|
+
|
63
|
+
/**
|
64
|
+
* If true, header will sticky.
|
65
|
+
*/
|
66
|
+
@property({ type: Boolean })
|
67
|
+
sticky: boolean;
|
68
|
+
|
69
|
+
protected render() {
|
70
|
+
return html`${
|
71
|
+
!this.noHeader
|
72
|
+
? html`<header part="header" class="${classList({ sticky: this.sticky })}">${htmlSlot("header")}</header>`
|
73
|
+
: ""
|
74
|
+
}
|
75
|
+
<main part="main">${htmlSlot()}</main>
|
76
|
+
${
|
77
|
+
!this.noFooter
|
78
|
+
? html`<footer part="footer">${htmlSlot("footer")}</footer>`
|
79
|
+
: ""
|
80
|
+
}`;
|
81
|
+
}
|
82
|
+
}
|
83
|
+
|
84
|
+
export default NavLayout;
|