@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/Input.svelte
CHANGED
|
@@ -1,47 +1,53 @@
|
|
|
1
|
-
<script>import { idGenerator } from
|
|
1
|
+
<script>import { idGenerator } from './idGenerator';
|
|
2
|
+
import { usingKeyboard } from './mediaQueries/usingKeyboard';
|
|
3
|
+
// ----- Props ----- //
|
|
2
4
|
export let disabled = false;
|
|
3
|
-
export let id =
|
|
4
|
-
export let value =
|
|
5
|
-
|
|
6
|
-
export let
|
|
5
|
+
export let id = undefined;
|
|
6
|
+
export let value = '';
|
|
7
|
+
/** Additional class names to apply. */
|
|
8
|
+
export let variant = '';
|
|
9
|
+
// ----- State ----- //
|
|
7
10
|
let inputRef;
|
|
8
11
|
$: {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
if ($$slots.default && id === undefined) {
|
|
13
|
+
id = idGenerator.nextId('Input');
|
|
14
|
+
}
|
|
12
15
|
}
|
|
16
|
+
// ----- Methods ----- //
|
|
13
17
|
export const blur = () => {
|
|
14
|
-
|
|
18
|
+
inputRef?.blur();
|
|
15
19
|
};
|
|
16
20
|
export const click = () => {
|
|
17
|
-
|
|
21
|
+
inputRef?.click();
|
|
18
22
|
};
|
|
19
23
|
export const focus = (options) => {
|
|
20
|
-
|
|
24
|
+
inputRef?.focus();
|
|
21
25
|
};
|
|
22
26
|
export const select = () => {
|
|
23
|
-
|
|
27
|
+
inputRef?.select();
|
|
24
28
|
};
|
|
25
29
|
export const setSelectionRange = (start, end, direction) => {
|
|
26
|
-
|
|
30
|
+
inputRef?.setSelectionRange(start, end, direction);
|
|
27
31
|
};
|
|
28
32
|
export const setRangeText = (replacement, start, end, selectionMode) => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
if (start && end) {
|
|
34
|
+
inputRef?.setRangeText(replacement, start, end, selectionMode);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
inputRef?.setRangeText(replacement);
|
|
38
|
+
}
|
|
34
39
|
};
|
|
35
40
|
</script>
|
|
36
41
|
|
|
37
42
|
{#if $$slots.default}
|
|
38
|
-
<label for={id}>
|
|
39
|
-
<slot {
|
|
43
|
+
<label class={`sterling-input-label ${variant}`} for={id}>
|
|
44
|
+
<slot {disabled} {value} {variant} />
|
|
40
45
|
</label>
|
|
41
46
|
{/if}
|
|
42
|
-
<div class=
|
|
47
|
+
<div class={`sterling-input ${variant}`} class:disabled>
|
|
43
48
|
<input
|
|
44
49
|
bind:this={inputRef}
|
|
50
|
+
class:using-keyboard={$usingKeyboard}
|
|
45
51
|
{disabled}
|
|
46
52
|
{id}
|
|
47
53
|
bind:value
|
|
@@ -81,118 +87,3 @@ export const setRangeText = (replacement, start, end, selectionMode) => {
|
|
|
81
87
|
{...$$restProps}
|
|
82
88
|
/>
|
|
83
89
|
</div>
|
|
84
|
-
|
|
85
|
-
<style>
|
|
86
|
-
.sterling-input {
|
|
87
|
-
box-sizing: border-box;
|
|
88
|
-
display: inline-block;
|
|
89
|
-
margin: 0;
|
|
90
|
-
padding: 0;
|
|
91
|
-
position: relative;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
input {
|
|
95
|
-
background-color: var(--stsv-input__background-color);
|
|
96
|
-
border-color: var(--stsv-input__border-color);
|
|
97
|
-
border-radius: var(--stsv-input__border-radius);
|
|
98
|
-
border-style: var(--stsv-input__border-style);
|
|
99
|
-
border-width: var(--stsv-input__border-width);
|
|
100
|
-
box-sizing: border-box;
|
|
101
|
-
color: var(--stsv-input__color);
|
|
102
|
-
display: block;
|
|
103
|
-
font: inherit;
|
|
104
|
-
margin: 0;
|
|
105
|
-
outline: none;
|
|
106
|
-
padding: 0.5em;
|
|
107
|
-
transition: background-color 250ms, color 250ms, border-color 250ms;
|
|
108
|
-
width: 100%;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
.sterling-input:hover input:not(:disabled) {
|
|
112
|
-
background-color: var(--stsv-input__background-color--hover);
|
|
113
|
-
border-color: var(--stsv-input__border-color--hover);
|
|
114
|
-
color: var(--stsv-input__color--hover);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
input:focus {
|
|
118
|
-
background-color: var(--stsv-input__background-color--focus);
|
|
119
|
-
border-color: var(--stsv-input__border-color--focus);
|
|
120
|
-
color: var(--stsv-input__color--focus);
|
|
121
|
-
outline-color: var(--stsv-common__outline-color);
|
|
122
|
-
outline-offset: var(--stsv-common__outline-offset);
|
|
123
|
-
outline-style: var(--stsv-common__outline-style);
|
|
124
|
-
outline-width: var(--stsv-common__outline-width);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
.sterling-input.colorful input {
|
|
128
|
-
background-color: var(--stsv-input--colorful__background-color);
|
|
129
|
-
border-color: var(--stsv-input--colorful__border-color);
|
|
130
|
-
color: var(--stsv-input--colorful__color);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
.sterling-input.colorful:hover input:not(:disabled) {
|
|
134
|
-
background-color: var(--stsv-input--colorful__background-color--hover);
|
|
135
|
-
border-color: var(--stsv-input--colorful__border-color--hover);
|
|
136
|
-
color: var(--stsv-input--colorful__color--hover);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
.sterling-input.colorful input:focus {
|
|
140
|
-
background-color: var(--stsv-input--colorful__background-color--focus);
|
|
141
|
-
border-color: var(--stsv-input--colorful__border-color--focus);
|
|
142
|
-
color: var(--stsv-input--colorful__color--focus);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
.sterling-input.composed input,
|
|
146
|
-
.sterling-input.composed:hover input,
|
|
147
|
-
.sterling-input.composed:focus input {
|
|
148
|
-
background: transparent;
|
|
149
|
-
border: none;
|
|
150
|
-
outline: none;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
input::placeholder {
|
|
154
|
-
color: var(--stsv-common__color--subtle);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
.sterling-input.disabled * {
|
|
158
|
-
cursor: not-allowed;
|
|
159
|
-
outline: none;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
.sterling-input::after {
|
|
163
|
-
background: repeating-linear-gradient(
|
|
164
|
-
var(--stsv-common--disabled__stripe-angle),
|
|
165
|
-
var(--stsv-common--disabled__stripe-color),
|
|
166
|
-
var(--stsv-common--disabled__stripe-color) var(--stsv-common--disabled__stripe-width),
|
|
167
|
-
var(--stsv-common--disabled__stripe-color--alt) var(--stsv-common--disabled__stripe-width),
|
|
168
|
-
var(--stsv-common--disabled__stripe-color--alt)
|
|
169
|
-
calc(2 * var(--stsv-common--disabled__stripe-width))
|
|
170
|
-
);
|
|
171
|
-
bottom: 0;
|
|
172
|
-
content: '';
|
|
173
|
-
left: 0;
|
|
174
|
-
opacity: 0;
|
|
175
|
-
position: absolute;
|
|
176
|
-
right: 0;
|
|
177
|
-
top: 0;
|
|
178
|
-
pointer-events: none;
|
|
179
|
-
transition: opacity 250ms;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
label {
|
|
183
|
-
color: var(--stsv-common__color);
|
|
184
|
-
transition: color 250ms;
|
|
185
|
-
font: inherit;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
.sterling-input.disabled::after {
|
|
189
|
-
opacity: 1;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
@media (prefers-reduced-motion) {
|
|
193
|
-
.sterling-input::after,
|
|
194
|
-
input {
|
|
195
|
-
transition: none;
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
</style>
|
package/Input.svelte.d.ts
CHANGED
|
@@ -5,8 +5,7 @@ declare const __propDef: {
|
|
|
5
5
|
disabled?: boolean | undefined;
|
|
6
6
|
id?: string | undefined;
|
|
7
7
|
value?: string | undefined;
|
|
8
|
-
|
|
9
|
-
composed?: boolean | undefined;
|
|
8
|
+
variant?: string | undefined;
|
|
10
9
|
blur?: (() => void) | undefined;
|
|
11
10
|
click?: (() => void) | undefined;
|
|
12
11
|
focus?: ((options?: FocusOptions) => void) | undefined;
|
|
@@ -53,9 +52,9 @@ declare const __propDef: {
|
|
|
53
52
|
};
|
|
54
53
|
slots: {
|
|
55
54
|
default: {
|
|
56
|
-
composed: boolean;
|
|
57
55
|
disabled: boolean;
|
|
58
56
|
value: string;
|
|
57
|
+
variant: string;
|
|
59
58
|
};
|
|
60
59
|
};
|
|
61
60
|
};
|
package/Label.constants.d.ts
CHANGED
package/Label.constants.js
CHANGED
package/Label.svelte
CHANGED
|
@@ -1,88 +1,122 @@
|
|
|
1
|
-
<script>import Tooltip from
|
|
2
|
-
import { usingKeyboard } from
|
|
3
|
-
|
|
1
|
+
<script>import Tooltip from './Tooltip.svelte';
|
|
2
|
+
import { usingKeyboard } from './mediaQueries/usingKeyboard';
|
|
3
|
+
// ----- Props ----- //
|
|
4
|
+
let htmlFor = undefined;
|
|
4
5
|
export { htmlFor as for };
|
|
6
|
+
/**
|
|
7
|
+
* If true, clicking the label invokes a click on the content.
|
|
8
|
+
* Needed only when the label is not associated with the content through containment or the `for`/`id` relationship.
|
|
9
|
+
*/
|
|
5
10
|
export let forwardClick = false;
|
|
6
|
-
|
|
7
|
-
export let
|
|
11
|
+
/** The text to display in the label. Not used if the text slot is filled. */
|
|
12
|
+
export let text = undefined;
|
|
13
|
+
/** The status message to display. */
|
|
14
|
+
export let message = undefined;
|
|
15
|
+
/** When true, indicates a value is required. */
|
|
8
16
|
export let required = false;
|
|
9
|
-
|
|
10
|
-
export let
|
|
17
|
+
/** The reason the value is required. */
|
|
18
|
+
export let requiredReason = 'required';
|
|
19
|
+
/** The status of the label. */
|
|
20
|
+
export let status = 'none';
|
|
21
|
+
/** Additional class names to apply. */
|
|
22
|
+
export let variant = '';
|
|
23
|
+
/** When true, the label appears above the content. */
|
|
24
|
+
export let vertical = true;
|
|
25
|
+
// ----- State ----- //
|
|
11
26
|
let labelRef;
|
|
12
27
|
let targetDisabled = false;
|
|
13
28
|
let targetRef = null;
|
|
14
29
|
const findTarget = () => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
30
|
+
let candidate = null;
|
|
31
|
+
if (htmlFor) {
|
|
32
|
+
candidate = labelRef?.querySelector(`[id="${htmlFor}"]`);
|
|
33
|
+
}
|
|
34
|
+
if (!candidate) {
|
|
35
|
+
candidate = labelRef?.querySelector('a[href], ' +
|
|
36
|
+
'audio[controls], ' +
|
|
37
|
+
'button, ' +
|
|
38
|
+
'details, ' +
|
|
39
|
+
'div[contenteditable], ' +
|
|
40
|
+
'form, ' +
|
|
41
|
+
'input, ' +
|
|
42
|
+
'select, ' +
|
|
43
|
+
'textarea, ' +
|
|
44
|
+
'video[controls], ' +
|
|
45
|
+
'[tabindex]:not([tabindex="-1"])');
|
|
46
|
+
}
|
|
47
|
+
targetRef = candidate;
|
|
25
48
|
};
|
|
26
49
|
const isElementDisabled = (element) => {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
50
|
+
if (element) {
|
|
51
|
+
return (element.getAttribute('aria-disabled') === 'true' ||
|
|
52
|
+
element?.matches(':disabled') ||
|
|
53
|
+
element?.disabled === true ||
|
|
54
|
+
element?.classList.contains('disabled'));
|
|
55
|
+
}
|
|
56
|
+
return false;
|
|
31
57
|
};
|
|
32
|
-
$:
|
|
33
|
-
$$slots.default, labelRef, htmlFor, findTarget();
|
|
58
|
+
$: $$slots.default, labelRef, htmlFor, findTarget();
|
|
34
59
|
$: {
|
|
35
|
-
|
|
60
|
+
targetDisabled = isElementDisabled(targetRef);
|
|
36
61
|
}
|
|
37
62
|
const mutationCallback = (mutations) => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
63
|
+
let disabled = undefined;
|
|
64
|
+
for (let i = 0; i < mutations.length; i++) {
|
|
65
|
+
const mutation = mutations[i];
|
|
66
|
+
if (mutation.type === 'attributes') {
|
|
67
|
+
if (mutation.attributeName === 'aria-disabled' ||
|
|
68
|
+
mutation.attributeName === 'disabled' ||
|
|
69
|
+
mutation.attributeName === 'class') {
|
|
70
|
+
if (isElementDisabled(targetRef)) {
|
|
71
|
+
// a mutation caused the target to be disabled
|
|
72
|
+
disabled = true;
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
// a mutation caused the target to be enabled
|
|
76
|
+
disabled = false;
|
|
77
|
+
}
|
|
46
78
|
}
|
|
47
|
-
disabled = false;
|
|
48
|
-
}
|
|
49
79
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
80
|
+
// if we found a mutation that changed disabled, then set targetDisabled
|
|
81
|
+
if (disabled !== undefined) {
|
|
82
|
+
targetDisabled = disabled;
|
|
83
|
+
}
|
|
54
84
|
};
|
|
55
85
|
let mutationObserver = new MutationObserver(mutationCallback);
|
|
56
86
|
$: {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
87
|
+
mutationObserver.disconnect();
|
|
88
|
+
if (targetRef) {
|
|
89
|
+
mutationObserver.observe(targetRef, {
|
|
90
|
+
attributes: true
|
|
91
|
+
});
|
|
92
|
+
}
|
|
63
93
|
}
|
|
94
|
+
// ----- Methods ----- //
|
|
64
95
|
export const click = () => {
|
|
65
|
-
|
|
96
|
+
labelRef?.click();
|
|
66
97
|
};
|
|
67
98
|
export const blur = () => {
|
|
68
|
-
|
|
99
|
+
labelRef?.blur();
|
|
69
100
|
};
|
|
70
101
|
export const focus = (options) => {
|
|
71
|
-
|
|
102
|
+
labelRef?.focus(options);
|
|
72
103
|
};
|
|
104
|
+
// ----- Event Handlers ----- //
|
|
73
105
|
const onClick = () => {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
106
|
+
if (forwardClick) {
|
|
107
|
+
targetRef?.click();
|
|
108
|
+
}
|
|
77
109
|
};
|
|
78
110
|
</script>
|
|
79
111
|
|
|
112
|
+
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
|
|
80
113
|
<label
|
|
81
114
|
bind:this={labelRef}
|
|
82
115
|
aria-disabled={targetDisabled}
|
|
83
|
-
class=
|
|
116
|
+
class={`sterling-label ${variant}`}
|
|
84
117
|
class:disabled={targetDisabled}
|
|
85
118
|
class:using-keyboard={$usingKeyboard}
|
|
119
|
+
class:vertical
|
|
86
120
|
for={htmlFor}
|
|
87
121
|
on:blur
|
|
88
122
|
on:click
|
|
@@ -115,7 +149,15 @@ const onClick = () => {
|
|
|
115
149
|
{...$$restProps}
|
|
116
150
|
>
|
|
117
151
|
{#if text || $$slots.text}
|
|
118
|
-
<slot
|
|
152
|
+
<slot
|
|
153
|
+
name="text"
|
|
154
|
+
disabled={targetDisabled}
|
|
155
|
+
for={htmlFor}
|
|
156
|
+
{forwardClick}
|
|
157
|
+
{required}
|
|
158
|
+
{text}
|
|
159
|
+
{variant}
|
|
160
|
+
>
|
|
119
161
|
<div class="text">
|
|
120
162
|
{text}
|
|
121
163
|
</div>
|
|
@@ -127,7 +169,7 @@ const onClick = () => {
|
|
|
127
169
|
</div>
|
|
128
170
|
{/if}
|
|
129
171
|
{#if message}
|
|
130
|
-
<slot name="message" disabled={targetDisabled} {message} {required} {status}>
|
|
172
|
+
<slot name="message" disabled={targetDisabled} {message} {required} {status} {variant}>
|
|
131
173
|
<div
|
|
132
174
|
class="message"
|
|
133
175
|
class:info={status === 'info'}
|
|
@@ -140,7 +182,7 @@ const onClick = () => {
|
|
|
140
182
|
</slot>
|
|
141
183
|
{/if}
|
|
142
184
|
{#if required}
|
|
143
|
-
<slot name="required" {requiredReason}>
|
|
185
|
+
<slot name="required" {requiredReason} {variant}>
|
|
144
186
|
<Tooltip showOn="hover">
|
|
145
187
|
<span class="required-reason" slot="tip">{requiredReason}</span>
|
|
146
188
|
<div class="required">*</div>
|
|
@@ -148,118 +190,3 @@ const onClick = () => {
|
|
|
148
190
|
</slot>
|
|
149
191
|
{/if}
|
|
150
192
|
</label>
|
|
151
|
-
|
|
152
|
-
<style>
|
|
153
|
-
.sterling-label {
|
|
154
|
-
background-color: var(--stsv-input__background-color);
|
|
155
|
-
border-color: var(--stsv-input__border-color);
|
|
156
|
-
border-radius: var(--stsv-input__border-radius);
|
|
157
|
-
border-style: var(--stsv-input__border-style);
|
|
158
|
-
border-width: var(--stsv-input__border-width);
|
|
159
|
-
box-sizing: border-box;
|
|
160
|
-
color: var(--stsv-input__color);
|
|
161
|
-
display: flex;
|
|
162
|
-
flex-direction: column;
|
|
163
|
-
font: inherit;
|
|
164
|
-
margin: 0;
|
|
165
|
-
overflow: visible;
|
|
166
|
-
padding: 0;
|
|
167
|
-
position: relative;
|
|
168
|
-
transition: background-color 250ms, color 250ms, border-color 250ms;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
.sterling-label:not(.disabled):hover {
|
|
172
|
-
background-color: var(--stsv-input__background-color--hover);
|
|
173
|
-
border-color: var(--stsv-input__border-color--hover);
|
|
174
|
-
color: var(--stsv-input__color--hover);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
.sterling-label.using-keyboard:focus-within {
|
|
178
|
-
border-color: var(--stsv-input__border-color--focus);
|
|
179
|
-
color: var(--stsv-input__color--focus);
|
|
180
|
-
outline-color: var(--stsv-common__outline-color);
|
|
181
|
-
outline-offset: var(--stsv-common__outline-offset);
|
|
182
|
-
outline-style: var(--stsv-common__outline-style);
|
|
183
|
-
outline-width: var(--stsv-common__outline-width);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
.sterling-label.disabled {
|
|
187
|
-
cursor: not-allowed;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
.sterling-label.disabled * {
|
|
191
|
-
cursor: not-allowed;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
.text {
|
|
195
|
-
color: var(--stsv-common__color--secondary);
|
|
196
|
-
font-size: 0.8em;
|
|
197
|
-
margin: 0.5em 0.7em 0.2em 0.2em;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
.text:empty {
|
|
201
|
-
margin: 0;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
.content {
|
|
205
|
-
display: grid;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
.message {
|
|
209
|
-
box-sizing: border-box;
|
|
210
|
-
font-size: 0.8em;
|
|
211
|
-
background-color: var(--stsv-common__background-color--secondary);
|
|
212
|
-
color: var(--stsv-common__color--secondary);
|
|
213
|
-
padding: 0.5em;
|
|
214
|
-
width: 100%;
|
|
215
|
-
transition: background-color 250ms, color 250ms, border-color 250ms;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
.message.info {
|
|
219
|
-
background-color: var(--stsv-status--info__background-color);
|
|
220
|
-
border-color: var(--stsv-status--info__border-color);
|
|
221
|
-
color: var(--stsv-status--info__color);
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
.message.success {
|
|
225
|
-
background-color: var(--stsv-status--success__background-color);
|
|
226
|
-
border-color: var(--stsv-status--success__border-color);
|
|
227
|
-
color: var(--stsv-status--success__color);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
.message.warning {
|
|
231
|
-
background-color: var(--stsv-status--warning__background-color);
|
|
232
|
-
border-color: var(--stsv-status--warning__border-color);
|
|
233
|
-
color: var(--stsv-status--warning__color);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
.message.error {
|
|
237
|
-
background-color: var(--stsv-status--danger__background-color);
|
|
238
|
-
border-color: var(--stsv_--danger-color);
|
|
239
|
-
color: var(--stsv-status--danger__color);
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
.required {
|
|
243
|
-
text-align: center;
|
|
244
|
-
font-weight: bold;
|
|
245
|
-
box-sizing: border-box;
|
|
246
|
-
width: 1em;
|
|
247
|
-
height: 1em;
|
|
248
|
-
position: absolute;
|
|
249
|
-
top: 0;
|
|
250
|
-
right: 0;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
.required-reason {
|
|
254
|
-
display: block;
|
|
255
|
-
padding: 4px;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
@media (prefers-reduced-motion) {
|
|
259
|
-
.sterling-label,
|
|
260
|
-
.sterling-label::after,
|
|
261
|
-
.message {
|
|
262
|
-
transition: none;
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
</style>
|
package/Label.svelte.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ declare const __propDef: {
|
|
|
9
9
|
required?: boolean | undefined;
|
|
10
10
|
requiredReason?: string | undefined;
|
|
11
11
|
status?: string | undefined;
|
|
12
|
+
variant?: string | undefined;
|
|
13
|
+
vertical?: boolean | undefined;
|
|
12
14
|
click?: (() => void) | undefined;
|
|
13
15
|
blur?: (() => void) | undefined;
|
|
14
16
|
focus?: ((options?: FocusOptions) => void) | undefined;
|
|
@@ -49,8 +51,9 @@ declare const __propDef: {
|
|
|
49
51
|
disabled: boolean;
|
|
50
52
|
for: string | undefined;
|
|
51
53
|
forwardClick: boolean;
|
|
52
|
-
text: string | undefined;
|
|
53
54
|
required: boolean;
|
|
55
|
+
text: string | undefined;
|
|
56
|
+
variant: string;
|
|
54
57
|
};
|
|
55
58
|
default: {};
|
|
56
59
|
message: {
|
|
@@ -58,9 +61,11 @@ declare const __propDef: {
|
|
|
58
61
|
message: string | undefined;
|
|
59
62
|
required: boolean;
|
|
60
63
|
status: string;
|
|
64
|
+
variant: string;
|
|
61
65
|
};
|
|
62
66
|
required: {
|
|
63
67
|
requiredReason: string;
|
|
68
|
+
variant: string;
|
|
64
69
|
};
|
|
65
70
|
};
|
|
66
71
|
};
|
package/Label.types.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import type { LABEL_STATUSES } from './Label.constants';
|
|
1
|
+
import type { LABEL_STATUSES, LABEL_VARIANTS } from './Label.constants';
|
|
2
2
|
type LabelStatusTuple = typeof LABEL_STATUSES;
|
|
3
3
|
export type LabelStatus = LabelStatusTuple[number];
|
|
4
|
+
type LabelVariantTuple = typeof LABEL_VARIANTS;
|
|
5
|
+
export type LabelVariant = LabelVariantTuple[number];
|
|
4
6
|
export {};
|