@geoffcox/sterling-svelte 0.0.31 → 1.0.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 (215) hide show
  1. package/@types/clickOutside.d.ts +11 -7
  2. package/Button.svelte +11 -183
  3. package/Button.svelte.d.ts +2 -6
  4. package/Callout.svelte +107 -146
  5. package/Callout.svelte.d.ts +1 -1
  6. package/Checkbox.svelte +15 -177
  7. package/Checkbox.svelte.d.ts +2 -2
  8. package/ColorPicker.svelte +204 -223
  9. package/ColorPicker.svelte.d.ts +1 -2
  10. package/Dialog.svelte +91 -187
  11. package/Dialog.svelte.d.ts +3 -1
  12. package/Dropdown.svelte +52 -220
  13. package/Dropdown.svelte.d.ts +4 -8
  14. package/HexColorSliders.svelte +77 -145
  15. package/HexColorSliders.svelte.d.ts +28 -1
  16. package/HslColorSliders.svelte +99 -179
  17. package/HslColorSliders.svelte.d.ts +28 -1
  18. package/Input.svelte +27 -136
  19. package/Input.svelte.d.ts +2 -3
  20. package/Label.constants.d.ts +1 -0
  21. package/Label.constants.js +1 -0
  22. package/Label.svelte +96 -169
  23. package/Label.svelte.d.ts +6 -1
  24. package/Label.types.d.ts +3 -1
  25. package/Link.svelte +9 -106
  26. package/Link.svelte.d.ts +0 -1
  27. package/List.svelte +142 -230
  28. package/List.svelte.d.ts +2 -3
  29. package/List.types.d.ts +6 -1
  30. package/ListItem.svelte +25 -94
  31. package/ListItem.svelte.d.ts +2 -0
  32. package/Menu.svelte +48 -65
  33. package/Menu.svelte.d.ts +4 -1
  34. package/MenuBar.svelte +84 -86
  35. package/MenuBar.svelte.d.ts +4 -1
  36. package/MenuButton.svelte +66 -73
  37. package/MenuButton.svelte.d.ts +7 -3
  38. package/MenuItem.svelte +256 -288
  39. package/MenuItem.svelte.d.ts +2 -2
  40. package/MenuItemDisplay.svelte +12 -116
  41. package/MenuItemDisplay.svelte.d.ts +21 -7
  42. package/MenuSeparator.svelte +6 -45
  43. package/MenuSeparator.svelte.d.ts +8 -78
  44. package/Popover.constants.d.ts +1 -1
  45. package/Popover.constants.js +1 -1
  46. package/Popover.svelte +66 -80
  47. package/Popover.svelte.d.ts +5 -1
  48. package/Progress.svelte +28 -126
  49. package/Progress.svelte.d.ts +4 -3
  50. package/Radio.svelte +49 -192
  51. package/Radio.svelte.d.ts +2 -2
  52. package/RgbColorSliders.svelte +48 -137
  53. package/RgbColorSliders.svelte.d.ts +5 -5
  54. package/Select.svelte +122 -250
  55. package/Select.svelte.d.ts +6 -2
  56. package/Slider.svelte +90 -259
  57. package/Slider.svelte.d.ts +1 -2
  58. package/Switch.svelte +24 -259
  59. package/Switch.svelte.d.ts +3 -1
  60. package/Tab.svelte +27 -175
  61. package/Tab.svelte.d.ts +6 -4
  62. package/TabList.svelte +146 -171
  63. package/TabList.svelte.d.ts +3 -2
  64. package/TabList.types.d.ts +6 -1
  65. package/TextArea.svelte +32 -129
  66. package/TextArea.svelte.d.ts +1 -1
  67. package/Tooltip.svelte +46 -47
  68. package/Tooltip.svelte.d.ts +8 -3
  69. package/Tree.constants.d.ts +0 -1
  70. package/Tree.constants.js +0 -1
  71. package/Tree.svelte +35 -119
  72. package/Tree.svelte.d.ts +4 -4
  73. package/Tree.types.d.ts +1 -3
  74. package/TreeChevron.svelte +18 -98
  75. package/TreeChevron.svelte.d.ts +1 -0
  76. package/TreeItem.constants.d.ts +1 -0
  77. package/TreeItem.constants.js +1 -0
  78. package/TreeItem.svelte +251 -211
  79. package/TreeItem.svelte.d.ts +7 -3
  80. package/TreeItem.types.d.ts +1 -1
  81. package/TreeItemDisplay.svelte +20 -104
  82. package/TreeItemDisplay.svelte.d.ts +2 -2
  83. package/actions/applyLightDarkMode.d.ts +10 -0
  84. package/actions/applyLightDarkMode.js +36 -0
  85. package/actions/forwardEvents.js +3 -3
  86. package/css/Button.base.css +74 -0
  87. package/css/Button.colorful.css +17 -0
  88. package/css/Button.css +7 -0
  89. package/css/Button.secondary.colorful.css +15 -0
  90. package/css/Button.secondary.css +11 -0
  91. package/css/Button.shapes.css +14 -0
  92. package/css/Button.tool.colorful.css +13 -0
  93. package/css/Button.tool.css +18 -0
  94. package/css/Callout.base.css +43 -0
  95. package/css/Callout.colorful.css +5 -0
  96. package/css/Callout.css +2 -0
  97. package/css/Checkbox.base.css +145 -0
  98. package/css/Checkbox.colorful.css +17 -0
  99. package/css/Checkbox.css +2 -0
  100. package/css/ColorPicker.base.css +23 -0
  101. package/css/ColorPicker.css +1 -0
  102. package/css/Dialog.base.css +116 -0
  103. package/css/Dialog.css +1 -0
  104. package/css/Dropdown.base.css +147 -0
  105. package/css/Dropdown.colorful.css +23 -0
  106. package/css/Dropdown.css +2 -0
  107. package/css/HexColorSliders.base.css +106 -0
  108. package/css/HexColorSliders.css +1 -0
  109. package/css/HslColorSliders.base.css +124 -0
  110. package/css/HslColorSliders.css +1 -0
  111. package/css/Input.base.css +100 -0
  112. package/css/Input.colorful.css +22 -0
  113. package/css/Input.composed.css +8 -0
  114. package/css/Input.css +3 -0
  115. package/css/Label.base.css +119 -0
  116. package/css/Label.boxed.colorful.css +21 -0
  117. package/css/Label.boxed.css +31 -0
  118. package/css/Label.colorful.css +3 -0
  119. package/css/Label.css +4 -0
  120. package/css/Link.base.css +52 -0
  121. package/css/Link.colorful.css +15 -0
  122. package/css/Link.css +6 -0
  123. package/css/Link.ghost.colorful.css +7 -0
  124. package/css/Link.ghost.css +11 -0
  125. package/css/Link.undecorated.colorful.css +6 -0
  126. package/css/Link.undecorated.css +6 -0
  127. package/css/List.base.css +98 -0
  128. package/css/List.css +1 -0
  129. package/css/ListItem.base.css +59 -0
  130. package/css/ListItem.css +1 -0
  131. package/css/Menu.base.css +21 -0
  132. package/css/Menu.css +1 -0
  133. package/css/MenuBar.base.css +9 -0
  134. package/css/MenuBar.css +1 -0
  135. package/css/MenuButton.base.css +13 -0
  136. package/css/MenuButton.css +1 -0
  137. package/css/MenuItem.base.css +48 -0
  138. package/css/MenuItem.css +1 -0
  139. package/css/MenuItemDisplay.base.css +104 -0
  140. package/css/MenuItemDisplay.css +1 -0
  141. package/css/MenuSeparator.base.css +5 -0
  142. package/css/MenuSeparator.css +1 -0
  143. package/css/Popover copy.css +21 -0
  144. package/css/Popover.css +21 -0
  145. package/css/Progress.base.css +99 -0
  146. package/css/Progress.css +1 -0
  147. package/css/Radio.base.css +135 -0
  148. package/css/Radio.colorful.css +18 -0
  149. package/css/Radio.css +2 -0
  150. package/css/RgbColorSliders.base.css +94 -0
  151. package/css/RgbColorSliders.css +1 -0
  152. package/css/Select.base.css +127 -0
  153. package/css/Select.colorful.css +24 -0
  154. package/css/Select.composed.css +12 -0
  155. package/css/Select.css +3 -0
  156. package/css/Slider.base.css +182 -0
  157. package/css/Slider.colorful.css +11 -0
  158. package/css/Slider.composed.css +8 -0
  159. package/css/Slider.css +3 -0
  160. package/css/Switch.base.css +193 -0
  161. package/css/Switch.colorful.css +39 -0
  162. package/css/Switch.css +2 -0
  163. package/css/Tab.base.css +135 -0
  164. package/css/Tab.colorful.css +13 -0
  165. package/css/Tab.css +2 -0
  166. package/css/TabList.base.css +34 -0
  167. package/css/TabList.css +1 -0
  168. package/css/TextArea.base.css +85 -0
  169. package/css/TextArea.colorful.css +17 -0
  170. package/css/TextArea.composed.css +8 -0
  171. package/css/TextArea.css +3 -0
  172. package/css/Tooltip.base.css +6 -0
  173. package/css/Tooltip.css +1 -0
  174. package/css/Tree.base.css +74 -0
  175. package/css/Tree.composed.css +8 -0
  176. package/css/Tree.css +2 -0
  177. package/css/TreeChevron.base.css +86 -0
  178. package/css/TreeChevron.css +1 -0
  179. package/css/TreeItem.base.css +3 -0
  180. package/css/TreeItem.css +1 -0
  181. package/css/TreeItemDisplay.base.css +74 -0
  182. package/css/TreeItemDisplay.colorful.css +9 -0
  183. package/css/TreeItemDisplay.css +1 -0
  184. package/css/dark-mode.css +134 -0
  185. package/css/light-mode.css +134 -0
  186. package/css/sterling.css +37 -0
  187. package/index.d.ts +9 -13
  188. package/index.js +8 -12
  189. package/mediaQueries/prefersColorSchemeDark.d.ts +2 -0
  190. package/mediaQueries/prefersColorSchemeDark.js +10 -0
  191. package/{stores → mediaQueries}/prefersReducedMotion.d.ts +1 -0
  192. package/{stores → mediaQueries}/usingKeyboard.d.ts +1 -0
  193. package/package.json +121 -13
  194. package/Link.constants.d.ts +0 -1
  195. package/Link.constants.js +0 -1
  196. package/Link.types.d.ts +0 -4
  197. package/Link.types.js +0 -1
  198. package/theme/applyDarkTheme.d.ts +0 -7
  199. package/theme/applyDarkTheme.js +0 -11
  200. package/theme/applyLightTheme.d.ts +0 -7
  201. package/theme/applyLightTheme.js +0 -11
  202. package/theme/applyTheme.d.ts +0 -7
  203. package/theme/applyTheme.js +0 -20
  204. package/theme/colors.d.ts +0 -54
  205. package/theme/colors.js +0 -82
  206. package/theme/darkTheme.d.ts +0 -2
  207. package/theme/darkTheme.js +0 -142
  208. package/theme/lightTheme.d.ts +0 -2
  209. package/theme/lightTheme.js +0 -119
  210. package/theme/toggleDarkTheme.d.ts +0 -18
  211. package/theme/toggleDarkTheme.js +0 -53
  212. package/theme/types.d.ts +0 -21
  213. package/theme/types.js +0 -1
  214. /package/{stores → mediaQueries}/prefersReducedMotion.js +0 -0
  215. /package/{stores → mediaQueries}/usingKeyboard.js +0 -0
package/Switch.svelte CHANGED
@@ -1,36 +1,37 @@
1
- <script>import { idGenerator } from "./idGenerator";
1
+ <script>import { idGenerator } from './idGenerator';
2
+ // ----- Props ----- //
2
3
  export let checked = false;
3
4
  export let disabled = false;
4
- export let colorful = false;
5
- export let offText = void 0;
6
- export let onText = void 0;
5
+ /** The text appearing by the off position. Not used when the offLabel slot is filled. */
6
+ export let offText = undefined;
7
+ /** The text appearing near the on position. Not used when the onLabel slot is filled. */
8
+ export let onText = undefined;
9
+ /** Additional class names to apply. */
10
+ export let variant = '';
11
+ /** When true, the switch is displayed vertically. */
7
12
  export let vertical = false;
8
- const inputId = idGenerator.nextId("Switch");
13
+ // ----- State ----- //
14
+ const inputId = idGenerator.nextId('Switch');
9
15
  let inputRef;
10
16
  let switchWidth = 0;
11
17
  let switchHeight = 0;
12
18
  let thumbWidth = 0;
13
19
  let thumbHeight = 0;
14
- $:
15
- switchSize = vertical ? switchHeight : switchWidth;
16
- $:
17
- thumbSize = vertical ? thumbHeight : thumbWidth;
18
- $:
19
- ratio = vertical ? checked ? 0 : 1 : checked ? 1 : 0;
20
- $:
21
- valueOffset = (switchSize - thumbSize) * ratio;
22
- $:
23
- hasOffLabel = $$slots.offLabel || offText !== void 0 && offText.length > 0;
24
- $:
25
- hasOnLabel = $$slots.onLabel || onText !== void 0 && onText.length > 0;
20
+ $: switchSize = vertical ? switchHeight : switchWidth;
21
+ $: thumbSize = vertical ? thumbHeight : thumbWidth;
22
+ $: ratio = vertical ? (checked ? 0 : 1) : checked ? 1 : 0;
23
+ $: valueOffset = (switchSize - thumbSize) * ratio;
24
+ $: hasOffLabel = $$slots.offLabel || (offText !== undefined && offText.length > 0);
25
+ $: hasOnLabel = $$slots.onLabel || (onText !== undefined && onText.length > 0);
26
+ // ----- Methods ----- //
26
27
  export const blur = () => {
27
- inputRef?.blur();
28
+ inputRef?.blur();
28
29
  };
29
30
  export const click = () => {
30
- inputRef?.click();
31
+ inputRef?.click();
31
32
  };
32
33
  export const focus = (options) => {
33
- inputRef?.focus(options);
34
+ inputRef?.focus(options);
34
35
  };
35
36
  </script>
36
37
 
@@ -38,7 +39,7 @@ export const focus = (options) => {
38
39
  @component
39
40
  A styled HTML input type=checkbox element.
40
41
  -->
41
- <div class="sterling-switch" class:colorful class:disabled class:vertical>
42
+ <div class={`sterling-switch ${variant}`} class:disabled class:vertical>
42
43
  <input
43
44
  bind:this={inputRef}
44
45
  bind:checked
@@ -74,7 +75,7 @@ export const focus = (options) => {
74
75
  />
75
76
  {#if hasOffLabel}
76
77
  <div class="off-label">
77
- <slot name="offLabel" {checked} {disabled} {inputId} {offText} {vertical}>
78
+ <slot name="offLabel" {checked} {disabled} {inputId} {offText} {variant} {vertical}>
78
79
  {#if offText}
79
80
  <label for={inputId}>{offText}</label>
80
81
  {/if}
@@ -92,7 +93,7 @@ export const focus = (options) => {
92
93
  </div>
93
94
  {#if hasOnLabel}
94
95
  <div class="on-label">
95
- <slot name="onLabel" {checked} {disabled} {inputId} {onText} {vertical}>
96
+ <slot name="onLabel" {checked} {disabled} {inputId} {onText} {variant} {vertical}>
96
97
  {#if onText}
97
98
  <label for={inputId}>{onText}</label>
98
99
  {/if}
@@ -100,239 +101,3 @@ export const focus = (options) => {
100
101
  </div>
101
102
  {/if}
102
103
  </div>
103
-
104
- <style>
105
- .sterling-switch {
106
- cursor: pointer;
107
- display: grid;
108
- position: relative;
109
- }
110
-
111
- .sterling-switch input {
112
- cursor: pointer;
113
- }
114
-
115
- .sterling-switch.disabled input {
116
- cursor: not-allowed;
117
- }
118
-
119
- .sterling-switch:not(.vertical) {
120
- align-content: center;
121
- align-items: center;
122
- column-gap: 0.5em;
123
- grid-template-columns: auto auto auto;
124
- grid-template-rows: auto;
125
- justify-content: flex-start;
126
- justify-items: flex-start;
127
- }
128
-
129
- .sterling-switch.vertical {
130
- align-content: flex-start;
131
- align-items: flex-start;
132
- grid-template-columns: auto;
133
- grid-template-rows: auto auto auto;
134
- justify-content: center;
135
- justify-items: center;
136
- row-gap: 0.5em;
137
- }
138
-
139
- .sterling-switch.vertical .off-label {
140
- grid-row: 3 / span 1;
141
- }
142
-
143
- .sterling-switch.vertical .on-label {
144
- grid-row: 1 / span 1;
145
- }
146
-
147
- /* ----- input hidden ----- */
148
-
149
- input {
150
- font: inherit;
151
- margin: 0;
152
- padding: 0;
153
- position: absolute;
154
- left: 0;
155
- right: 0;
156
- bottom: 0;
157
- top: 0;
158
- opacity: 0;
159
- }
160
-
161
- /* ----- switch ----- */
162
-
163
- .switch {
164
- background-color: var(--stsv-input__background-color);
165
- border-color: var(--stsv-input__border-color);
166
- border-radius: 10000px;
167
- border-style: var(--stsv-input__border-style);
168
- border-width: var(--stsv-input__border-width);
169
- box-sizing: border-box;
170
- color: var(--stsv-input__color);
171
- font: inherit;
172
- pointer-events: none;
173
- position: relative;
174
- transition: background-color 250ms, color 250ms, border-color 250ms;
175
- user-select: none;
176
- }
177
-
178
- .sterling-switch:hover .switch {
179
- background-color: var(--stsv-input__background-color--hover);
180
- border-color: var(--stsv-input__border-color--hover);
181
- color: var(--stsv-input__color--hover);
182
- }
183
-
184
- input:focus-visible ~ .switch {
185
- background-color: var(--stsv-input__background-color--focus);
186
- border-color: var(--stsv-input__border-color--focus);
187
- color: var(--stsv-common__color--focux);
188
- outline-color: var(--stsv-common__outline-color);
189
- outline-offset: var(--stsv-common__outline-offset);
190
- outline-style: var(--stsv-common__outline-style);
191
- outline-width: var(--stsv-common__outline-width);
192
- }
193
-
194
- /* ----- switch vertical ----- */
195
-
196
- .sterling-switch:not(.vertical) .switch {
197
- width: 2em;
198
- height: 1.25em;
199
- }
200
-
201
- .sterling-switch.vertical .switch {
202
- width: 1.25em;
203
- height: 2em;
204
- }
205
-
206
- /* ----- labels ----- */
207
-
208
- label {
209
- color: var(--stsv-common__color);
210
- transition: color 250ms;
211
- font: inherit;
212
- }
213
-
214
- .off-label,
215
- .on-label {
216
- padding-top: var(--stsv-button__border-width);
217
- }
218
-
219
- /* ----- switch colorful ----- */
220
-
221
- .sterling-switch.colorful .switch {
222
- background-color: var(--stsv-input--colorful__background-color);
223
- border-color: var(--stsv-input--colorful__border-color);
224
- color: var(--stsv-input--colorful__color);
225
- }
226
-
227
- .sterling-switch.colorful:hover .switch {
228
- background-color: var(--stsv-input--colorful__background-color--hover);
229
- border-color: var(--stsv-input--colorful__border-color--hover);
230
- color: var(--stsv-input_--colorful_color--hover);
231
- }
232
-
233
- .sterling-switch.colorful input:focus-visible ~ .switch {
234
- background-color: var(--stsv-input--colorful__background-color--focus);
235
- border-color: var(--stsv-input--colorful__border-color--focus);
236
- color: var(--stsv-input--colorful__color--focus);
237
- }
238
-
239
- /* ----- thumb ----- */
240
-
241
- .thumb {
242
- background-color: var(--stsv-button__background-color);
243
- border-color: var(--stsv-button__border-color);
244
- border-radius: 10000px;
245
- border-style: var(--stsv-button__border-style);
246
- border-width: var(--stsv-button__border-width);
247
- box-sizing: border-box;
248
- color: var(--stsv-button__color);
249
- display: block;
250
- font: inherit;
251
- height: 1.25em;
252
- position: absolute;
253
- transition: background-color 250ms, color 250ms, border-color 250ms, transform 250ms;
254
- width: 1.25em;
255
- }
256
-
257
- .sterling-switch:hover .thumb {
258
- background-color: var(--stsv-button__background-color--hover);
259
- border-color: var(--stsv-button__border-color--hover);
260
- color: var(--stsv-button__color--hover);
261
- }
262
-
263
- .sterling-switch:active .thumb {
264
- background-color: var(--stsv-button__background-color--active);
265
- border-color: var(--stsv-button__border-color--active);
266
- color: var(--stsv-button__color--hover);
267
- }
268
-
269
- /* ----- thumb colorful ----- */
270
-
271
- .sterling-switch.colorful .thumb {
272
- background-color: var(--stsv-button--colorful__background-color);
273
- border-color: var(--stsv-button--colorful__border-color);
274
- color: var(--stsv-button--colorful__color);
275
- }
276
-
277
- .sterling-switch.colorful:hover .thumb {
278
- background-color: var(--stsv-button--colorful__background-color--hover);
279
- border-color: var(--stsv-button--colorful__border-color--hover);
280
- color: var(--stsv-button--colorful__color--hover);
281
- }
282
-
283
- .sterling-switch.colorful:active .thumb {
284
- background-color: var(--stsv-button--colorful__background-color--active);
285
- border-color: var(--stsv-button--colorful__border-color--active);
286
- color: var(--stsv-button--colorful__color--hover);
287
- }
288
-
289
- /* ----- thumb disabled ----- */
290
-
291
- .sterling-switch .thumb::after {
292
- background: repeating-linear-gradient(
293
- var(--stsv-common--disabled__stripe-angle),
294
- var(--stsv-common--disabled__stripe-color),
295
- var(--stsv-common--disabled__stripe-color) var(--stsv-common--disabled__stripe-width),
296
- var(--stsv-common--disabled__stripe-color--alt) var(--stsv-common--disabled__stripe-width),
297
- var(--stsv-common--disabled__stripe-color--alt)
298
- calc(2 * var(--stsv-common--disabled__stripe-width))
299
- );
300
- bottom: 0;
301
- border-radius: 10000px;
302
- content: '';
303
- left: 0;
304
- opacity: 0;
305
- position: absolute;
306
- right: 0;
307
- top: 0;
308
- pointer-events: none;
309
- transition: opacity 250ms;
310
- }
311
-
312
- .sterling-switch.disabled .thumb::after {
313
- opacity: 1;
314
- }
315
-
316
- /* ----- thumb vertical ----- */
317
-
318
- .sterling-switch:not(.vertical) .thumb {
319
- top: calc(-1 * var(--stsv-button__border-width));
320
- transform: translateX(calc(var(--thumb-offset) - var(--stsv-button__border-width)));
321
- }
322
-
323
- .sterling-switch.vertical .thumb {
324
- left: calc(-1 * var(--stsv-button__border-width));
325
- transform: translateY(calc(var(--thumb-offset) - var(--stsv-button__border-width)));
326
- }
327
-
328
- /* ----- reduced motion ----- */
329
-
330
- @media (prefers-reduced-motion) {
331
- .switch,
332
- .thumb,
333
- .thumb::after,
334
- label {
335
- transition: none;
336
- }
337
- }
338
- </style>
@@ -4,9 +4,9 @@ declare const __propDef: {
4
4
  [x: string]: any;
5
5
  checked?: boolean | undefined;
6
6
  disabled?: boolean | undefined;
7
- colorful?: boolean | undefined;
8
7
  offText?: string | undefined;
9
8
  onText?: string | undefined;
9
+ variant?: string | undefined;
10
10
  vertical?: boolean | undefined;
11
11
  blur?: (() => void) | undefined;
12
12
  click?: (() => void) | undefined;
@@ -47,6 +47,7 @@ declare const __propDef: {
47
47
  disabled: boolean;
48
48
  inputId: string;
49
49
  offText: string | undefined;
50
+ variant: string;
50
51
  vertical: boolean;
51
52
  };
52
53
  onLabel: {
@@ -54,6 +55,7 @@ declare const __propDef: {
54
55
  disabled: boolean;
55
56
  inputId: string;
56
57
  onText: string | undefined;
58
+ variant: string;
57
59
  vertical: boolean;
58
60
  };
59
61
  };
package/Tab.svelte CHANGED
@@ -1,43 +1,48 @@
1
- <script>import { getContext } from "svelte";
2
- import { TAB_LIST_CONTEXT_KEY } from "./TabList.constants";
3
- import { usingKeyboard } from "./stores/usingKeyboard";
1
+ <script>import { getContext } from 'svelte';
2
+ import { TAB_LIST_CONTEXT_KEY } from './TabList.constants';
3
+ import { usingKeyboard } from './mediaQueries/usingKeyboard';
4
+ // ----- Props ----- //
5
+ /**
6
+ * When true, the tab is disabled.
7
+ * The tab is also disabled when its parent tab list is disabled.
8
+ */
4
9
  export let disabled = false;
10
+ /** When true, the tab is selected. */
5
11
  export let selected = false;
6
- export let text = void 0;
12
+ /** The text of the tab. Not used when the default slot is filled. */
13
+ export let text = undefined;
14
+ /** The value uniquely identifying this tab within the tab list. */
7
15
  export let value;
16
+ /** Additional class names to apply. */
17
+ export let variant = '';
18
+ // ----- State ----- //
8
19
  let tabRef;
9
- const {
10
- colorful,
11
- disabled: tabListDisabled,
12
- selectedValue,
13
- vertical
14
- } = getContext(TAB_LIST_CONTEXT_KEY);
15
- $:
16
- _disabled = $tabListDisabled || disabled;
20
+ const { disabled: tabListDisabled, selectedValue, vertical } = getContext(TAB_LIST_CONTEXT_KEY);
21
+ $: _disabled = $tabListDisabled || disabled;
17
22
  $: {
18
- selected = $selectedValue === value;
23
+ selected = $selectedValue === value;
19
24
  }
20
25
  $: {
21
- if (selected) {
22
- selectedValue.set(value);
23
- }
26
+ if (selected) {
27
+ selectedValue.set(value);
28
+ }
24
29
  }
30
+ // ----- Methods ----- //
25
31
  export const click = () => {
26
- tabRef?.click();
32
+ tabRef?.click();
27
33
  };
28
34
  export const blur = () => {
29
- tabRef?.blur();
35
+ tabRef?.blur();
30
36
  };
31
37
  export const focus = (options) => {
32
- tabRef?.focus(options);
38
+ tabRef?.focus(options);
33
39
  };
34
40
  </script>
35
41
 
36
42
  <button
37
43
  bind:this={tabRef}
38
44
  aria-selected={selected}
39
- class="sterling-tab"
40
- class:colorful={$colorful}
45
+ class={`sterling-tab ${variant}`}
41
46
  disabled={_disabled}
42
47
  class:selected
43
48
  class:using-keyboard={$usingKeyboard}
@@ -79,7 +84,7 @@ export const focus = (options) => {
79
84
  on:wheel|passive
80
85
  >
81
86
  <div class="content">
82
- <slot disabled={_disabled} {selected} {value} {text}>
87
+ <slot disabled={_disabled} {selected} {text} {value} {variant}>
83
88
  <div class="text">
84
89
  {text || value}
85
90
  </div>
@@ -87,156 +92,3 @@ export const focus = (options) => {
87
92
  </div>
88
93
  <div class="indicator" />
89
94
  </button>
90
-
91
- <style>
92
- .sterling-tab {
93
- align-content: center;
94
- align-items: center;
95
- background-color: var(--stsv-common__background-color);
96
- border-color: transparent;
97
- border-radius: var(--stsv-button__border-radius);
98
- border-style: var(--stsv-common__border-style);
99
- border-width: 0;
100
- box-sizing: border-box;
101
- color: var(--stsv-common__color);
102
- cursor: pointer;
103
- display: grid;
104
- font: inherit;
105
- overflow: hidden;
106
- padding: 0.5em 1em 0.25em 1em;
107
- position: relative;
108
- text-decoration: none;
109
- text-overflow: ellipsis;
110
- transition: background-color 250ms, color 250ms, border-color 250ms;
111
- white-space: nowrap;
112
- }
113
-
114
- .sterling-tab:not(.vertical) {
115
- grid-template-columns: 1fr;
116
- grid-template-rows: 1fr 1em;
117
- justify-content: center;
118
- justify-items: center;
119
- row-gap: 0.15em;
120
- }
121
-
122
- .sterling-tab.vertical {
123
- grid-template-columns: auto 1em;
124
- grid-template-rows: 1fr;
125
- align-content: center;
126
- align-items: center;
127
- justify-content: flex-end;
128
- justify-items: flex-end;
129
- column-gap: 0.15em;
130
- }
131
-
132
- .sterling-tab.using-keyboard:focus-visible {
133
- outline-color: var(--stsv-common__outline-color);
134
- outline-offset: var(--stsv-common__outline-offset);
135
- outline-style: var(--stsv-common__outline-style);
136
- outline-width: var(--stsv-common__outline-width);
137
- }
138
-
139
- /* ----- disabled -----*/
140
-
141
- .sterling-tab:disabled {
142
- cursor: not-allowed;
143
- outline: none;
144
- }
145
-
146
- .sterling-tab::after {
147
- background: repeating-linear-gradient(
148
- var(--stsv-common--disabled__stripe-angle),
149
- var(--stsv-common--disabled__stripe-color),
150
- var(--stsv-common--disabled__stripe-color) var(--stsv-common--disabled__stripe-width),
151
- var(--stsv-common--disabled__stripe-color--alt) var(--stsv-common--disabled__stripe-width),
152
- var(--stsv-common--disabled__stripe-color--alt)
153
- calc(2 * var(--stsv-common--disabled__stripe-width))
154
- );
155
- bottom: 0;
156
- content: '';
157
- left: 0;
158
- opacity: 0;
159
- position: absolute;
160
- right: 0;
161
- top: 0;
162
- pointer-events: none;
163
- transition: opacity 250ms;
164
- }
165
-
166
- .sterling-tab:disabled::after {
167
- opacity: 1;
168
- }
169
-
170
- /* ----- content -----*/
171
-
172
- .content {
173
- padding: 0 0.2em;
174
- }
175
-
176
- .sterling-tab.vertical .content .text {
177
- padding-top: 0.25em;
178
- }
179
-
180
- /* ----- indicator -----*/
181
-
182
- .indicator {
183
- background-color: transparent;
184
- border-radius: 10000px;
185
- transition: background-color 250ms;
186
- }
187
-
188
- .sterling-tab:not(.vertical) .indicator {
189
- justify-self: stretch;
190
- height: 0.4em;
191
- }
192
-
193
- .sterling-tab.vertical .indicator {
194
- align-self: stretch;
195
- width: 0.4em;
196
- }
197
-
198
- .sterling-tab:not(.selected):not(:active):hover .indicator {
199
- background-color: var(--stsv-input__border-color--hover);
200
- opacity: 0.3;
201
- }
202
-
203
- .sterling-tab:active .indicator {
204
- background-color: var(--stsv-input__border-color--selected);
205
- }
206
-
207
- .sterling-tab.selected .indicator {
208
- background-color: var(--stsv-input__border-color--selected);
209
- }
210
-
211
- /* ----- indicator colorful -----*/
212
-
213
- .sterling-tab.colorful:not(.selected):not(:active):hover .indicator {
214
- background-color: var(--stsv-input--colorful__border-color--hover);
215
- }
216
-
217
- .sterling-tab.colorful:active .indicator {
218
- background-color: var(--stsv-input--colorful__border-color--selected);
219
- }
220
-
221
- .sterling-tab.colorful.selected .indicator {
222
- background-color: var(--stsv-input--colorful__border-color--selected);
223
- }
224
-
225
- /* ----- indicator disabled -----*/
226
-
227
- .sterling-tab:disabled:not(.selected) .indicator,
228
- .sterling-tab:disabled:not(.selected):hover .indicator,
229
- .sterling-tab:disabled:not(.selected):active .indicator {
230
- background-color: transparent;
231
- }
232
-
233
- /* ----- reduced motion -----*/
234
-
235
- @media (prefers-reduced-motion) {
236
- .sterling-tab,
237
- .sterling-tab::after,
238
- .indicator {
239
- transition: none;
240
- }
241
- }
242
- </style>
package/Tab.svelte.d.ts CHANGED
@@ -3,11 +3,12 @@ declare const __propDef: {
3
3
  props: {
4
4
  /**
5
5
  * When true, the tab is disabled.
6
- * The tab is also disabled if the tab list is disabled.
6
+ * The tab is also disabled when its parent tab list is disabled.
7
7
  */ disabled?: boolean | undefined;
8
8
  /** When true, the tab is selected. */ selected?: boolean | undefined;
9
- /** The text of the tab when the default slot is not replaced. */ text?: string | undefined;
10
- /** The value uniquely identifying this item within the tab list. */ value: string;
9
+ /** The text of the tab. Not used when the default slot is filled. */ text?: string | undefined;
10
+ /** The value uniquely identifying this tab within the tab list. */ value: string;
11
+ /** Additional class names to apply. */ variant?: string | undefined;
11
12
  click?: (() => void) | undefined;
12
13
  blur?: (() => void) | undefined;
13
14
  focus?: ((options?: FocusOptions) => void) | undefined;
@@ -51,8 +52,9 @@ declare const __propDef: {
51
52
  default: {
52
53
  disabled: boolean;
53
54
  selected: boolean;
54
- value: string;
55
55
  text: string | undefined;
56
+ value: string;
57
+ variant: string;
56
58
  };
57
59
  };
58
60
  };