@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.
- 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 +91 -187
- package/Dialog.svelte.d.ts +3 -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/Link.svelte
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
<script>export let href;
|
|
2
2
|
export let disabled = false;
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
// ----- Props ----- //
|
|
4
|
+
/** Additional class names to apply. */
|
|
5
|
+
export let variant = '';
|
|
6
|
+
// ----- State ----- //
|
|
5
7
|
let linkRef;
|
|
8
|
+
// ----- Methods ----- //
|
|
6
9
|
export const blur = () => {
|
|
7
|
-
|
|
10
|
+
linkRef?.blur();
|
|
8
11
|
};
|
|
9
12
|
export const click = () => {
|
|
10
|
-
|
|
13
|
+
linkRef?.click();
|
|
11
14
|
};
|
|
12
15
|
export const focus = (options) => {
|
|
13
|
-
|
|
16
|
+
linkRef?.focus();
|
|
14
17
|
};
|
|
15
18
|
</script>
|
|
16
19
|
|
|
17
20
|
<a
|
|
18
21
|
bind:this={linkRef}
|
|
19
|
-
class=
|
|
20
|
-
class:colorful
|
|
22
|
+
class={`sterling-link ${variant}`}
|
|
21
23
|
class:disabled
|
|
22
|
-
class:ghost={variant === 'ghost'}
|
|
23
|
-
class:undecorated={variant === 'undecorated'}
|
|
24
24
|
{href}
|
|
25
25
|
on:blur
|
|
26
26
|
on:click
|
|
@@ -55,100 +55,3 @@ export const focus = (options) => {
|
|
|
55
55
|
on:wheel|passive
|
|
56
56
|
{...$$restProps}><slot {disabled} {href} {variant} /></a
|
|
57
57
|
>
|
|
58
|
-
|
|
59
|
-
<style>
|
|
60
|
-
a {
|
|
61
|
-
background-color: transparent;
|
|
62
|
-
border-top: none;
|
|
63
|
-
border-left: none;
|
|
64
|
-
border-right: none;
|
|
65
|
-
border-radius: 0;
|
|
66
|
-
border-bottom-style: var(--stsv-common__border-style);
|
|
67
|
-
border-bottom-width: calc(var(--stsv-common__border-width));
|
|
68
|
-
border-bottom-color: var(--stsv-common__border-color);
|
|
69
|
-
color: var(--stsv-common__color);
|
|
70
|
-
cursor: pointer;
|
|
71
|
-
font: inherit;
|
|
72
|
-
text-decoration: none;
|
|
73
|
-
text-overflow: ellipsis;
|
|
74
|
-
transition: background-color 250ms, color 250ms, border-color 250ms;
|
|
75
|
-
white-space: nowrap;
|
|
76
|
-
user-select: none;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
a:visited {
|
|
80
|
-
border-bottom-color: var(--stsv-input__border-color);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
a:hover {
|
|
84
|
-
border-bottom-color: var(--stsv-input__border-color--hover);
|
|
85
|
-
color: var(--stsv-input__color--hover);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
a:active {
|
|
89
|
-
border-bottom-color: var(--stsv-input__border-color--selected);
|
|
90
|
-
color: var(--stsv-input__color--active);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/* ----- colorful ----- */
|
|
94
|
-
|
|
95
|
-
a.colorful,
|
|
96
|
-
a.colorful:visited {
|
|
97
|
-
border-bottom-color: var(--stsv-input--colorful__border-color);
|
|
98
|
-
color: var(--stsv-input--colorful__color);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
a.colorful:hover {
|
|
102
|
-
border-bottom-color: var(--stsv-input--colorful__border-color--hover);
|
|
103
|
-
color: var(--stsv-input--colorful__color--hover);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
a.colorful:active {
|
|
107
|
-
border-bottom-color: var(--stsv-input--colorful__border-color--selected);
|
|
108
|
-
color: var(--stsv-input--colorful__color--active);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/* ----- ghost ----- */
|
|
112
|
-
|
|
113
|
-
a.ghost {
|
|
114
|
-
border-bottom-color: transparent;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
a.ghost:hover {
|
|
118
|
-
border-bottom-color: var(--stsv-input__border-color--hover);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
a.ghost:active {
|
|
122
|
-
border-bottom-color: var(--stsv-input__border-color--selected);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/* ----- ghost colorful ----- */
|
|
126
|
-
|
|
127
|
-
a.ghost.colorful:hover {
|
|
128
|
-
border-bottom-color: var(--stsv-input--colorful__border-color--hover);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
a.ghost.colorful:active {
|
|
132
|
-
border-bottom-color: var(--stsv-input--colorful__border-color--selected);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/* ----- disabled ----- */
|
|
136
|
-
|
|
137
|
-
a.disabled,
|
|
138
|
-
a.disabled:visited,
|
|
139
|
-
a.disabled:hover,
|
|
140
|
-
a.disabled:active {
|
|
141
|
-
border-bottom-color: var(--stsv-common__border-color--disabled);
|
|
142
|
-
color: var(--stsv-common__color--disabled);
|
|
143
|
-
cursor: not-allowed;
|
|
144
|
-
pointer-events: none;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/* ----- undecorated ----- */
|
|
148
|
-
a.undecorated,
|
|
149
|
-
a.undecorated:hover,
|
|
150
|
-
a.undecorated:active,
|
|
151
|
-
a.undecorated:visited {
|
|
152
|
-
border-bottom-color: transparent;
|
|
153
|
-
}
|
|
154
|
-
</style>
|
package/Link.svelte.d.ts
CHANGED
package/List.svelte
CHANGED
|
@@ -1,180 +1,192 @@
|
|
|
1
|
-
<script>import { createEventDispatcher, setContext } from
|
|
2
|
-
import { writable } from
|
|
3
|
-
import { LIST_CONTEXT_KEY } from
|
|
4
|
-
import { usingKeyboard } from
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
<script>import { createEventDispatcher, setContext } from 'svelte';
|
|
2
|
+
import { writable } from 'svelte/store';
|
|
3
|
+
import { LIST_CONTEXT_KEY } from './List.constants';
|
|
4
|
+
import { usingKeyboard } from './mediaQueries/usingKeyboard';
|
|
5
|
+
// ----- Props ----- //
|
|
6
|
+
/** If the list and all its items are disabled. */
|
|
7
7
|
export let disabled = false;
|
|
8
|
+
/** When true, items are arranged horizontally. */
|
|
8
9
|
export let horizontal = false;
|
|
9
|
-
|
|
10
|
+
/** The value of the currently selected item. */
|
|
11
|
+
export let selectedValue = undefined;
|
|
12
|
+
/** Additional class names to apply. */
|
|
13
|
+
export let variant = '';
|
|
14
|
+
// ----- State ----- //
|
|
10
15
|
let listRef;
|
|
11
16
|
let lastSelectedItemRef;
|
|
12
|
-
const colorfulStore = writable(colorful);
|
|
13
17
|
const disabledStore = writable(disabled);
|
|
14
18
|
const horizontalStore = writable(horizontal);
|
|
15
19
|
const selectedValueStore = writable(selectedValue);
|
|
16
20
|
$: {
|
|
17
|
-
|
|
21
|
+
disabledStore.set(disabled);
|
|
18
22
|
}
|
|
19
23
|
$: {
|
|
20
|
-
|
|
24
|
+
horizontalStore.set(horizontal);
|
|
21
25
|
}
|
|
22
26
|
$: {
|
|
23
|
-
|
|
27
|
+
selectedValueStore.set(selectedValue);
|
|
24
28
|
}
|
|
25
29
|
$: {
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
$: {
|
|
29
|
-
selectedValue = $selectedValueStore;
|
|
30
|
+
selectedValue = $selectedValueStore;
|
|
30
31
|
}
|
|
32
|
+
// ----- Events ----- //
|
|
31
33
|
const dispatch = createEventDispatcher();
|
|
32
34
|
const raiseSelect = (value) => {
|
|
33
|
-
|
|
35
|
+
dispatch('select', { value });
|
|
34
36
|
};
|
|
35
37
|
$: {
|
|
36
|
-
|
|
38
|
+
raiseSelect(selectedValue);
|
|
37
39
|
}
|
|
40
|
+
// ----- Methods ----- //
|
|
38
41
|
export const blur = () => {
|
|
39
|
-
|
|
42
|
+
listRef?.blur();
|
|
40
43
|
};
|
|
41
44
|
export const click = () => {
|
|
42
|
-
|
|
45
|
+
listRef?.click();
|
|
43
46
|
};
|
|
44
47
|
export const focus = (options) => {
|
|
45
|
-
|
|
48
|
+
listRef?.focus();
|
|
46
49
|
};
|
|
47
50
|
export const scrollToSelectedItem = () => {
|
|
48
|
-
|
|
49
|
-
|
|
51
|
+
const element = getSelectedItemElement();
|
|
52
|
+
element?.scrollIntoView({ block: 'nearest', inline: 'nearest' });
|
|
50
53
|
};
|
|
54
|
+
// ----- Focus ----- //
|
|
55
|
+
// ----- Selection ----- //
|
|
51
56
|
const isElementListItem = (candidate) => {
|
|
52
|
-
|
|
57
|
+
return (candidate &&
|
|
58
|
+
candidate.getAttribute('data-value') !== null &&
|
|
59
|
+
candidate.getAttribute('data-value') !== undefined &&
|
|
60
|
+
candidate.getAttribute('role') === 'listitem');
|
|
53
61
|
};
|
|
54
62
|
const getSelectedItemElement = () => {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
63
|
+
if (isElementListItem(lastSelectedItemRef) &&
|
|
64
|
+
lastSelectedItemRef?.getAttribute('data-value') === selectedValue &&
|
|
65
|
+
lastSelectedItemRef?.closest('[role="list"]') === listRef) {
|
|
66
|
+
return lastSelectedItemRef;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
return listRef?.querySelector('[data-value][aria-selected=true]');
|
|
70
|
+
}
|
|
60
71
|
};
|
|
61
72
|
const selectItem = (value, element) => {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
73
|
+
selectedValueStore.set(value);
|
|
74
|
+
lastSelectedItemRef = element;
|
|
75
|
+
element.scrollIntoView({ block: 'nearest', inline: 'nearest' });
|
|
65
76
|
};
|
|
66
77
|
export const selectFirstItem = () => {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
78
|
+
let candidate = listRef?.firstElementChild;
|
|
79
|
+
while (candidate && !isElementListItem(candidate)) {
|
|
80
|
+
candidate = candidate.nextElementSibling;
|
|
81
|
+
}
|
|
82
|
+
let candidateValue = candidate?.getAttribute('data-value');
|
|
83
|
+
if (candidateValue && candidate) {
|
|
84
|
+
selectItem(candidateValue, candidate);
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
return false;
|
|
77
88
|
};
|
|
78
89
|
export const selectPreviousItem = () => {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
+
let selectedItem = getSelectedItemElement();
|
|
91
|
+
let candidate = selectedItem?.previousElementSibling;
|
|
92
|
+
while (candidate && !isElementListItem(candidate)) {
|
|
93
|
+
candidate = candidate.previousElementSibling;
|
|
94
|
+
}
|
|
95
|
+
let candidateValue = candidate?.getAttribute('data-value');
|
|
96
|
+
if (candidateValue && candidate) {
|
|
97
|
+
selectItem(candidateValue, candidate);
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
return false;
|
|
90
101
|
};
|
|
91
102
|
export const selectNextItem = () => {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
+
let selectedItem = getSelectedItemElement();
|
|
104
|
+
let candidate = selectedItem?.nextElementSibling;
|
|
105
|
+
while (candidate && !isElementListItem(candidate)) {
|
|
106
|
+
candidate = candidate.nextElementSibling;
|
|
107
|
+
}
|
|
108
|
+
let candidateValue = candidate?.getAttribute('data-value');
|
|
109
|
+
if (candidateValue && candidate) {
|
|
110
|
+
selectItem(candidateValue, candidate);
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
return false;
|
|
103
114
|
};
|
|
104
115
|
export const selectLastItem = () => {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
let candidateValue = candidate?.getAttribute("data-value");
|
|
110
|
-
if (candidateValue && candidate) {
|
|
111
|
-
selectItem(candidateValue, candidate);
|
|
112
|
-
return true;
|
|
113
|
-
}
|
|
114
|
-
return false;
|
|
115
|
-
};
|
|
116
|
-
const onClick = (event) => {
|
|
117
|
-
if (!disabled) {
|
|
118
|
-
let candidate = event.target;
|
|
119
|
-
let candidateValue = candidate?.getAttribute("data-value");
|
|
120
|
-
if (candidateValue === void 0 || candidateValue === null) {
|
|
121
|
-
candidate = candidate?.closest("[data-value]");
|
|
122
|
-
candidateValue = candidate?.getAttribute("data-value");
|
|
116
|
+
let candidate = listRef?.lastElementChild;
|
|
117
|
+
while (candidate && !isElementListItem(candidate)) {
|
|
118
|
+
candidate = candidate.previousElementSibling;
|
|
123
119
|
}
|
|
120
|
+
let candidateValue = candidate?.getAttribute('data-value');
|
|
124
121
|
if (candidateValue && candidate) {
|
|
125
|
-
|
|
122
|
+
selectItem(candidateValue, candidate);
|
|
123
|
+
return true;
|
|
126
124
|
}
|
|
127
|
-
|
|
125
|
+
return false;
|
|
128
126
|
};
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
case "End":
|
|
138
|
-
selectLastItem();
|
|
139
|
-
event.preventDefault();
|
|
140
|
-
event.stopPropagation();
|
|
141
|
-
return false;
|
|
142
|
-
case "ArrowLeft":
|
|
143
|
-
if (horizontal) {
|
|
144
|
-
selectedValue !== void 0 ? selectPreviousItem() : selectLastItem();
|
|
145
|
-
}
|
|
146
|
-
event.preventDefault();
|
|
147
|
-
event.stopPropagation();
|
|
148
|
-
return false;
|
|
149
|
-
case "ArrowRight":
|
|
150
|
-
if (horizontal) {
|
|
151
|
-
selectedValue !== void 0 ? selectNextItem() : selectFirstItem();
|
|
127
|
+
// ----- Event Handlers ----- //
|
|
128
|
+
const onClick = (event) => {
|
|
129
|
+
if (!disabled) {
|
|
130
|
+
let candidate = event.target;
|
|
131
|
+
let candidateValue = candidate?.getAttribute('data-value');
|
|
132
|
+
if (candidateValue === undefined || candidateValue === null) {
|
|
133
|
+
candidate = candidate?.closest('[data-value]');
|
|
134
|
+
candidateValue = candidate?.getAttribute('data-value');
|
|
152
135
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
return false;
|
|
156
|
-
case "ArrowUp":
|
|
157
|
-
if (!horizontal) {
|
|
158
|
-
selectedValue !== void 0 ? selectPreviousItem() : selectLastItem();
|
|
136
|
+
if (candidateValue && candidate) {
|
|
137
|
+
selectItem(candidateValue, candidate);
|
|
159
138
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
const onKeydown = (event) => {
|
|
142
|
+
if (!disabled && !event.ctrlKey && !event.shiftKey && !event.altKey && !event.metaKey) {
|
|
143
|
+
switch (event.key) {
|
|
144
|
+
case 'Home':
|
|
145
|
+
selectFirstItem();
|
|
146
|
+
event.preventDefault();
|
|
147
|
+
event.stopPropagation();
|
|
148
|
+
return false;
|
|
149
|
+
case 'End':
|
|
150
|
+
selectLastItem();
|
|
151
|
+
event.preventDefault();
|
|
152
|
+
event.stopPropagation();
|
|
153
|
+
return false;
|
|
154
|
+
case 'ArrowLeft':
|
|
155
|
+
if (horizontal) {
|
|
156
|
+
selectedValue !== undefined ? selectPreviousItem() : selectLastItem();
|
|
157
|
+
}
|
|
158
|
+
event.preventDefault();
|
|
159
|
+
event.stopPropagation();
|
|
160
|
+
return false;
|
|
161
|
+
case 'ArrowRight':
|
|
162
|
+
if (horizontal) {
|
|
163
|
+
selectedValue !== undefined ? selectNextItem() : selectFirstItem();
|
|
164
|
+
}
|
|
165
|
+
event.preventDefault();
|
|
166
|
+
event.stopPropagation();
|
|
167
|
+
return false;
|
|
168
|
+
case 'ArrowUp':
|
|
169
|
+
if (!horizontal) {
|
|
170
|
+
selectedValue !== undefined ? selectPreviousItem() : selectLastItem();
|
|
171
|
+
}
|
|
172
|
+
event.preventDefault();
|
|
173
|
+
event.stopPropagation();
|
|
174
|
+
return false;
|
|
175
|
+
case 'ArrowDown':
|
|
176
|
+
if (!horizontal) {
|
|
177
|
+
selectedValue !== undefined ? selectNextItem() : selectFirstItem();
|
|
178
|
+
}
|
|
179
|
+
event.preventDefault();
|
|
180
|
+
event.stopPropagation();
|
|
181
|
+
return false;
|
|
166
182
|
}
|
|
167
|
-
event.preventDefault();
|
|
168
|
-
event.stopPropagation();
|
|
169
|
-
return false;
|
|
170
183
|
}
|
|
171
|
-
}
|
|
172
184
|
};
|
|
185
|
+
// ----- Set Context ----- //
|
|
173
186
|
setContext(LIST_CONTEXT_KEY, {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
horizontal: horizontalStore
|
|
187
|
+
disabled: disabledStore,
|
|
188
|
+
selectedValue: selectedValueStore,
|
|
189
|
+
horizontal: horizontalStore
|
|
178
190
|
});
|
|
179
191
|
</script>
|
|
180
192
|
|
|
@@ -183,13 +195,14 @@ setContext(LIST_CONTEXT_KEY, {
|
|
|
183
195
|
A list of items where a single item can be selected.
|
|
184
196
|
-->
|
|
185
197
|
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
|
|
198
|
+
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
|
|
199
|
+
<!-- svelte-ignore a11y-role-supports-aria-props -->
|
|
186
200
|
<div
|
|
187
201
|
aria-activedescendant={selectedValue}
|
|
188
202
|
aria-disabled={disabled}
|
|
189
203
|
aria-orientation={horizontal ? 'horizontal' : 'vertical'}
|
|
190
204
|
bind:this={listRef}
|
|
191
|
-
class=
|
|
192
|
-
class:composed
|
|
205
|
+
class={`sterling-list ${variant}`}
|
|
193
206
|
class:disabled
|
|
194
207
|
class:horizontal
|
|
195
208
|
class:using-keyboard={$usingKeyboard}
|
|
@@ -227,107 +240,6 @@ A list of items where a single item can be selected.
|
|
|
227
240
|
{...$$restProps}
|
|
228
241
|
>
|
|
229
242
|
<div class="container">
|
|
230
|
-
<slot {
|
|
243
|
+
<slot {disabled} {horizontal} {selectedValue} {variant} />
|
|
231
244
|
</div>
|
|
232
245
|
</div>
|
|
233
|
-
|
|
234
|
-
<style>
|
|
235
|
-
.sterling-list {
|
|
236
|
-
background-color: var(--stsv-common__background-color);
|
|
237
|
-
border-color: var(--stsv-input__border-color);
|
|
238
|
-
border-radius: var(--stsv-input__border-radius);
|
|
239
|
-
border-style: var(--stsv-input__border-style);
|
|
240
|
-
border-width: var(--stsv-input__border-width);
|
|
241
|
-
box-sizing: border-box;
|
|
242
|
-
color: var(--stsv-input__color);
|
|
243
|
-
height: 100%;
|
|
244
|
-
overflow-x: hidden;
|
|
245
|
-
overflow-y: auto;
|
|
246
|
-
margin: 0;
|
|
247
|
-
outline: none;
|
|
248
|
-
padding: 0;
|
|
249
|
-
position: relative;
|
|
250
|
-
transition: background-color 250ms, color 250ms, border-color 250ms;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
.sterling-list.horizontal {
|
|
254
|
-
height: unset;
|
|
255
|
-
overflow-x: auto;
|
|
256
|
-
overflow-y: hidden;
|
|
257
|
-
width: 100%;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
.sterling-list:hover {
|
|
261
|
-
border-color: var(--stsv-input__border-color--hover);
|
|
262
|
-
color: var(--stsv-input__color--hover);
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
.sterling-list.using-keyboard:focus-within {
|
|
266
|
-
border-color: var(--stsv-input__border-color--focus);
|
|
267
|
-
color: var(--stsv-input__color--focus);
|
|
268
|
-
outline-color: var(--stsv-common__outline-color);
|
|
269
|
-
outline-offset: var(--stsv-common__outline-offset);
|
|
270
|
-
outline-style: var(--stsv-common__outline-style);
|
|
271
|
-
outline-width: var(--stsv-common__outline-width);
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
.sterling-list.composed,
|
|
275
|
-
.sterling-list.composed:hover,
|
|
276
|
-
.sterling-list.composed.using-keyboard:focus-within,
|
|
277
|
-
.sterling-list.composed.disabled {
|
|
278
|
-
background: none;
|
|
279
|
-
border: none;
|
|
280
|
-
outline: none;
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
.sterling-list.disabled * {
|
|
284
|
-
cursor: not-allowed;
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
/* ----- container - a layout panel that grows with the items ----- */
|
|
288
|
-
|
|
289
|
-
.container {
|
|
290
|
-
display: flex;
|
|
291
|
-
position: relative;
|
|
292
|
-
flex-direction: column;
|
|
293
|
-
flex-wrap: nowrap;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
.sterling-list.horizontal .container {
|
|
297
|
-
flex-direction: row;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
.container::after {
|
|
301
|
-
background: repeating-linear-gradient(
|
|
302
|
-
var(--stsv-common--disabled__stripe-angle),
|
|
303
|
-
var(--stsv-common--disabled__stripe-color),
|
|
304
|
-
var(--stsv-common--disabled__stripe-color) var(--stsv-common--disabled__stripe-width),
|
|
305
|
-
var(--stsv-common--disabled__stripe-color--alt) var(--stsv-common--disabled__stripe-width),
|
|
306
|
-
var(--stsv-common--disabled__stripe-color--alt)
|
|
307
|
-
calc(2 * var(--stsv-common--disabled__stripe-width))
|
|
308
|
-
);
|
|
309
|
-
content: '';
|
|
310
|
-
bottom: 0;
|
|
311
|
-
left: 0;
|
|
312
|
-
opacity: 0;
|
|
313
|
-
position: absolute;
|
|
314
|
-
right: 0;
|
|
315
|
-
top: 0;
|
|
316
|
-
height: 100%;
|
|
317
|
-
pointer-events: none;
|
|
318
|
-
transition: opacity 250ms;
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
.sterling-list.disabled .container::after {
|
|
322
|
-
opacity: 1;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
/* ----- media queries ----- */
|
|
326
|
-
|
|
327
|
-
@media (prefers-reduced-motion) {
|
|
328
|
-
.sterling-list,
|
|
329
|
-
.container::after {
|
|
330
|
-
transition: none;
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
</style>
|
package/List.svelte.d.ts
CHANGED
|
@@ -2,11 +2,10 @@ import { SvelteComponentTyped } from "svelte";
|
|
|
2
2
|
declare const __propDef: {
|
|
3
3
|
props: {
|
|
4
4
|
[x: string]: any;
|
|
5
|
-
colorful?: boolean | undefined;
|
|
6
|
-
composed?: boolean | undefined;
|
|
7
5
|
disabled?: boolean | undefined;
|
|
8
6
|
horizontal?: boolean | undefined;
|
|
9
7
|
selectedValue?: string | undefined;
|
|
8
|
+
variant?: string | undefined;
|
|
10
9
|
blur?: (() => void) | undefined;
|
|
11
10
|
click?: (() => void) | undefined;
|
|
12
11
|
focus?: ((options?: FocusOptions) => void) | undefined;
|
|
@@ -50,10 +49,10 @@ declare const __propDef: {
|
|
|
50
49
|
};
|
|
51
50
|
slots: {
|
|
52
51
|
default: {
|
|
53
|
-
composed: boolean;
|
|
54
52
|
disabled: boolean;
|
|
55
53
|
horizontal: boolean;
|
|
56
54
|
selectedValue: string | undefined;
|
|
55
|
+
variant: string;
|
|
57
56
|
};
|
|
58
57
|
};
|
|
59
58
|
};
|
package/List.types.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import type { Readable, Writable } from 'svelte/store';
|
|
2
|
+
/**
|
|
3
|
+
* The context for a List and its descendants.
|
|
4
|
+
*/
|
|
2
5
|
export type ListContext = {
|
|
3
|
-
|
|
6
|
+
/** When true, the list and its items are disabled. */
|
|
4
7
|
disabled?: Readable<boolean>;
|
|
8
|
+
/** The value of the currently selected item. */
|
|
5
9
|
selectedValue?: Writable<string | undefined>;
|
|
10
|
+
/** When true, the list is laid out horizontally. */
|
|
6
11
|
horizontal?: Readable<boolean>;
|
|
7
12
|
};
|