@geoffcox/sterling-svelte 0.0.31 → 1.0.1
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/@types/clickOutside.d.ts +11 -7
- package/Button.svelte +11 -183
- package/Button.svelte.d.ts +2 -6
- package/Callout.svelte +107 -146
- package/Callout.svelte.d.ts +1 -1
- package/Checkbox.svelte +15 -177
- package/Checkbox.svelte.d.ts +2 -2
- package/ColorPicker.svelte +204 -223
- package/ColorPicker.svelte.d.ts +1 -2
- package/Dialog.svelte +90 -187
- package/Dialog.svelte.d.ts +2 -1
- package/Dropdown.svelte +52 -220
- package/Dropdown.svelte.d.ts +4 -8
- package/HexColorSliders.svelte +77 -145
- package/HexColorSliders.svelte.d.ts +28 -1
- package/HslColorSliders.svelte +99 -179
- package/HslColorSliders.svelte.d.ts +28 -1
- package/Input.svelte +27 -136
- package/Input.svelte.d.ts +2 -3
- package/Label.constants.d.ts +1 -0
- package/Label.constants.js +1 -0
- package/Label.svelte +96 -169
- package/Label.svelte.d.ts +6 -1
- package/Label.types.d.ts +3 -1
- package/Link.svelte +9 -106
- package/Link.svelte.d.ts +0 -1
- package/List.svelte +142 -230
- package/List.svelte.d.ts +2 -3
- package/List.types.d.ts +6 -1
- package/ListItem.svelte +25 -94
- package/ListItem.svelte.d.ts +2 -0
- package/Menu.svelte +48 -65
- package/Menu.svelte.d.ts +4 -1
- package/MenuBar.svelte +84 -86
- package/MenuBar.svelte.d.ts +4 -1
- package/MenuButton.svelte +66 -73
- package/MenuButton.svelte.d.ts +7 -3
- package/MenuItem.svelte +256 -288
- package/MenuItem.svelte.d.ts +2 -2
- package/MenuItemDisplay.svelte +12 -116
- package/MenuItemDisplay.svelte.d.ts +21 -7
- package/MenuSeparator.svelte +6 -45
- package/MenuSeparator.svelte.d.ts +8 -78
- package/Popover.constants.d.ts +1 -1
- package/Popover.constants.js +1 -1
- package/Popover.svelte +66 -80
- package/Popover.svelte.d.ts +5 -1
- package/Progress.svelte +28 -126
- package/Progress.svelte.d.ts +4 -3
- package/Radio.svelte +49 -192
- package/Radio.svelte.d.ts +2 -2
- package/RgbColorSliders.svelte +48 -137
- package/RgbColorSliders.svelte.d.ts +5 -5
- package/Select.svelte +122 -250
- package/Select.svelte.d.ts +6 -2
- package/Slider.svelte +90 -259
- package/Slider.svelte.d.ts +1 -2
- package/Switch.svelte +24 -259
- package/Switch.svelte.d.ts +3 -1
- package/Tab.svelte +27 -175
- package/Tab.svelte.d.ts +6 -4
- package/TabList.svelte +146 -171
- package/TabList.svelte.d.ts +3 -2
- package/TabList.types.d.ts +6 -1
- package/TextArea.svelte +32 -129
- package/TextArea.svelte.d.ts +1 -1
- package/Tooltip.svelte +46 -47
- package/Tooltip.svelte.d.ts +8 -3
- package/Tree.constants.d.ts +0 -1
- package/Tree.constants.js +0 -1
- package/Tree.svelte +35 -119
- package/Tree.svelte.d.ts +4 -4
- package/Tree.types.d.ts +1 -3
- package/TreeChevron.svelte +18 -98
- package/TreeChevron.svelte.d.ts +1 -0
- package/TreeItem.constants.d.ts +1 -0
- package/TreeItem.constants.js +1 -0
- package/TreeItem.svelte +251 -211
- package/TreeItem.svelte.d.ts +7 -3
- package/TreeItem.types.d.ts +1 -1
- package/TreeItemDisplay.svelte +20 -104
- package/TreeItemDisplay.svelte.d.ts +2 -2
- package/actions/applyLightDarkMode.d.ts +10 -0
- package/actions/applyLightDarkMode.js +36 -0
- package/actions/forwardEvents.js +3 -3
- package/css/Button.base.css +74 -0
- package/css/Button.colorful.css +17 -0
- package/css/Button.css +7 -0
- package/css/Button.secondary.colorful.css +15 -0
- package/css/Button.secondary.css +11 -0
- package/css/Button.shapes.css +14 -0
- package/css/Button.tool.colorful.css +13 -0
- package/css/Button.tool.css +18 -0
- package/css/Callout.base.css +43 -0
- package/css/Callout.colorful.css +5 -0
- package/css/Callout.css +2 -0
- package/css/Checkbox.base.css +145 -0
- package/css/Checkbox.colorful.css +17 -0
- package/css/Checkbox.css +2 -0
- package/css/ColorPicker.base.css +23 -0
- package/css/ColorPicker.css +1 -0
- package/css/Dialog.base.css +116 -0
- package/css/Dialog.css +1 -0
- package/css/Dropdown.base.css +147 -0
- package/css/Dropdown.colorful.css +23 -0
- package/css/Dropdown.css +2 -0
- package/css/HexColorSliders.base.css +106 -0
- package/css/HexColorSliders.css +1 -0
- package/css/HslColorSliders.base.css +124 -0
- package/css/HslColorSliders.css +1 -0
- package/css/Input.base.css +100 -0
- package/css/Input.colorful.css +22 -0
- package/css/Input.composed.css +8 -0
- package/css/Input.css +3 -0
- package/css/Label.base.css +119 -0
- package/css/Label.boxed.colorful.css +21 -0
- package/css/Label.boxed.css +31 -0
- package/css/Label.colorful.css +3 -0
- package/css/Label.css +4 -0
- package/css/Link.base.css +52 -0
- package/css/Link.colorful.css +15 -0
- package/css/Link.css +6 -0
- package/css/Link.ghost.colorful.css +7 -0
- package/css/Link.ghost.css +11 -0
- package/css/Link.undecorated.colorful.css +6 -0
- package/css/Link.undecorated.css +6 -0
- package/css/List.base.css +98 -0
- package/css/List.css +1 -0
- package/css/ListItem.base.css +59 -0
- package/css/ListItem.css +1 -0
- package/css/Menu.base.css +21 -0
- package/css/Menu.css +1 -0
- package/css/MenuBar.base.css +9 -0
- package/css/MenuBar.css +1 -0
- package/css/MenuButton.base.css +13 -0
- package/css/MenuButton.css +1 -0
- package/css/MenuItem.base.css +48 -0
- package/css/MenuItem.css +1 -0
- package/css/MenuItemDisplay.base.css +104 -0
- package/css/MenuItemDisplay.css +1 -0
- package/css/MenuSeparator.base.css +5 -0
- package/css/MenuSeparator.css +1 -0
- package/css/Popover copy.css +21 -0
- package/css/Popover.css +21 -0
- package/css/Progress.base.css +99 -0
- package/css/Progress.css +1 -0
- package/css/Radio.base.css +135 -0
- package/css/Radio.colorful.css +18 -0
- package/css/Radio.css +2 -0
- package/css/RgbColorSliders.base.css +94 -0
- package/css/RgbColorSliders.css +1 -0
- package/css/Select.base.css +127 -0
- package/css/Select.colorful.css +24 -0
- package/css/Select.composed.css +12 -0
- package/css/Select.css +3 -0
- package/css/Slider.base.css +182 -0
- package/css/Slider.colorful.css +11 -0
- package/css/Slider.composed.css +8 -0
- package/css/Slider.css +3 -0
- package/css/Switch.base.css +193 -0
- package/css/Switch.colorful.css +39 -0
- package/css/Switch.css +2 -0
- package/css/Tab.base.css +135 -0
- package/css/Tab.colorful.css +13 -0
- package/css/Tab.css +2 -0
- package/css/TabList.base.css +34 -0
- package/css/TabList.css +1 -0
- package/css/TextArea.base.css +85 -0
- package/css/TextArea.colorful.css +17 -0
- package/css/TextArea.composed.css +8 -0
- package/css/TextArea.css +3 -0
- package/css/Tooltip.base.css +6 -0
- package/css/Tooltip.css +1 -0
- package/css/Tree.base.css +74 -0
- package/css/Tree.composed.css +8 -0
- package/css/Tree.css +2 -0
- package/css/TreeChevron.base.css +86 -0
- package/css/TreeChevron.css +1 -0
- package/css/TreeItem.base.css +3 -0
- package/css/TreeItem.css +1 -0
- package/css/TreeItemDisplay.base.css +74 -0
- package/css/TreeItemDisplay.colorful.css +9 -0
- package/css/TreeItemDisplay.css +1 -0
- package/css/dark-mode.css +134 -0
- package/css/light-mode.css +134 -0
- package/css/sterling.css +37 -0
- package/index.d.ts +9 -13
- package/index.js +8 -12
- package/mediaQueries/prefersColorSchemeDark.d.ts +2 -0
- package/mediaQueries/prefersColorSchemeDark.js +10 -0
- package/{stores → mediaQueries}/prefersReducedMotion.d.ts +1 -0
- package/{stores → mediaQueries}/usingKeyboard.d.ts +1 -0
- package/package.json +121 -13
- package/Link.constants.d.ts +0 -1
- package/Link.constants.js +0 -1
- package/Link.types.d.ts +0 -4
- package/Link.types.js +0 -1
- package/theme/applyDarkTheme.d.ts +0 -7
- package/theme/applyDarkTheme.js +0 -11
- package/theme/applyLightTheme.d.ts +0 -7
- package/theme/applyLightTheme.js +0 -11
- package/theme/applyTheme.d.ts +0 -7
- package/theme/applyTheme.js +0 -20
- package/theme/colors.d.ts +0 -54
- package/theme/colors.js +0 -82
- package/theme/darkTheme.d.ts +0 -2
- package/theme/darkTheme.js +0 -142
- package/theme/lightTheme.d.ts +0 -2
- package/theme/lightTheme.js +0 -119
- package/theme/toggleDarkTheme.d.ts +0 -18
- package/theme/toggleDarkTheme.js +0 -53
- package/theme/types.d.ts +0 -21
- package/theme/types.js +0 -1
- /package/{stores → mediaQueries}/prefersReducedMotion.js +0 -0
- /package/{stores → mediaQueries}/usingKeyboard.js +0 -0
package/Switch.svelte
CHANGED
|
@@ -1,36 +1,37 @@
|
|
|
1
|
-
<script>import { idGenerator } from
|
|
1
|
+
<script>import { idGenerator } from './idGenerator';
|
|
2
|
+
// ----- Props ----- //
|
|
2
3
|
export let checked = false;
|
|
3
4
|
export let disabled = false;
|
|
4
|
-
|
|
5
|
-
export let offText =
|
|
6
|
-
|
|
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
|
-
|
|
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
|
-
|
|
16
|
-
$:
|
|
17
|
-
|
|
18
|
-
$:
|
|
19
|
-
|
|
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
|
-
|
|
28
|
+
inputRef?.blur();
|
|
28
29
|
};
|
|
29
30
|
export const click = () => {
|
|
30
|
-
|
|
31
|
+
inputRef?.click();
|
|
31
32
|
};
|
|
32
33
|
export const focus = (options) => {
|
|
33
|
-
|
|
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=
|
|
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>
|
package/Switch.svelte.d.ts
CHANGED
|
@@ -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
|
|
2
|
-
import { TAB_LIST_CONTEXT_KEY } from
|
|
3
|
-
import { usingKeyboard } from
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
23
|
+
selected = $selectedValue === value;
|
|
19
24
|
}
|
|
20
25
|
$: {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
26
|
+
if (selected) {
|
|
27
|
+
selectedValue.set(value);
|
|
28
|
+
}
|
|
24
29
|
}
|
|
30
|
+
// ----- Methods ----- //
|
|
25
31
|
export const click = () => {
|
|
26
|
-
|
|
32
|
+
tabRef?.click();
|
|
27
33
|
};
|
|
28
34
|
export const blur = () => {
|
|
29
|
-
|
|
35
|
+
tabRef?.blur();
|
|
30
36
|
};
|
|
31
37
|
export const focus = (options) => {
|
|
32
|
-
|
|
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=
|
|
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} {
|
|
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
|
|
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
|
|
10
|
-
/** The value uniquely identifying this
|
|
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
|
};
|