godown 3.0.0-canary.6 → 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 +1 -1
- package/components/alert.d.ts.map +1 -1
- package/components/alert.js +8 -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/details.d.ts +1 -1
- package/components/details.js +1 -1
- package/components/dialog.d.ts +1 -1
- package/components/dialog.js +1 -1
- package/components/divider.d.ts +1 -1
- package/components/divider.js +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/progress.d.ts +1 -1
- package/components/progress.js +1 -1
- package/components/router.js +1 -1
- package/components/router.js.map +1 -1
- package/components/select.d.ts +1 -5
- package/components/select.d.ts.map +1 -1
- package/components/select.js +1 -8
- 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/components/time.d.ts +0 -16
- package/components/time.d.ts.map +1 -1
- package/components/time.js +4 -57
- package/components/time.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 +1 -1
- package/dev/components/alert.d.ts.map +1 -1
- package/dev/components/alert.js +8 -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/details.d.ts +1 -1
- package/dev/components/details.js +1 -1
- package/dev/components/dialog.d.ts +1 -1
- package/dev/components/dialog.js +1 -1
- package/dev/components/divider.d.ts +1 -1
- package/dev/components/divider.js +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/progress.d.ts +1 -1
- package/dev/components/progress.js +1 -1
- package/dev/components/router.js +1 -1
- package/dev/components/router.js.map +1 -1
- package/dev/components/select.d.ts +1 -5
- package/dev/components/select.d.ts.map +1 -1
- package/dev/components/select.js +1 -8
- 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/components/time.d.ts +0 -16
- package/dev/components/time.d.ts.map +1 -1
- package/dev/components/time.js +4 -57
- package/dev/components/time.js.map +1 -1
- 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 +9 -7
- 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,93 @@
|
|
1
|
+
import { godown, styles } from "@godown/element/decorators/index.js";
|
2
|
+
import { htmlSlot } from "@godown/element/directives/index.js";
|
3
|
+
import { css, html } from "lit";
|
4
|
+
import { property } from "lit/decorators.js";
|
5
|
+
|
6
|
+
import { GlobalStyle, scopePrefix } from "../core/global-style.js";
|
7
|
+
|
8
|
+
const protoName = "avatar";
|
9
|
+
const cssScope = scopePrefix(protoName);
|
10
|
+
|
11
|
+
/**
|
12
|
+
* {@linkcode Avatar} renders a avatar.
|
13
|
+
*
|
14
|
+
* Renders as an image if it has a src property,
|
15
|
+
* otherwise falls back to name or nameless slot.
|
16
|
+
*
|
17
|
+
* @category display
|
18
|
+
*/
|
19
|
+
@godown(protoName)
|
20
|
+
@styles(
|
21
|
+
css`
|
22
|
+
:host {
|
23
|
+
${cssScope}--size: 2em;
|
24
|
+
width: var(${cssScope}--size);
|
25
|
+
height: var(${cssScope}--size);
|
26
|
+
display: inline-block;
|
27
|
+
vertical-align: bottom;
|
28
|
+
}
|
29
|
+
|
30
|
+
:host([round]){
|
31
|
+
border-radius:50%;
|
32
|
+
}
|
33
|
+
|
34
|
+
[part="image"] {
|
35
|
+
width: 100%;
|
36
|
+
height: 100%;
|
37
|
+
object-fit: cover;
|
38
|
+
}
|
39
|
+
|
40
|
+
[part="root"] {
|
41
|
+
overflow: hidden;
|
42
|
+
position: relative;
|
43
|
+
border-radius: inherit;
|
44
|
+
width: 100%;
|
45
|
+
height: 100%;
|
46
|
+
}
|
47
|
+
|
48
|
+
[part="root"] {
|
49
|
+
display: flex;
|
50
|
+
align-items: center;
|
51
|
+
justify-content: center;
|
52
|
+
}
|
53
|
+
`,
|
54
|
+
)
|
55
|
+
class Avatar extends GlobalStyle {
|
56
|
+
/**
|
57
|
+
* Image src.
|
58
|
+
*/
|
59
|
+
@property()
|
60
|
+
src: string | undefined | null;
|
61
|
+
/**
|
62
|
+
* If the image is not available, the {@linkcode Avatar.format} will be displayed.
|
63
|
+
*/
|
64
|
+
@property()
|
65
|
+
name = "";
|
66
|
+
|
67
|
+
@property({ type: Boolean })
|
68
|
+
round = false;
|
69
|
+
|
70
|
+
protected render() {
|
71
|
+
return html`<div part="root">${this._renderAvatar()}</div>`;
|
72
|
+
}
|
73
|
+
|
74
|
+
private _renderAvatar() {
|
75
|
+
if (this.src) {
|
76
|
+
return html`<img part="image" src="${this.src}" @error=${this._handleError} alt="${this.name}">`;
|
77
|
+
}
|
78
|
+
if (this.name) {
|
79
|
+
return html`<span part="name">${this.format()}</span>`;
|
80
|
+
}
|
81
|
+
return htmlSlot();
|
82
|
+
}
|
83
|
+
|
84
|
+
format() {
|
85
|
+
return this.name;
|
86
|
+
}
|
87
|
+
|
88
|
+
_handleError() {
|
89
|
+
this.src = undefined;
|
90
|
+
}
|
91
|
+
}
|
92
|
+
|
93
|
+
export default Avatar;
|
@@ -0,0 +1,151 @@
|
|
1
|
+
import { godown } from "@godown/element/decorators/godown.js";
|
2
|
+
import { styles } from "@godown/element/decorators/styles.js";
|
3
|
+
import { htmlStyle } from "@godown/element/directives/html-style.js";
|
4
|
+
import { css, html } from "lit";
|
5
|
+
import { property } from "lit/decorators.js";
|
6
|
+
|
7
|
+
import { cssGlobalVars, GlobalStyle, scopePrefix } from "../core/global-style.js";
|
8
|
+
|
9
|
+
const defineName = "breath";
|
10
|
+
const cssScope = scopePrefix(defineName);
|
11
|
+
|
12
|
+
/**
|
13
|
+
* {@linkcode Breath} render the text with a breathing effect.
|
14
|
+
*
|
15
|
+
* Dynamically generate a breathing effect based on the length of the split text.
|
16
|
+
*
|
17
|
+
* If there is not enough CSS variable, overrun elements will use the.
|
18
|
+
*
|
19
|
+
* godown was a css library in its earliest days,
|
20
|
+
* and this is the component version of its first effect.
|
21
|
+
*
|
22
|
+
* Inspired by Vercel home page (2023).
|
23
|
+
*
|
24
|
+
* @category effect
|
25
|
+
*/
|
26
|
+
@godown(defineName)
|
27
|
+
@styles(
|
28
|
+
css`
|
29
|
+
:host {
|
30
|
+
${cssScope}--deg: 60deg;
|
31
|
+
${cssScope}--1-1: var(${cssGlobalVars._colors.red[5]});
|
32
|
+
${cssScope}--1-2: var(${cssGlobalVars._colors.yellow[5]});
|
33
|
+
${cssScope}--2-1: var(${cssGlobalVars._colors.green[5]});
|
34
|
+
${cssScope}--2-2: var(${cssGlobalVars._colors.purple[5]});
|
35
|
+
${cssScope}--3-1: var(${cssGlobalVars._colors.blue[5]});
|
36
|
+
${cssScope}--3-2: var(${cssGlobalVars._colors.pink[5]});
|
37
|
+
${cssScope}--1: linear-gradient(var(${cssScope}--deg), var(${cssScope}--1-1), var(${cssScope}--1-2));
|
38
|
+
${cssScope}--2: linear-gradient(var(${cssScope}--deg), var(${cssScope}--2-1), var(${cssScope}--2-2));
|
39
|
+
${cssScope}--3: linear-gradient(var(${cssScope}--deg), var(${cssScope}--3-1), var(${cssScope}--3-2));
|
40
|
+
}
|
41
|
+
`,
|
42
|
+
css`
|
43
|
+
:host {
|
44
|
+
display: flex;
|
45
|
+
margin: auto;
|
46
|
+
width: -moz-fit-content;
|
47
|
+
width: fit-content;
|
48
|
+
font-size: 2em;
|
49
|
+
align-items: center;
|
50
|
+
direction: ltr;
|
51
|
+
}
|
52
|
+
|
53
|
+
::selection {
|
54
|
+
background: none;
|
55
|
+
}
|
56
|
+
|
57
|
+
.rel {
|
58
|
+
position: relative;
|
59
|
+
font-weight: 800;
|
60
|
+
font-size: inherit;
|
61
|
+
letter-spacing: -0.05em;
|
62
|
+
}
|
63
|
+
`,
|
64
|
+
css`
|
65
|
+
.nocolor,
|
66
|
+
.colorful {
|
67
|
+
padding: 0 0.05em;
|
68
|
+
box-sizing: border-box;
|
69
|
+
display: inline-block;
|
70
|
+
animation-iteration-count: infinite;
|
71
|
+
-webkit-text-fill-color: transparent;
|
72
|
+
-webkit-background-clip: text !important;
|
73
|
+
background-clip: text !important;
|
74
|
+
}
|
75
|
+
.colorful {
|
76
|
+
opacity: 0;
|
77
|
+
animation-name: colorfulN;
|
78
|
+
}
|
79
|
+
.nocolor {
|
80
|
+
position: absolute;
|
81
|
+
top: 0;
|
82
|
+
background: var(${cssGlobalVars.clipBackground});
|
83
|
+
}
|
84
|
+
`,
|
85
|
+
)
|
86
|
+
class Breath extends GlobalStyle {
|
87
|
+
/**
|
88
|
+
* Strings or array of strings,
|
89
|
+
* if array, divided each element into chunks,
|
90
|
+
* otherwise split strings by whitespace.
|
91
|
+
*/
|
92
|
+
@property()
|
93
|
+
text: string | string[];
|
94
|
+
/**
|
95
|
+
* Effect duration, ending in s or ms.
|
96
|
+
*/
|
97
|
+
@property()
|
98
|
+
duration: string;
|
99
|
+
|
100
|
+
protected render() {
|
101
|
+
const texts = this.getTexts();
|
102
|
+
return [
|
103
|
+
texts.map(this.renderText),
|
104
|
+
htmlStyle(this.computeStyle(texts.length)),
|
105
|
+
];
|
106
|
+
}
|
107
|
+
|
108
|
+
protected renderText(text: string) {
|
109
|
+
return html`<span class="rel">
|
110
|
+
<span class="nocolor">${text}</span>
|
111
|
+
<span class="colorful">${text}</span>
|
112
|
+
</span>`;
|
113
|
+
}
|
114
|
+
|
115
|
+
protected getTexts(): string[] {
|
116
|
+
return Array.isArray(this.text) ? this.text : (this.text || this.textContent).split(/\s+/).filter((x) => x);
|
117
|
+
}
|
118
|
+
|
119
|
+
protected computeStyle(len: number) {
|
120
|
+
const gap = 100 / 2 / len;
|
121
|
+
const duration = this.parseDuration() || len * 2 + 2;
|
122
|
+
|
123
|
+
return (
|
124
|
+
`.colorful{animation-duration:${duration}s;}`
|
125
|
+
+ `@keyframes colorfulN{0%,${gap * 3}%{opacity:0;}${gap}%,${gap * 2}%{opacity:1;}}`
|
126
|
+
+ (() => {
|
127
|
+
let style1 = "";
|
128
|
+
for (let number = 1; number <= len; number++) {
|
129
|
+
const delay = -duration / len * (len - number + 1);
|
130
|
+
const defaultNumber = ((number - 1) % 3) + 1;
|
131
|
+
style1 +=
|
132
|
+
`.rel:nth-child(${number}) .colorful{animation-delay:${delay}s;background:var(${cssScope}--${number},var(${cssScope}--${defaultNumber}));}`;
|
133
|
+
}
|
134
|
+
return style1;
|
135
|
+
})()
|
136
|
+
);
|
137
|
+
}
|
138
|
+
|
139
|
+
protected parseDuration() {
|
140
|
+
const { duration } = this;
|
141
|
+
if (duration) {
|
142
|
+
if (duration.endsWith("s")) {
|
143
|
+
return parseFloat(duration.slice(0, -1));
|
144
|
+
} else if (duration.endsWith("ms")) {
|
145
|
+
return parseFloat(duration.slice(0, -2)) / 1000;
|
146
|
+
}
|
147
|
+
}
|
148
|
+
}
|
149
|
+
}
|
150
|
+
|
151
|
+
export default Breath;
|
@@ -0,0 +1,276 @@
|
|
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 { htmlSlot } from "@godown/element/directives/html-slot.js";
|
5
|
+
import { htmlStyle } from "@godown/element/directives/html-style.js";
|
6
|
+
import { constructCSSObject, toVar } from "@godown/element/tools/css.js";
|
7
|
+
import { css, html } from "lit";
|
8
|
+
import { property } from "lit/decorators.js";
|
9
|
+
|
10
|
+
import { cssGlobalVars, GlobalStyle, scopePrefix } from "../core/global-style.js";
|
11
|
+
|
12
|
+
const protoName = "button";
|
13
|
+
const cssScope = scopePrefix(protoName);
|
14
|
+
|
15
|
+
const whiteFont = cssGlobalVars._colors.lightgray[0];
|
16
|
+
const blackFont = cssGlobalVars._colors.darkgray[6];
|
17
|
+
|
18
|
+
const colors = constructCSSObject(
|
19
|
+
["color", "background", "gradients"].map((k) => `${cssScope}--${k}`),
|
20
|
+
{
|
21
|
+
black: [
|
22
|
+
whiteFont, // color
|
23
|
+
cssGlobalVars._colors.darkgray[7], // background
|
24
|
+
cssGlobalVars._colors.darkgray[4], // gradients
|
25
|
+
],
|
26
|
+
gray: [
|
27
|
+
whiteFont, // color
|
28
|
+
cssGlobalVars._colors.darkgray[1], // background
|
29
|
+
cssGlobalVars._colors.lightgray[8], // gradients
|
30
|
+
],
|
31
|
+
white: [
|
32
|
+
blackFont, // color
|
33
|
+
cssGlobalVars._colors.lightgray[3], // background
|
34
|
+
cssGlobalVars._colors.lightgray[0], // gradients
|
35
|
+
],
|
36
|
+
blue: [
|
37
|
+
whiteFont, // color
|
38
|
+
cssGlobalVars._colors.blue[6], // background
|
39
|
+
cssGlobalVars._colors.blue[4], // gradients
|
40
|
+
],
|
41
|
+
green: [
|
42
|
+
whiteFont, // color
|
43
|
+
cssGlobalVars._colors.green[6], // background
|
44
|
+
cssGlobalVars._colors.green[4], // gradients
|
45
|
+
],
|
46
|
+
red: [
|
47
|
+
whiteFont, // color
|
48
|
+
cssGlobalVars._colors.red[6], // background
|
49
|
+
cssGlobalVars._colors.red[4], // gradients
|
50
|
+
],
|
51
|
+
orange: [
|
52
|
+
whiteFont, // color
|
53
|
+
cssGlobalVars._colors.orange[6], // background
|
54
|
+
cssGlobalVars._colors.orange[4], // gradients
|
55
|
+
],
|
56
|
+
pink: [
|
57
|
+
whiteFont, // color
|
58
|
+
cssGlobalVars._colors.pink[6], // background
|
59
|
+
cssGlobalVars._colors.pink[4], // gradients
|
60
|
+
],
|
61
|
+
purple: [
|
62
|
+
whiteFont, // color
|
63
|
+
cssGlobalVars._colors.purple[6], // background
|
64
|
+
cssGlobalVars._colors.purple[4], // gradients
|
65
|
+
],
|
66
|
+
yellow: [
|
67
|
+
blackFont, // color
|
68
|
+
cssGlobalVars._colors.yellow[6], // background
|
69
|
+
cssGlobalVars._colors.yellow[4], // gradients
|
70
|
+
],
|
71
|
+
teal: [
|
72
|
+
whiteFont, // color
|
73
|
+
cssGlobalVars._colors.teal[6], // background
|
74
|
+
cssGlobalVars._colors.teal[4], // gradients
|
75
|
+
],
|
76
|
+
},
|
77
|
+
() => `:host`,
|
78
|
+
(prop) => toVar(prop),
|
79
|
+
);
|
80
|
+
|
81
|
+
/**
|
82
|
+
* {@linkcode Button} renders a button.
|
83
|
+
*
|
84
|
+
* Color defaults to black.
|
85
|
+
*
|
86
|
+
* @category input
|
87
|
+
*/
|
88
|
+
@godown(protoName)
|
89
|
+
@styles(
|
90
|
+
css`
|
91
|
+
:host(:not([disabled]):active) {
|
92
|
+
transform: scale(var(${cssScope}--focus-scale));
|
93
|
+
}
|
94
|
+
|
95
|
+
:host([round]) {
|
96
|
+
${cssScope}--padding-x: .75em;
|
97
|
+
border-radius: calc(infinity * 1px);
|
98
|
+
}
|
99
|
+
|
100
|
+
:host([disabled]) {
|
101
|
+
cursor: not-allowed;
|
102
|
+
filter: brightness(0.85);
|
103
|
+
}
|
104
|
+
|
105
|
+
:host([ghost]) {
|
106
|
+
${cssScope}--modal-background: var(${cssScope}--ghost-color);
|
107
|
+
box-shadow:inset 0px 0px 0px var(${cssScope}--ghost-width) var(${cssScope}--ghost-color);
|
108
|
+
color: var(${cssScope}--ghost-color);
|
109
|
+
background: transparent;
|
110
|
+
}
|
111
|
+
`,
|
112
|
+
css`
|
113
|
+
:host {
|
114
|
+
${cssScope}--padding-x: .5em;
|
115
|
+
${cssScope}--padding-y: .15em;
|
116
|
+
${cssScope}--padding: var(${cssScope}--padding-y) var(${cssScope}--padding-x);
|
117
|
+
${cssScope}--modal-animation-duration: 1s;
|
118
|
+
${cssScope}--ghost-width: .08em;
|
119
|
+
${cssScope}--focus-scale: .97;
|
120
|
+
${cssScope}--deg: 45deg;
|
121
|
+
${cssScope}--ghost-color:var(${cssScope}--background);
|
122
|
+
color: var(${cssScope}--color, inherit);
|
123
|
+
background: linear-gradient(
|
124
|
+
var(${cssScope}--deg),
|
125
|
+
var(${cssScope}--background),
|
126
|
+
var(${cssScope}--gradients, var(${cssScope}--background))
|
127
|
+
);
|
128
|
+
border-radius: 0.3em;
|
129
|
+
width: -moz-fit-content;
|
130
|
+
width: fit-content;
|
131
|
+
transition: 0.1s;
|
132
|
+
display: block;
|
133
|
+
overflow: hidden;
|
134
|
+
text-align: center;
|
135
|
+
padding: 0 !important;
|
136
|
+
cursor: pointer;
|
137
|
+
}
|
138
|
+
|
139
|
+
[part="root"] {
|
140
|
+
width: 100%;
|
141
|
+
height: 100%;
|
142
|
+
overflow: hidden;
|
143
|
+
position: relative;
|
144
|
+
transition: none;
|
145
|
+
user-select: none;
|
146
|
+
border-radius: inherit;
|
147
|
+
transition-duration: inherit;
|
148
|
+
}
|
149
|
+
|
150
|
+
[part="slot"] {
|
151
|
+
padding: var(${cssScope}--padding);
|
152
|
+
}
|
153
|
+
|
154
|
+
i {
|
155
|
+
position: absolute;
|
156
|
+
inset: 0;
|
157
|
+
opacity: 0;
|
158
|
+
width: 100%;
|
159
|
+
height: 100%;
|
160
|
+
border-radius: 50%;
|
161
|
+
visibility: visible;
|
162
|
+
pointer-events: none;
|
163
|
+
transform-origin: 0 0;
|
164
|
+
background: var(${cssScope}--modal-background, currentColor);
|
165
|
+
animation-duration: var(${cssScope}--modal-animation-duration);
|
166
|
+
}
|
167
|
+
|
168
|
+
@keyframes kf {
|
169
|
+
0% {
|
170
|
+
transform: scale(0) translate(-50%, -50%);
|
171
|
+
opacity: var(${cssScope}--modal-opacity, 0.18);
|
172
|
+
}
|
173
|
+
80% {
|
174
|
+
transform: scale(1) translate(-50%, -50%);
|
175
|
+
}
|
176
|
+
to {
|
177
|
+
opacity: 0;
|
178
|
+
}
|
179
|
+
}
|
180
|
+
`,
|
181
|
+
)
|
182
|
+
class Button extends GlobalStyle {
|
183
|
+
/**
|
184
|
+
* Whether to disable this element.
|
185
|
+
*/
|
186
|
+
@property({ type: Boolean, reflect: true })
|
187
|
+
disabled: boolean;
|
188
|
+
/**
|
189
|
+
* Invert font and background color.
|
190
|
+
*/
|
191
|
+
@property({ type: Boolean, reflect: true })
|
192
|
+
ghost: boolean;
|
193
|
+
/**
|
194
|
+
* Whether this element is active or not.
|
195
|
+
*/
|
196
|
+
@property({ type: Boolean, reflect: true })
|
197
|
+
active: boolean;
|
198
|
+
/**
|
199
|
+
* Enables rounded corners to appear capsule shaped.
|
200
|
+
*/
|
201
|
+
@property({ type: Boolean, reflect: true })
|
202
|
+
round: boolean;
|
203
|
+
/**
|
204
|
+
* The primary color.
|
205
|
+
*/
|
206
|
+
@property({ reflect: true })
|
207
|
+
color: "none" | keyof typeof colors = "black";
|
208
|
+
/**
|
209
|
+
* Text inside.
|
210
|
+
*/
|
211
|
+
@property()
|
212
|
+
text: string;
|
213
|
+
|
214
|
+
@part("modal-root")
|
215
|
+
_modalRoot: HTMLElement;
|
216
|
+
@part("root")
|
217
|
+
_root: HTMLElement;
|
218
|
+
|
219
|
+
protected render() {
|
220
|
+
const color = this.nextColor();
|
221
|
+
return [
|
222
|
+
html`<div part="root">
|
223
|
+
<span part="modal-root"></span>
|
224
|
+
<div part="slot">${this.text || htmlSlot()}</div>
|
225
|
+
</div>`,
|
226
|
+
htmlStyle(colors[color]),
|
227
|
+
];
|
228
|
+
}
|
229
|
+
|
230
|
+
focus() {
|
231
|
+
if (this.disabled) {
|
232
|
+
return;
|
233
|
+
}
|
234
|
+
this.active = true;
|
235
|
+
super.focus();
|
236
|
+
}
|
237
|
+
|
238
|
+
blur() {
|
239
|
+
this.active = false;
|
240
|
+
super.blur();
|
241
|
+
}
|
242
|
+
|
243
|
+
firstUpdated() {
|
244
|
+
this.events.add(this, "click", this._handelClick, true);
|
245
|
+
}
|
246
|
+
|
247
|
+
protected _handelClick(e: MouseEvent) {
|
248
|
+
if (this.disabled) {
|
249
|
+
e.stopPropagation();
|
250
|
+
e.preventDefault();
|
251
|
+
return;
|
252
|
+
}
|
253
|
+
this._handleModal(e);
|
254
|
+
}
|
255
|
+
|
256
|
+
protected _handleModal(e: MouseEvent) {
|
257
|
+
const modal = document.createElement("i");
|
258
|
+
const rect = this.getBoundingClientRect();
|
259
|
+
const h = rect.height;
|
260
|
+
const w = rect.width;
|
261
|
+
const size = `${Math.sqrt(h * h + w * w) * 2}px`;
|
262
|
+
modal.style.height = size;
|
263
|
+
modal.style.width = size;
|
264
|
+
modal.style.left = `${e.clientX - rect.left}px`;
|
265
|
+
modal.style.top = `${e.clientY - rect.y}px`;
|
266
|
+
modal.style.animationName = "kf";
|
267
|
+
this._modalRoot.appendChild(modal);
|
268
|
+
modal.addEventListener("animationend", () => modal.remove(), { once: true });
|
269
|
+
}
|
270
|
+
|
271
|
+
nextColor() {
|
272
|
+
return this.color;
|
273
|
+
}
|
274
|
+
}
|
275
|
+
|
276
|
+
export default Button;
|
@@ -0,0 +1,85 @@
|
|
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, GlobalStyle, scopePrefix } from "../core/global-style.js";
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
9
|
+
import type Layout from "../layout.js";
|
10
|
+
|
11
|
+
const protoName = "card";
|
12
|
+
const cssScope = scopePrefix(protoName);
|
13
|
+
|
14
|
+
/**
|
15
|
+
* {@linkcode Card} renders a card.
|
16
|
+
*
|
17
|
+
* This may be similar to {@linkcode Layout},
|
18
|
+
* but it needs to be specified to enable header and footer.
|
19
|
+
*
|
20
|
+
* @slot - The main content of the card.
|
21
|
+
* @slot header - The header of the card.
|
22
|
+
* @slot footer - The footer of the card.
|
23
|
+
* @category display
|
24
|
+
*/
|
25
|
+
@godown(protoName)
|
26
|
+
@styles(
|
27
|
+
css`
|
28
|
+
:host {
|
29
|
+
${cssScope}--shadow-width: .0375em;
|
30
|
+
${cssScope}--shadow-color: transparent;
|
31
|
+
${cssScope}--background: var(${cssGlobalVars.background});
|
32
|
+
${cssScope}--divider-width: 100%;
|
33
|
+
${cssScope}--divider-height: var(${cssScope}--shadow-width);
|
34
|
+
${cssScope}--divider-background: var(${cssGlobalVars.passive});
|
35
|
+
${cssScope}--padding: .75em;
|
36
|
+
color: var(${cssGlobalVars.foreground});
|
37
|
+
background: var(${cssScope}--background);
|
38
|
+
display: block;
|
39
|
+
flex-shrink: 0;
|
40
|
+
position: relative;
|
41
|
+
overflow: hidden;
|
42
|
+
box-sizing: border-box;
|
43
|
+
border-radius: 0.25em;
|
44
|
+
transition: box-shadow .1s ease-in-out;
|
45
|
+
}
|
46
|
+
|
47
|
+
:host([shadow="hover"]:hover),
|
48
|
+
:host([shadow="always"]) {
|
49
|
+
${cssScope}--shadow-color: var(${cssScope}--divider-background);
|
50
|
+
box-shadow: inset 0 0 0px var(${cssScope}--shadow-width) var(${cssScope}--shadow-color);
|
51
|
+
}
|
52
|
+
|
53
|
+
[part="divider"] {
|
54
|
+
margin: auto;
|
55
|
+
width: var(${cssScope}--divider-width);
|
56
|
+
height: var(${cssScope}--divider-height);
|
57
|
+
background: var(${cssScope}--divider-background);
|
58
|
+
}
|
59
|
+
|
60
|
+
slot {
|
61
|
+
display: block;
|
62
|
+
padding: var(${cssScope}--padding);
|
63
|
+
}
|
64
|
+
`,
|
65
|
+
)
|
66
|
+
class Card extends GlobalStyle {
|
67
|
+
@property({ reflect: true })
|
68
|
+
shadow: "none" | "always" | "hover" = "hover";
|
69
|
+
|
70
|
+
@property({ type: Boolean })
|
71
|
+
footer = false;
|
72
|
+
@property({ type: Boolean })
|
73
|
+
header = false;
|
74
|
+
|
75
|
+
protected render() {
|
76
|
+
const hr = html`<hr part="divider">`;
|
77
|
+
return [
|
78
|
+
this.header ? [htmlSlot("header"), hr] : "",
|
79
|
+
htmlSlot(),
|
80
|
+
this.footer ? [hr, htmlSlot("footer")] : "",
|
81
|
+
];
|
82
|
+
}
|
83
|
+
}
|
84
|
+
|
85
|
+
export default Card;
|