godown 3.11.2 → 3.13.0

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 (161) hide show
  1. package/build/godown+lit.iife.js +12 -13
  2. package/build/godown+lit.iife.js.map +1 -1
  3. package/build/godown+lit.js +11 -12
  4. package/build/godown+lit.js.map +1 -1
  5. package/build/godown+lit.umd.js +12 -13
  6. package/build/godown+lit.umd.js.map +1 -1
  7. package/build/godown.iife.js +9 -8
  8. package/build/godown.iife.js.map +1 -0
  9. package/build/godown.js +7 -7
  10. package/build/godown.js.map +1 -1
  11. package/build/godown.umd.js +8 -8
  12. package/build/godown.umd.js.map +1 -1
  13. package/custom-elements.json +1 -1
  14. package/index.d.ts +1 -0
  15. package/index.d.ts.map +1 -1
  16. package/index.js +1 -1
  17. package/internal/global-style.d.ts.map +1 -1
  18. package/internal/global-style.js +1 -1
  19. package/internal/global-style.js.map +1 -1
  20. package/internal/popover.d.ts +3 -0
  21. package/internal/popover.d.ts.map +1 -0
  22. package/internal/popover.js +2 -0
  23. package/internal/popover.js.map +1 -0
  24. package/internal/reset-style.d.ts +3 -0
  25. package/internal/reset-style.d.ts.map +1 -0
  26. package/internal/reset-style.js +2 -0
  27. package/internal/reset-style.js.map +1 -0
  28. package/internal/ring.d.ts +1 -0
  29. package/internal/ring.d.ts.map +1 -1
  30. package/internal/ring.js +1 -1
  31. package/internal/ring.js.map +1 -1
  32. package/internal/super-input.d.ts +1 -4
  33. package/internal/super-input.d.ts.map +1 -1
  34. package/internal/super-input.js +1 -1
  35. package/internal/super-input.js.map +1 -1
  36. package/internal/utils.d.ts +2 -0
  37. package/internal/utils.d.ts.map +1 -0
  38. package/internal/utils.js +2 -0
  39. package/internal/utils.js.map +1 -0
  40. package/package.json +3 -4
  41. package/popover.d.ts +2 -0
  42. package/popover.d.ts.map +1 -0
  43. package/popover.js +2 -0
  44. package/popover.js.map +1 -0
  45. package/src/index.ts +1 -0
  46. package/src/internal/global-style.ts +6 -34
  47. package/src/internal/popover.ts +64 -0
  48. package/src/internal/reset-style.ts +63 -0
  49. package/src/internal/ring.ts +3 -2
  50. package/src/internal/super-input.ts +2 -33
  51. package/src/internal/utils.ts +10 -0
  52. package/src/popover.ts +1 -0
  53. package/src/web-components/alert/component.ts +5 -4
  54. package/src/web-components/avatar/component.ts +1 -0
  55. package/src/web-components/button/component.ts +22 -18
  56. package/src/web-components/card/component.ts +3 -2
  57. package/src/web-components/chip/component.ts +1 -3
  58. package/src/web-components/details/component.ts +28 -17
  59. package/src/web-components/dialog/component.ts +51 -67
  60. package/src/web-components/heading/component.ts +0 -1
  61. package/src/web-components/input/component.ts +38 -30
  62. package/src/web-components/layout/component.ts +1 -0
  63. package/src/web-components/link/component.ts +0 -2
  64. package/src/web-components/popover/component.ts +172 -0
  65. package/src/web-components/popover/definition.ts +11 -0
  66. package/src/web-components/range/component.ts +2 -1
  67. package/src/web-components/rotate/component.ts +0 -1
  68. package/src/web-components/select/component.ts +109 -173
  69. package/src/web-components/split/component.ts +2 -2
  70. package/src/web-components/switch/component.ts +2 -1
  71. package/src/web-components/tabs/component.ts +99 -100
  72. package/src/web-components/text/component.ts +47 -52
  73. package/src/web-components/time/component.ts +5 -15
  74. package/src/web-components/tooltip/component.ts +44 -111
  75. package/vscode.css-custom-data.json +1 -1
  76. package/vscode.html-custom-data.json +1 -1
  77. package/web-components/alert/component.d.ts.map +1 -1
  78. package/web-components/alert/component.js +1 -1
  79. package/web-components/alert/component.js.map +1 -1
  80. package/web-components/avatar/component.d.ts.map +1 -1
  81. package/web-components/avatar/component.js +1 -1
  82. package/web-components/avatar/component.js.map +1 -1
  83. package/web-components/button/component.d.ts.map +1 -1
  84. package/web-components/button/component.js +1 -1
  85. package/web-components/button/component.js.map +1 -1
  86. package/web-components/card/component.d.ts.map +1 -1
  87. package/web-components/card/component.js +1 -1
  88. package/web-components/card/component.js.map +1 -1
  89. package/web-components/chip/component.d.ts +1 -3
  90. package/web-components/chip/component.d.ts.map +1 -1
  91. package/web-components/chip/component.js.map +1 -1
  92. package/web-components/details/component.d.ts +9 -13
  93. package/web-components/details/component.d.ts.map +1 -1
  94. package/web-components/details/component.js +1 -1
  95. package/web-components/details/component.js.map +1 -1
  96. package/web-components/dialog/component.d.ts +12 -14
  97. package/web-components/dialog/component.d.ts.map +1 -1
  98. package/web-components/dialog/component.js +1 -1
  99. package/web-components/dialog/component.js.map +1 -1
  100. package/web-components/heading/component.d.ts.map +1 -1
  101. package/web-components/heading/component.js +1 -1
  102. package/web-components/heading/component.js.map +1 -1
  103. package/web-components/input/component.d.ts +3 -1
  104. package/web-components/input/component.d.ts.map +1 -1
  105. package/web-components/input/component.js +1 -1
  106. package/web-components/input/component.js.map +1 -1
  107. package/web-components/layout/component.d.ts.map +1 -1
  108. package/web-components/layout/component.js +1 -1
  109. package/web-components/layout/component.js.map +1 -1
  110. package/web-components/link/component.d.ts.map +1 -1
  111. package/web-components/link/component.js +1 -1
  112. package/web-components/link/component.js.map +1 -1
  113. package/web-components/popover/component.d.ts +35 -0
  114. package/web-components/popover/component.d.ts.map +1 -0
  115. package/web-components/popover/component.js +2 -0
  116. package/web-components/popover/component.js.map +1 -0
  117. package/web-components/popover/definition.d.ts +8 -0
  118. package/web-components/popover/definition.d.ts.map +1 -0
  119. package/web-components/popover/definition.js +2 -0
  120. package/web-components/popover/definition.js.map +1 -0
  121. package/web-components/range/component.d.ts.map +1 -1
  122. package/web-components/range/component.js +1 -1
  123. package/web-components/range/component.js.map +1 -1
  124. package/web-components/rotate/component.d.ts.map +1 -1
  125. package/web-components/rotate/component.js.map +1 -1
  126. package/web-components/select/component.d.ts +11 -27
  127. package/web-components/select/component.d.ts.map +1 -1
  128. package/web-components/select/component.js +1 -1
  129. package/web-components/select/component.js.map +1 -1
  130. package/web-components/split/component.js +1 -1
  131. package/web-components/split/component.js.map +1 -1
  132. package/web-components/switch/component.d.ts.map +1 -1
  133. package/web-components/switch/component.js +1 -1
  134. package/web-components/switch/component.js.map +1 -1
  135. package/web-components/tabs/component.d.ts +18 -25
  136. package/web-components/tabs/component.d.ts.map +1 -1
  137. package/web-components/tabs/component.js +1 -1
  138. package/web-components/tabs/component.js.map +1 -1
  139. package/web-components/text/component.d.ts +4 -7
  140. package/web-components/text/component.d.ts.map +1 -1
  141. package/web-components/text/component.js +1 -1
  142. package/web-components/text/component.js.map +1 -1
  143. package/web-components/time/component.d.ts +2 -2
  144. package/web-components/time/component.d.ts.map +1 -1
  145. package/web-components/time/component.js +1 -1
  146. package/web-components/time/component.js.map +1 -1
  147. package/web-components/tooltip/component.d.ts +15 -39
  148. package/web-components/tooltip/component.d.ts.map +1 -1
  149. package/web-components/tooltip/component.js +1 -1
  150. package/web-components/tooltip/component.js.map +1 -1
  151. package/web-types.json +1 -1
  152. package/internal/direction.d.ts +0 -27
  153. package/internal/direction.d.ts.map +0 -1
  154. package/internal/direction.js +0 -2
  155. package/internal/direction.js.map +0 -1
  156. package/internal/super-openable.d.ts +0 -15
  157. package/internal/super-openable.d.ts.map +0 -1
  158. package/internal/super-openable.js +0 -2
  159. package/internal/super-openable.js.map +0 -1
  160. package/src/internal/direction.ts +0 -65
  161. package/src/internal/super-openable.ts +0 -34
@@ -2,52 +2,32 @@ import { attr, godown, htmlSlot, StyleController, styles, tokenList } from "@god
2
2
  import { cssGlobalVars, GlobalStyle, scopePrefix } from "../../internal/global-style.js";
3
3
  import { css, html, type TemplateResult } from "lit";
4
4
  import { property, queryAll } from "lit/decorators.js";
5
- import { RingBuilder, type RingType } from "../../internal/ring.js";
5
+ import { RingBuilder, ringTypeAttribute, type RingType } from "../../internal/ring.js";
6
6
 
7
7
  const protoName = "tabs";
8
8
  const cssScope = scopePrefix(protoName);
9
9
 
10
- const mouseEnterAddedToken = "hover";
10
+ const hoverToken = "hover";
11
11
 
12
12
  /**
13
13
  * {@linkcode Tabs} used to render a set of tabs.
14
14
  *
15
- * It accepts "tabs" to present the sub-content.
16
- *
17
- * When "useSlot" is enabled, each item in "tabs" becomes a named slot with the same name as itself,
18
- * while for non-slot tabs, the content is rendered as a horizontally padded string.
19
- *
20
- * When "mouseenter" and "mouseleave" are triggered on an individual tab, the indicator will move.
21
- *
22
- * The moving indicator will start from the position of the item that was last entered.
23
- *
24
- * If the pointer moves out of the root element or the element is connected to the document,
25
- * the starting position of the indicator will be regarded as the current selection.
26
- *
27
- * Apply "flex-direction: column" to the tabs to arrange them vertically.
28
- *
29
- * @csspart root - The root element.
30
- * @csspart item - The tab items.
31
- * @csspart indicator - The indicator.
32
- * @csspart selected - The selected tab item.
33
- * @csspart hover - The hovered tab item.
34
- * @fires select - Fires when the tab is selected.
15
+ * @fires select - Fires when the tab index is changed.
35
16
  * @category display
36
17
  */
37
18
  @godown(protoName)
38
19
  @styles(css`
39
20
  :host {
40
21
  ${cssScope}--indicator-background: var(${cssGlobalVars.passive});
41
- ${cssScope}--space: 0.25em;
42
- border-radius: var(${cssGlobalVars.radius});
43
- transition: 0.3s ease-in-out;
44
- width: fit-content;
22
+ ${cssScope}--selected-background: var(${cssGlobalVars.passive});
23
+ transition: 0.2s ease-in-out;
45
24
  display: flex;
46
25
  cursor: default;
47
26
  }
48
27
 
49
28
  [part="root"] {
50
- padding: 0.2em;
29
+ gap: 0.25em;
30
+ padding: 0.25em;
51
31
  position: relative;
52
32
  z-index: 1;
53
33
  display: flex;
@@ -56,14 +36,10 @@ const mouseEnterAddedToken = "hover";
56
36
  border-radius: inherit;
57
37
  transition: inherit;
58
38
  transition-property: width, transform, opacity;
59
- gap: var(${cssScope}--space);
60
- }
61
-
62
- [useslot] [part~="item"] {
63
- padding: 0;
64
39
  }
65
40
 
66
41
  [part~="item"] {
42
+ position: relative;
67
43
  width: 100%;
68
44
  display: block;
69
45
  padding: 0 0.25em;
@@ -74,12 +50,11 @@ const mouseEnterAddedToken = "hover";
74
50
  transition-property: inherit;
75
51
  }
76
52
 
77
- [part="indicator"] {
53
+ [part="indicator"],
54
+ [part~="item"]::after {
78
55
  width: 100%;
79
56
  height: 100%;
80
57
  inset: 0;
81
- opacity: 0;
82
- z-index: -1;
83
58
  position: absolute;
84
59
  transition: inherit;
85
60
  border-radius: inherit;
@@ -87,27 +62,58 @@ const mouseEnterAddedToken = "hover";
87
62
  background: var(${cssScope}--indicator-background);
88
63
  }
89
64
 
90
- [part~="selected"] {
91
- background: var(${cssScope}--indicator-background);
65
+ [part="indicator"] {
66
+ opacity: 0;
67
+ z-index: -1;
68
+ }
69
+
70
+ [part~="item"]::after {
71
+ z-index: -2;
72
+ }
73
+
74
+ [indicator="underline"] [part="indicator"],
75
+ [indicator="underline"] [part~="item"]::after {
76
+ top: 100%;
77
+ height: 0.15em;
78
+ border-radius: 0.075em;
79
+ margin-top: 0.15em;
80
+ }
81
+
82
+ [part~="selected"]::after {
83
+ content: "";
84
+ background: var(${cssScope}--selected-background);
92
85
  }
93
86
 
94
- [part~="selected"] [part="indicator"],
95
87
  [part~="hover"] [part="indicator"] {
96
88
  opacity: 1;
97
89
  }
98
90
  `)
99
91
  class Tabs extends GlobalStyle {
100
- @property({ attribute: "ring-type" })
92
+ @property({ attribute: ringTypeAttribute })
101
93
  ringType: RingType = "border";
102
94
 
103
95
  /**
104
- * Determines whether the tabs should use a slot for their content instead of a string.
96
+ * If it is "select", the indicator moves from the selected content to the hover position.
97
+ *
98
+ * If it is "previous", the indicator moves from the last moved position to the hover position.
99
+ *
100
+ * If "none", the indicator will not move.
101
+ */
102
+ @property()
103
+ beginning: "selected" | "previous" | "none" = "selected";
104
+
105
+ /**
106
+ * The behavior of the indicator:
107
+ *
108
+ * If "background", its size will be consistent with that of a single tab.
109
+ *
110
+ * If "underline", an underline will be displayed at the bottom of the tab.
105
111
  */
106
- @property({ type: Boolean })
107
- useSlot = false;
112
+ @property()
113
+ indicator: "background" | "underline" = "background";
108
114
 
109
115
  /**
110
- * An array of strings or slot content representing the tabs.
116
+ * Tab list or slot list.
111
117
  */
112
118
  @property({ type: Array })
113
119
  tabs: string[];
@@ -118,7 +124,7 @@ class Tabs extends GlobalStyle {
118
124
  @property({ type: Number })
119
125
  index = 0;
120
126
 
121
- protected _lastIndex: number;
127
+ protected previousIndex: number;
122
128
 
123
129
  @queryAll("[part~=item]")
124
130
  protected _items: HTMLCollectionOf<HTMLLIElement>;
@@ -138,24 +144,20 @@ class Tabs extends GlobalStyle {
138
144
  ${attr(this.observedRecord)}
139
145
  @mouseleave="${this._handleMouseLeave}"
140
146
  >
141
- ${this.tabs?.map((tab, index) =>
142
- tab || this.useSlot
143
- ? html`
144
- <li
145
- part="${tokenList("item", {
146
- selected: this.index === index,
147
- })}"
148
- @mouseenter=${() => {
149
- this.move(this._lastIndex, index);
150
- this._lastIndex = index;
151
- }}
152
- @click=${() => this.select(index)}
153
- >
154
- ${this.useSlot ? htmlSlot(tab) : tab}
155
- <div part="indicator"></div>
156
- </li>
157
- `
158
- : "",
147
+ ${this.tabs?.map(
148
+ (tab, index) => html`
149
+ <li
150
+ part="${tokenList("item", this.index === index && "selected")}"
151
+ @mouseenter=${() => {
152
+ this.move(this.previousIndex, index);
153
+ this.previousIndex = index;
154
+ }}
155
+ @click=${() => this.select(index)}
156
+ >
157
+ ${htmlSlot(tab, tab)}
158
+ <div part="indicator"></div>
159
+ </li>
160
+ `,
159
161
  )}
160
162
  </ul>
161
163
  `;
@@ -163,65 +165,62 @@ class Tabs extends GlobalStyle {
163
165
 
164
166
  connectedCallback(): void {
165
167
  super.connectedCallback();
166
- this._lastIndex = this.index;
168
+ this.previousIndex = this.beginning === "selected" ? this.index : -1;
167
169
  }
168
170
 
169
171
  protected _handleMouseLeave(): void {
170
- const lastItem = this._items[this._lastIndex];
172
+ const lastItem = this._items[this.previousIndex];
171
173
  if (lastItem) {
172
- lastItem.part.remove(mouseEnterAddedToken);
174
+ lastItem.part.remove(hoverToken);
173
175
  }
174
- this._lastIndex = this.index;
176
+ this.previousIndex = this.beginning === "selected" ? this.index : -1;
175
177
  }
176
178
 
177
- move(from: number, to: number): void {
178
- if (from === to) {
179
+ move(sourceIndex: number, targetIndex: number): void {
180
+ if (sourceIndex === targetIndex) {
179
181
  return;
180
182
  }
181
183
  const { _items, _indicators } = this;
182
- const toItem = _items[to];
183
- if (!toItem) {
184
+ const targetElement = _items[targetIndex];
185
+ if (!targetElement) {
184
186
  return;
185
187
  }
186
- toItem.part.add(mouseEnterAddedToken);
187
- const fromItem = _items[from];
188
+ targetElement.part.add(hoverToken);
189
+ const fromItem = _items[sourceIndex];
188
190
  if (!fromItem) {
189
191
  return;
190
192
  }
191
- fromItem.part.remove(mouseEnterAddedToken);
192
- const toIndicator = _indicators[to];
193
- const fromIndicator = _indicators[from];
194
- if (!toIndicator || !fromIndicator) {
193
+ fromItem.part.remove(hoverToken);
194
+ if (this.beginning === "none") {
195
195
  return;
196
196
  }
197
- const fromIndicatorRect = fromIndicator.getBoundingClientRect();
198
- const toItemRect = toItem.getBoundingClientRect();
199
- const transformX = fromIndicatorRect.x - toItemRect.x;
200
- const transformY = fromIndicatorRect.y - toItemRect.y;
201
- const fromWidth = fromIndicatorRect.width;
202
-
203
- const { style } = toIndicator;
204
- const cssNone = "none";
205
-
206
- style.transform = `translate3d(${transformX}px,${transformY}px,0)`;
207
- style.width = fromWidth + "px";
208
- style.transition = fromIndicator.style.transition = cssNone;
209
-
210
- toIndicator.getBoundingClientRect();
211
-
212
- style.width = style.transform = style.transition = fromIndicator.style.transition = "";
197
+ const targetIndicator = _indicators[targetIndex];
198
+ const sourceIndicator = _indicators[sourceIndex];
199
+ if (!targetIndicator || !sourceIndicator) {
200
+ return;
201
+ }
202
+ const { x: sourceX, y: sourceY, width: sourceWidth } = sourceIndicator.getBoundingClientRect();
203
+ const { x, y } = targetIndicator.getBoundingClientRect();
204
+ const transformX = sourceX - x;
205
+ const transformY = sourceY - y;
206
+
207
+ const { style: targetStyle } = targetIndicator;
208
+ const { style: sourceStyle } = sourceIndicator;
209
+
210
+ targetStyle.transform = `translate3d(${transformX}px,${transformY}px,0)`;
211
+ targetStyle.width = `${sourceWidth}px`;
212
+ targetStyle.transition = sourceStyle.transition = "none";
213
+ targetIndicator.getBoundingClientRect();
214
+ targetStyle.width = targetStyle.transform = targetStyle.transition = sourceStyle.transition = "";
213
215
  }
214
216
 
215
217
  select(selected: number): void {
216
- const { index, tabs, _lastIndex, useSlot } = this;
217
- if (!tabs || index === selected || !(selected in tabs)) {
218
- return;
219
- }
220
- this.dispatchCustomEvent("select", selected);
221
- this.move(_lastIndex, selected);
222
- this._lastIndex = selected;
223
- if (index in tabs && (tabs[index] || useSlot)) {
218
+ const { index, previousIndex } = this;
219
+ this.move(previousIndex, selected);
220
+ if (selected !== index) {
221
+ this.previousIndex = selected;
224
222
  this.index = selected;
223
+ this.dispatchCustomEvent("select", selected);
225
224
  }
226
225
  }
227
226
  }
@@ -1,13 +1,11 @@
1
- import { attr, tokenList, godown, htmlSlot, styles } from "@godown/element";
1
+ import { godown, htmlSlot, styles } from "@godown/element";
2
2
  import { type TemplateResult, css, html } from "lit";
3
3
  import { property } from "lit/decorators.js";
4
4
 
5
- import { GlobalStyle, cssGlobalVars, scopePrefix } from "../../internal/global-style.js";
5
+ import { GlobalStyle, cssGlobalVars } from "../../internal/global-style.js";
6
6
 
7
7
  const protoName = "text";
8
8
 
9
- const cssScope = scopePrefix(protoName);
10
-
11
9
  /**
12
10
  * {@linkcode Text} renders text.
13
11
  *
@@ -15,74 +13,71 @@ const cssScope = scopePrefix(protoName);
15
13
  */
16
14
  @godown(protoName)
17
15
  @styles(css`
18
- :host {
19
- ${cssScope}--color: currentColor;
20
- ${cssScope}--color-hover: currentColor;
21
- ${cssScope}--color-active: currentColor;
16
+ :host([clip]) {
17
+ background: var(${cssGlobalVars.backgroundClip});
22
18
  display: inline-block;
23
- text-overflow: ellipsis;
24
- overflow-wrap: break-word;
19
+ color: transparent;
20
+ -webkit-text-fill-color: transparent;
21
+ background-clip: text;
22
+ -webkit-background-clip: text;
25
23
  }
26
24
 
27
- [part="root"] {
25
+ :host([nowrap]) {
28
26
  white-space: nowrap;
29
- vertical-align: bottom;
30
- display: inline-block;
31
- text-overflow: inherit;
32
- overflow-wrap: inherit;
33
- overflow: hidden;
34
- color: var(${cssScope}--color);
35
27
  }
36
28
 
37
- [part="root"]:hover {
38
- color: var(${cssScope}--color-hover, var(${cssScope}--color));
29
+ :host([italic]) {
30
+ font-style: italic;
39
31
  }
40
32
 
41
- [part="root"]:active {
42
- color: var(${cssScope}--color-active, var(${cssScope}--color));
43
- }
44
-
45
- .hover:hover,
46
- .active:active,
47
- .always {
48
- text-decoration: underline;
33
+ :host([truncate]),
34
+ :host([truncate]) ::slotted(*) {
35
+ max-width: 100%;
36
+ overflow: hidden;
37
+ text-overflow: ellipsis;
49
38
  }
50
39
 
51
- .none {
52
- text-decoration: none;
40
+ :host([strikethrough]) {
41
+ text-decoration: line-through;
53
42
  }
54
43
 
55
- [clip] {
56
- background: var(${cssGlobalVars.backgroundClip});
57
- display: inline-block;
58
- color: transparent;
59
- -webkit-text-fill-color: transparent;
60
- background-clip: text;
61
- -webkit-background-clip: text;
44
+ :host([underline=""]),
45
+ :host([underline="always"]),
46
+ :host(:hover[underline="hover"]),
47
+ :host(:active[underline="active"]),
48
+ :host(:focus[underline="focus"]) {
49
+ text-decoration: underline;
62
50
  }
63
51
  `)
64
52
  class Text extends GlobalStyle {
65
- /**
66
- * Underline behavior.
67
- */
68
- @property()
69
- underline: "none" | "hover" | "active" | "always" = "none";
53
+ @property({
54
+ converter: {
55
+ fromAttribute(value) {
56
+ return value === "" ? true : value;
57
+ },
58
+ toAttribute(value) {
59
+ return value === false ? null : value === true ? "" : value;
60
+ },
61
+ },
62
+ reflect: true,
63
+ })
64
+ underline: "none" | "hover" | "active" | "always" | boolean = "none";
65
+
66
+ @property({ type: Boolean, reflect: true })
67
+ nowrap = false;
68
+
69
+ @property({ type: Boolean, reflect: true })
70
+ italic = false;
71
+
72
+ @property({ type: Boolean, reflect: true })
73
+ truncate = false;
70
74
 
71
- /**
72
- * Set background-clip to text.
73
- */
74
- @property({ type: Boolean })
75
+ @property({ type: Boolean, reflect: true })
75
76
  clip = false;
76
77
 
77
78
  protected render(): TemplateResult<1> {
78
79
  return html`
79
- <span
80
- part="root"
81
- ${attr(this.observedRecord)}
82
- class="${tokenList(this.underline)}"
83
- >
84
- ${htmlSlot()}
85
- </span>
80
+ <p part="root">${htmlSlot()}</p>
86
81
  `;
87
82
  }
88
83
  }
@@ -1,9 +1,9 @@
1
- import { attr, godown, styles } from "@godown/element";
1
+ import { attr, godown } from "@godown/element";
2
2
  import fmtime from "fmtime";
3
- import { type PropertyValues, type TemplateResult, css, html } from "lit";
3
+ import { type PropertyValues, type TemplateResult, html } from "lit";
4
4
  import { property } from "lit/decorators.js";
5
5
 
6
- import { GlobalStyle } from "../../internal/global-style.js";
6
+ import Text from "../text/component.js";
7
7
 
8
8
  const protoName = "time";
9
9
 
@@ -14,12 +14,7 @@ const protoName = "time";
14
14
  * @category display
15
15
  */
16
16
  @godown(protoName)
17
- @styles(css`
18
- :host {
19
- text-align: center;
20
- }
21
- `)
22
- class Time extends GlobalStyle {
17
+ class Time extends Text {
23
18
  /**
24
19
  * Escape symbol.
25
20
  */
@@ -54,12 +49,7 @@ class Time extends GlobalStyle {
54
49
 
55
50
  protected render(): TemplateResult<1> {
56
51
  return html`
57
- <span
58
- part="root"
59
- ${attr(this.observedRecord)}
60
- >
61
- ${fmtime(this.format, this.time, this.escape)}
62
- </span>
52
+ <p part="root">${fmtime(this.format, this.time, this.escape)}</p>
63
53
  `;
64
54
  }
65
55
 
@@ -1,138 +1,71 @@
1
- import { attr, godown, htmlSlot, styles } from "@godown/element";
2
- import { type TemplateResult, css, html } from "lit";
1
+ import { godown, htmlSlot } from "@godown/element";
2
+ import { type TemplateResult, html } from "lit";
3
3
  import { property } from "lit/decorators.js";
4
4
 
5
- import { scopePrefix } from "../../internal/global-style.js";
6
- import { SuperOpenable } from "../../internal/super-openable.js";
7
- import { type DirectionCardinal, type DirectionCorner, directionOutsetPlace } from "../../internal/direction.js";
5
+ import Popover from "../popover/component.js";
8
6
 
9
7
  const protoName = "tooltip";
10
- const cssScope = scopePrefix(protoName);
11
8
 
12
9
  /**
13
- * {@linkcode Tooltip} provide tooltip for slot elements.
10
+ * {@linkcode Tooltip} is similar to {@linkcode Popover}.
14
11
  *
15
- * If it has the tip property, ignore the slot tip.
12
+ * It listens for the mouseenter event and displays the tip or popover after a specified delay.
16
13
  *
17
- * @slot tip - Tip element if no `tip` provided.
18
- * @slot - Content.
14
+ * When it is clicked or the mouseleave event occurs followed by another delay, closes the tip.
15
+ *
16
+ * @fires toggle - Fired when the popover is toggled.
17
+ * @slot tip - Tip content.
18
+ * @slot - Tip trigger.
19
19
  * @category feedback
20
20
  */
21
21
  @godown(protoName)
22
- @styles(
23
- directionOutsetPlace,
24
- css`
25
- :host {
26
- ${cssScope}--tip-background: inherit;
27
- width: fit-content;
28
- }
29
-
30
- :host,
31
- [part="root"] {
32
- display: inline-flex;
33
- }
34
-
35
- [part="root"] {
36
- position: relative;
37
- transition: inherit;
38
- border-radius: inherit;
39
- }
40
-
41
- [part="tip"] {
42
- width: fit-content;
43
- height: fit-content;
44
- position: absolute;
45
- visibility: hidden;
46
- transition: inherit;
47
- user-select: none;
48
- }
49
-
50
- :host([open]) [part="tip"] {
51
- visibility: visible;
52
- }
22
+ class Tooltip extends Popover {
23
+ action: "hide";
24
+ span: "span" | "isolated";
53
25
 
54
- .passive {
55
- background: var(${cssScope}--tip-background);
56
- }
57
-
58
- [propagation] [part="tip"] {
59
- pointer-events: none;
60
- }
61
- `,
62
- )
63
- class Tooltip extends SuperOpenable {
64
- /**
65
- * Tip text, if there is a value, the slot will be ignored.
66
- */
67
26
  @property()
68
27
  tip: string;
69
28
 
70
- /**
71
- * Direction of opening the tip.
72
- */
73
- @property()
74
- direction: DirectionCardinal | DirectionCorner = "top";
75
-
76
- /**
77
- * Content alignment.
78
- */
79
- @property()
80
- align: "center" | "flex-start" | "flex-end" | "start" | "end" = "center";
81
-
82
- /**
83
- * If true, allow penetration of the tip.
84
- */
85
- @property({ type: Boolean })
86
- propagation = false;
87
-
88
- /**
89
- * How can tips be triggered.
90
- *
91
- * If `focus`, element will be focusable, open tip when focused.
92
- *
93
- * If `hover`, element will open tip when hovered.
94
- *
95
- * @default "hover"
96
- */
97
- @property()
98
- type: "hover" | "focus" = "hover";
99
-
100
- static aligns = {
101
- start: "flex-start",
102
- end: "flex-end",
103
- center: "center",
104
- "flex-start": "flex-start",
105
- "flex-end": "flex-end",
106
- };
29
+ @property({ type: Number })
30
+ delay = 300;
107
31
 
108
32
  protected render(): TemplateResult<1> {
109
- const align = Tooltip.aligns[this.align] || "inherit";
110
- const isFocusable = this.type === "focus";
111
33
  return html`
112
- <div
113
- part="root"
114
- ${attr(this.observedRecord)}
115
- tabindex="${isFocusable ? 0 : -1}"
116
- @focus="${isFocusable ? () => (this.open = true) : null}"
117
- @blur="${isFocusable ? () => (this.open = false) : null}"
118
- @mouseenter="${isFocusable ? null : () => (this.open = true)}"
119
- @mouseleave="${isFocusable ? null : () => (this.open = false)}"
120
- style="justify-content:${align};align-items:${align}"
121
- >
122
- ${htmlSlot()}
34
+ <div part="root">
123
35
  <div
124
- part="tip"
125
- direction-outset-place
36
+ part="trigger"
37
+ @click=${this.hide}
126
38
  >
127
- ${this.tip
128
- ? html`
129
- <span class="passive">${this.tip}</span>
130
- `
131
- : htmlSlot("tip")}
39
+ ${htmlSlot()}
40
+ </div>
41
+ <div
42
+ part="popover"
43
+ popover="manual"
44
+ >
45
+ ${htmlSlot("tip", this.tip)}
132
46
  </div>
133
47
  </div>
134
48
  `;
135
49
  }
50
+
51
+ _hoverTimeout: number;
52
+ _leaveTimeout: number;
53
+
54
+ connectedCallback(): void {
55
+ super.connectedCallback();
56
+ this.events.add(this, "mouseenter", () => {
57
+ clearTimeout(this._leaveTimeout);
58
+ this._hoverTimeout = setTimeout(() => {
59
+ this.show();
60
+ }, this.delay);
61
+ });
62
+ this.events.add(this, "mouseleave", () => {
63
+ clearTimeout(this._hoverTimeout);
64
+ this._leaveTimeout = setTimeout(() => {
65
+ this.hide();
66
+ }, this.delay);
67
+ });
68
+ }
136
69
  }
137
70
 
138
71
  export default Tooltip;
@@ -1 +1 @@
1
- {"version":1.1,"properties":[],"pseudoElements":[{"name":"::part(root)","description":"The root element."},{"name":"::part(item)","description":"The tab items."},{"name":"::part(indicator)","description":"The indicator."},{"name":"::part(selected)","description":"The selected tab item."},{"name":"::part(hover)","description":"The hovered tab item."}]}
1
+ {"version":1.1,"properties":[],"pseudoElements":[]}