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.
Files changed (168) hide show
  1. package/components/alert.d.ts +1 -1
  2. package/components/alert.d.ts.map +1 -1
  3. package/components/alert.js +8 -2
  4. package/components/alert.js.map +1 -1
  5. package/components/breath.js +2 -2
  6. package/components/breath.js.map +1 -1
  7. package/components/card.d.ts +1 -1
  8. package/components/card.d.ts.map +1 -1
  9. package/components/card.js +3 -4
  10. package/components/card.js.map +1 -1
  11. package/components/carousel.js +1 -1
  12. package/components/carousel.js.map +1 -1
  13. package/components/details.d.ts +1 -1
  14. package/components/details.js +1 -1
  15. package/components/dialog.d.ts +1 -1
  16. package/components/dialog.js +1 -1
  17. package/components/divider.d.ts +1 -1
  18. package/components/divider.js +1 -1
  19. package/components/input.d.ts +0 -1
  20. package/components/input.d.ts.map +1 -1
  21. package/components/input.js +0 -3
  22. package/components/input.js.map +1 -1
  23. package/components/layout.d.ts +1 -1
  24. package/components/layout.d.ts.map +1 -1
  25. package/components/layout.js +5 -6
  26. package/components/layout.js.map +1 -1
  27. package/components/progress.d.ts +1 -1
  28. package/components/progress.js +1 -1
  29. package/components/router.js +1 -1
  30. package/components/router.js.map +1 -1
  31. package/components/select.d.ts +1 -5
  32. package/components/select.d.ts.map +1 -1
  33. package/components/select.js +1 -8
  34. package/components/select.js.map +1 -1
  35. package/components/skeleton.d.ts.map +1 -1
  36. package/components/skeleton.js +1 -2
  37. package/components/skeleton.js.map +1 -1
  38. package/components/split.d.ts +1 -1
  39. package/components/split.d.ts.map +1 -1
  40. package/components/split.js +8 -2
  41. package/components/split.js.map +1 -1
  42. package/components/text.js +1 -1
  43. package/components/text.js.map +1 -1
  44. package/components/time.d.ts +0 -16
  45. package/components/time.d.ts.map +1 -1
  46. package/components/time.js +4 -57
  47. package/components/time.js.map +1 -1
  48. package/core/super-input.d.ts +0 -1
  49. package/core/super-input.d.ts.map +1 -1
  50. package/core/super-input.js +0 -3
  51. package/core/super-input.js.map +1 -1
  52. package/custom-elements.json +1 -1
  53. package/dev/components/alert.d.ts +1 -1
  54. package/dev/components/alert.d.ts.map +1 -1
  55. package/dev/components/alert.js +8 -2
  56. package/dev/components/alert.js.map +1 -1
  57. package/dev/components/breath.d.ts.map +1 -1
  58. package/dev/components/breath.js +2 -1
  59. package/dev/components/breath.js.map +1 -1
  60. package/dev/components/card.d.ts +1 -1
  61. package/dev/components/card.d.ts.map +1 -1
  62. package/dev/components/card.js +3 -4
  63. package/dev/components/card.js.map +1 -1
  64. package/dev/components/carousel.d.ts.map +1 -1
  65. package/dev/components/carousel.js +1 -0
  66. package/dev/components/carousel.js.map +1 -1
  67. package/dev/components/details.d.ts +1 -1
  68. package/dev/components/details.js +1 -1
  69. package/dev/components/dialog.d.ts +1 -1
  70. package/dev/components/dialog.js +1 -1
  71. package/dev/components/divider.d.ts +1 -1
  72. package/dev/components/divider.js +1 -1
  73. package/dev/components/input.d.ts +0 -1
  74. package/dev/components/input.d.ts.map +1 -1
  75. package/dev/components/input.js +0 -3
  76. package/dev/components/input.js.map +1 -1
  77. package/dev/components/layout.d.ts +1 -1
  78. package/dev/components/layout.d.ts.map +1 -1
  79. package/dev/components/layout.js +7 -6
  80. package/dev/components/layout.js.map +1 -1
  81. package/dev/components/progress.d.ts +1 -1
  82. package/dev/components/progress.js +1 -1
  83. package/dev/components/router.js +1 -1
  84. package/dev/components/router.js.map +1 -1
  85. package/dev/components/select.d.ts +1 -5
  86. package/dev/components/select.d.ts.map +1 -1
  87. package/dev/components/select.js +1 -8
  88. package/dev/components/select.js.map +1 -1
  89. package/dev/components/skeleton.d.ts.map +1 -1
  90. package/dev/components/skeleton.js +1 -2
  91. package/dev/components/skeleton.js.map +1 -1
  92. package/dev/components/split.d.ts +1 -1
  93. package/dev/components/split.d.ts.map +1 -1
  94. package/dev/components/split.js +9 -3
  95. package/dev/components/split.js.map +1 -1
  96. package/dev/components/text.js +3 -3
  97. package/dev/components/time.d.ts +0 -16
  98. package/dev/components/time.d.ts.map +1 -1
  99. package/dev/components/time.js +4 -57
  100. package/dev/components/time.js.map +1 -1
  101. package/dev/core/super-input.d.ts +0 -1
  102. package/dev/core/super-input.d.ts.map +1 -1
  103. package/dev/core/super-input.js +0 -3
  104. package/dev/core/super-input.js.map +1 -1
  105. package/package.json +9 -7
  106. package/src/alert.ts +11 -0
  107. package/src/avatar.ts +11 -0
  108. package/src/breath.ts +13 -0
  109. package/src/button.ts +11 -0
  110. package/src/card.ts +11 -0
  111. package/src/carousel.ts +11 -0
  112. package/src/components/alert.ts +282 -0
  113. package/src/components/avatar.ts +93 -0
  114. package/src/components/breath.ts +151 -0
  115. package/src/components/button.ts +276 -0
  116. package/src/components/card.ts +85 -0
  117. package/src/components/carousel.ts +166 -0
  118. package/src/components/details.ts +112 -0
  119. package/src/components/dialog.ts +160 -0
  120. package/src/components/divider.ts +44 -0
  121. package/src/components/dragbox.ts +126 -0
  122. package/src/components/flex.ts +65 -0
  123. package/src/components/form.ts +83 -0
  124. package/src/components/grid.ts +66 -0
  125. package/src/components/input.ts +71 -0
  126. package/src/components/layout.ts +84 -0
  127. package/src/components/link.ts +36 -0
  128. package/src/components/progress.ts +101 -0
  129. package/src/components/range.ts +409 -0
  130. package/src/components/rotate.ts +92 -0
  131. package/src/components/router.ts +264 -0
  132. package/src/components/select.ts +268 -0
  133. package/src/components/skeleton.ts +116 -0
  134. package/src/components/split.ts +190 -0
  135. package/src/components/switch.ts +176 -0
  136. package/src/components/text.ts +95 -0
  137. package/src/components/time.ts +77 -0
  138. package/src/components/tooltip.ts +118 -0
  139. package/src/components/typewriter.ts +147 -0
  140. package/src/core/global-style.ts +86 -0
  141. package/src/core/super-anchor.ts +52 -0
  142. package/src/core/super-input.ts +230 -0
  143. package/src/core/super-openable.ts +51 -0
  144. package/src/details.ts +11 -0
  145. package/src/dialog.ts +11 -0
  146. package/src/divider.ts +11 -0
  147. package/src/dragbox.ts +11 -0
  148. package/src/flex.ts +11 -0
  149. package/src/form.ts +11 -0
  150. package/src/grid.ts +11 -0
  151. package/src/index.ts +28 -0
  152. package/src/input.ts +13 -0
  153. package/src/layout.ts +12 -0
  154. package/src/link.ts +13 -0
  155. package/src/progress.ts +12 -0
  156. package/src/range.ts +13 -0
  157. package/src/rotate.ts +13 -0
  158. package/src/router.ts +12 -0
  159. package/src/select.ts +13 -0
  160. package/src/skeleton.ts +13 -0
  161. package/src/split.ts +13 -0
  162. package/src/switch.ts +13 -0
  163. package/src/text.ts +13 -0
  164. package/src/time.ts +13 -0
  165. package/src/tooltip.ts +13 -0
  166. package/src/typewriter.ts +11 -0
  167. package/vscode.html-custom-data.json +1 -1
  168. 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;