@geoffcox/sterling-svelte 0.0.30 → 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 +188 -0
- package/Callout.svelte.d.ts +54 -0
- 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 -219
- 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 -64
- package/Menu.svelte.d.ts +4 -1
- package/MenuBar.svelte +84 -86
- package/MenuBar.svelte.d.ts +4 -1
- package/MenuButton.svelte +67 -74
- 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 +2 -0
- package/{floating-ui.constants.js → Popover.constants.js} +10 -9
- package/Popover.svelte +72 -82
- package/Popover.svelte.d.ts +10 -5
- package/Popover.types.d.ts +4 -0
- 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 +124 -251
- 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 +88 -222
- package/Tooltip.svelte.d.ts +21 -13
- 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 +13 -18
- package/index.js +11 -15
- 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 +136 -19
- package/Link.constants.d.ts +0 -1
- package/Link.constants.js +0 -1
- package/Link.types.d.ts +0 -4
- package/Tooltip.constants.d.ts +0 -1
- package/Tooltip.constants.js +0 -1
- package/Tooltip.types.d.ts +0 -4
- package/Tooltip.types.js +0 -1
- package/floating-ui.constants.d.ts +0 -1
- package/floating-ui.types.d.ts +0 -4
- package/floating-ui.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/{Link.types.js → Popover.types.js} +0 -0
- /package/{stores → mediaQueries}/prefersReducedMotion.js +0 -0
- /package/{stores → mediaQueries}/usingKeyboard.js +0 -0
package/TabList.svelte
CHANGED
|
@@ -1,186 +1,198 @@
|
|
|
1
|
-
<script>import { createEventDispatcher, setContext } from
|
|
2
|
-
import { writable } from
|
|
3
|
-
import { TAB_LIST_CONTEXT_KEY } from
|
|
4
|
-
|
|
1
|
+
<script>import { createEventDispatcher, setContext } from 'svelte';
|
|
2
|
+
import { writable } from 'svelte/store';
|
|
3
|
+
import { TAB_LIST_CONTEXT_KEY } from './TabList.constants';
|
|
4
|
+
// ----- Props ----- //
|
|
5
|
+
/** When true, the tab list and its tabs are disabled. */
|
|
5
6
|
export let disabled = false;
|
|
7
|
+
/** The value of the currently selected tab. */
|
|
8
|
+
export let selectedValue = undefined;
|
|
9
|
+
/** When true, the tab list is displayed vertically. */
|
|
6
10
|
export let vertical = false;
|
|
7
|
-
|
|
11
|
+
/** Additional class names to apply. */
|
|
12
|
+
export let variant = '';
|
|
13
|
+
// ----- State ----- //
|
|
8
14
|
let tabListRef;
|
|
9
15
|
let lastSelectedTabRef;
|
|
10
|
-
const colorfulStore = writable(colorful);
|
|
11
16
|
const disabledStore = writable(disabled);
|
|
12
17
|
const selectedValueStore = writable(selectedValue);
|
|
13
18
|
const verticalStore = writable(vertical);
|
|
14
|
-
$:
|
|
15
|
-
|
|
16
|
-
$:
|
|
17
|
-
disabledStore.set(disabled);
|
|
18
|
-
$:
|
|
19
|
-
selectedValueStore.set(selectedValue);
|
|
19
|
+
$: disabledStore.set(disabled);
|
|
20
|
+
$: selectedValueStore.set(selectedValue);
|
|
20
21
|
$: {
|
|
21
|
-
|
|
22
|
+
selectedValue = $selectedValueStore;
|
|
22
23
|
}
|
|
23
|
-
$:
|
|
24
|
-
|
|
24
|
+
$: verticalStore.set(vertical);
|
|
25
|
+
// ----- Events ----- //
|
|
25
26
|
const dispatch = createEventDispatcher();
|
|
26
27
|
const raiseSelect = (value) => {
|
|
27
|
-
|
|
28
|
+
dispatch('select', { value });
|
|
28
29
|
};
|
|
29
30
|
$: {
|
|
30
|
-
|
|
31
|
+
raiseSelect(selectedValue);
|
|
31
32
|
}
|
|
33
|
+
// ----- Methods ----- //
|
|
32
34
|
export const blur = () => {
|
|
33
|
-
|
|
35
|
+
tabListRef?.blur();
|
|
34
36
|
};
|
|
35
37
|
export const focus = (options) => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
let selectedItem = getSelectedTabElement();
|
|
39
|
+
if (selectedValue && selectedItem) {
|
|
40
|
+
selectTab(selectedValue, selectedItem);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
selectFirstTab();
|
|
44
|
+
}
|
|
42
45
|
};
|
|
46
|
+
// ----- Selection ----- //
|
|
43
47
|
const isElementTab = (candidate) => {
|
|
44
|
-
|
|
48
|
+
return (candidate &&
|
|
49
|
+
candidate.getAttribute('data-value') !== null &&
|
|
50
|
+
candidate.getAttribute('data-value') !== undefined &&
|
|
51
|
+
candidate.getAttribute('role') === 'tab');
|
|
45
52
|
};
|
|
46
53
|
const getSelectedTabElement = () => {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
54
|
+
if (isElementTab(lastSelectedTabRef) &&
|
|
55
|
+
lastSelectedTabRef?.getAttribute('data-value') === selectedValue &&
|
|
56
|
+
lastSelectedTabRef?.closest('[role="tablist"]') === tabListRef) {
|
|
57
|
+
return lastSelectedTabRef;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
return tabListRef?.querySelector('[data-value][aria-selected=true]');
|
|
61
|
+
}
|
|
52
62
|
};
|
|
53
63
|
const selectTab = (value, element) => {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
64
|
+
selectedValueStore.set(value);
|
|
65
|
+
lastSelectedTabRef = element;
|
|
66
|
+
element.scrollIntoView({ block: 'nearest', inline: 'nearest' });
|
|
67
|
+
element.focus();
|
|
58
68
|
};
|
|
59
69
|
export const selectFirstTab = () => {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
+
let candidate = tabListRef?.firstElementChild;
|
|
71
|
+
while (candidate && !isElementTab(candidate)) {
|
|
72
|
+
candidate = candidate.nextElementSibling;
|
|
73
|
+
}
|
|
74
|
+
let candidateValue = candidate?.getAttribute('data-value');
|
|
75
|
+
if (candidateValue && candidate) {
|
|
76
|
+
selectTab(candidateValue, candidate);
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
return false;
|
|
70
80
|
};
|
|
71
81
|
export const selectPreviousTab = () => {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
82
|
+
let selectedTab = getSelectedTabElement();
|
|
83
|
+
let candidate = selectedTab?.previousElementSibling;
|
|
84
|
+
while (candidate && !isElementTab(candidate)) {
|
|
85
|
+
candidate = candidate.previousElementSibling;
|
|
86
|
+
}
|
|
87
|
+
let candidateValue = candidate?.getAttribute('data-value');
|
|
88
|
+
if (candidateValue && candidate) {
|
|
89
|
+
selectTab(candidateValue, candidate);
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
return false;
|
|
83
93
|
};
|
|
84
94
|
export const selectNextTab = () => {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
95
|
+
let selectedTab = getSelectedTabElement();
|
|
96
|
+
let candidate = selectedTab?.nextElementSibling;
|
|
97
|
+
while (candidate && !isElementTab(candidate)) {
|
|
98
|
+
candidate = candidate.nextElementSibling;
|
|
99
|
+
}
|
|
100
|
+
let candidateValue = candidate?.getAttribute('data-value');
|
|
101
|
+
if (candidateValue && candidate) {
|
|
102
|
+
selectTab(candidateValue, candidate);
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
return false;
|
|
96
106
|
};
|
|
97
107
|
export const selectLastTab = () => {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
let candidateValue = candidate?.getAttribute("data-value");
|
|
103
|
-
if (candidateValue && candidate) {
|
|
104
|
-
selectTab(candidateValue, candidate);
|
|
105
|
-
return true;
|
|
106
|
-
}
|
|
107
|
-
return false;
|
|
108
|
-
};
|
|
109
|
-
const onClick = (event) => {
|
|
110
|
-
if (!disabled) {
|
|
111
|
-
let candidate = event.target;
|
|
112
|
-
let candidateValue = candidate?.getAttribute("data-value");
|
|
113
|
-
if (candidateValue === void 0 || candidateValue === null) {
|
|
114
|
-
candidate = candidate?.closest("[role=tab]");
|
|
115
|
-
candidateValue = candidate?.getAttribute("data-value");
|
|
108
|
+
let candidate = tabListRef?.lastElementChild;
|
|
109
|
+
while (candidate && !isElementTab(candidate)) {
|
|
110
|
+
candidate = candidate.previousElementSibling;
|
|
116
111
|
}
|
|
112
|
+
let candidateValue = candidate?.getAttribute('data-value');
|
|
117
113
|
if (candidateValue && candidate) {
|
|
118
|
-
|
|
114
|
+
selectTab(candidateValue, candidate);
|
|
115
|
+
return true;
|
|
119
116
|
}
|
|
120
|
-
|
|
117
|
+
return false;
|
|
121
118
|
};
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
case "End":
|
|
131
|
-
selectLastTab();
|
|
132
|
-
event.preventDefault();
|
|
133
|
-
event.stopPropagation();
|
|
134
|
-
return false;
|
|
135
|
-
case "ArrowLeft":
|
|
136
|
-
if (!vertical) {
|
|
137
|
-
selectPreviousTab();
|
|
138
|
-
}
|
|
139
|
-
event.preventDefault();
|
|
140
|
-
event.stopPropagation();
|
|
141
|
-
return false;
|
|
142
|
-
case "ArrowRight":
|
|
143
|
-
if (!vertical) {
|
|
144
|
-
selectNextTab();
|
|
119
|
+
// ----- EventHandlers ----- //
|
|
120
|
+
const onClick = (event) => {
|
|
121
|
+
if (!disabled) {
|
|
122
|
+
let candidate = event.target;
|
|
123
|
+
let candidateValue = candidate?.getAttribute('data-value');
|
|
124
|
+
if (candidateValue === undefined || candidateValue === null) {
|
|
125
|
+
candidate = candidate?.closest('[role=tab]');
|
|
126
|
+
candidateValue = candidate?.getAttribute('data-value');
|
|
145
127
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
return false;
|
|
149
|
-
case "ArrowUp":
|
|
150
|
-
if (vertical) {
|
|
151
|
-
selectPreviousTab();
|
|
128
|
+
if (candidateValue && candidate) {
|
|
129
|
+
selectTab(candidateValue, candidate);
|
|
152
130
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
const onKeydown = (event) => {
|
|
134
|
+
// if using arrows, only move when there are no modifier keys
|
|
135
|
+
if (!disabled && !event.ctrlKey && !event.shiftKey && !event.altKey && !event.metaKey) {
|
|
136
|
+
switch (event.key) {
|
|
137
|
+
case 'Home':
|
|
138
|
+
selectFirstTab();
|
|
139
|
+
event.preventDefault();
|
|
140
|
+
event.stopPropagation();
|
|
141
|
+
return false;
|
|
142
|
+
case 'End':
|
|
143
|
+
selectLastTab();
|
|
144
|
+
event.preventDefault();
|
|
145
|
+
event.stopPropagation();
|
|
146
|
+
return false;
|
|
147
|
+
case 'ArrowLeft':
|
|
148
|
+
if (!vertical) {
|
|
149
|
+
selectPreviousTab();
|
|
150
|
+
}
|
|
151
|
+
event.preventDefault();
|
|
152
|
+
event.stopPropagation();
|
|
153
|
+
return false;
|
|
154
|
+
case 'ArrowRight':
|
|
155
|
+
if (!vertical) {
|
|
156
|
+
selectNextTab();
|
|
157
|
+
}
|
|
158
|
+
event.preventDefault();
|
|
159
|
+
event.stopPropagation();
|
|
160
|
+
return false;
|
|
161
|
+
case 'ArrowUp':
|
|
162
|
+
if (vertical) {
|
|
163
|
+
selectPreviousTab();
|
|
164
|
+
}
|
|
165
|
+
event.preventDefault();
|
|
166
|
+
event.stopPropagation();
|
|
167
|
+
return false;
|
|
168
|
+
case 'ArrowDown':
|
|
169
|
+
if (vertical) {
|
|
170
|
+
selectNextTab();
|
|
171
|
+
}
|
|
172
|
+
event.preventDefault();
|
|
173
|
+
event.stopPropagation();
|
|
174
|
+
return false;
|
|
175
|
+
default:
|
|
176
|
+
break;
|
|
159
177
|
}
|
|
160
|
-
event.preventDefault();
|
|
161
|
-
event.stopPropagation();
|
|
162
|
-
return false;
|
|
163
|
-
default:
|
|
164
|
-
break;
|
|
165
178
|
}
|
|
166
|
-
}
|
|
167
179
|
};
|
|
180
|
+
// ----- Set Context ----- //
|
|
168
181
|
setContext(TAB_LIST_CONTEXT_KEY, {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
vertical: verticalStore
|
|
182
|
+
disabled: disabledStore,
|
|
183
|
+
selectedValue: selectedValueStore,
|
|
184
|
+
vertical: verticalStore
|
|
173
185
|
});
|
|
174
186
|
</script>
|
|
175
187
|
|
|
176
188
|
<div
|
|
177
189
|
aria-orientation={vertical ? 'vertical' : 'horizontal'}
|
|
178
190
|
bind:this={tabListRef}
|
|
179
|
-
class=
|
|
180
|
-
class:colorful
|
|
191
|
+
class={`sterling-tab-list ${variant}`}
|
|
181
192
|
class:disabled
|
|
182
193
|
class:vertical
|
|
183
194
|
role="tablist"
|
|
195
|
+
tabindex="-1"
|
|
184
196
|
on:blur
|
|
185
197
|
on:click
|
|
186
198
|
on:click={onClick}
|
|
@@ -212,42 +224,5 @@ setContext(TAB_LIST_CONTEXT_KEY, {
|
|
|
212
224
|
on:paste
|
|
213
225
|
{...$$restProps}
|
|
214
226
|
>
|
|
215
|
-
<slot {disabled} {selectedValue} {vertical} />
|
|
227
|
+
<slot {disabled} {selectedValue} {variant} {vertical} />
|
|
216
228
|
</div>
|
|
217
|
-
|
|
218
|
-
<style>
|
|
219
|
-
.sterling-tab-list {
|
|
220
|
-
box-sizing: border-box;
|
|
221
|
-
display: grid;
|
|
222
|
-
margin: 0;
|
|
223
|
-
padding: calc(2 * var(--stsv-common__outline-width));
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
.sterling-tab-list:not(.vertical) {
|
|
227
|
-
column-gap: 0.5em;
|
|
228
|
-
grid-auto-flow: column;
|
|
229
|
-
grid-template-columns: repeat(auto-fill, auto);
|
|
230
|
-
grid-template-rows: 1fr;
|
|
231
|
-
overflow-x: auto;
|
|
232
|
-
overflow-y: hidden;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
.sterling-tab-list.vertical {
|
|
236
|
-
grid-auto-flow: row;
|
|
237
|
-
grid-template-rows: auto;
|
|
238
|
-
grid-template-columns: 1fr;
|
|
239
|
-
overflow-x: hidden;
|
|
240
|
-
overflow-y: auto;
|
|
241
|
-
row-gap: 0.5em;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
.sterling-tab-list:hover {
|
|
245
|
-
color: var(--stsv-common__color--hover);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
@media (prefers-reduced-motion) {
|
|
249
|
-
.sterling-tab-list {
|
|
250
|
-
transition: none;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
</style>
|
package/TabList.svelte.d.ts
CHANGED
|
@@ -2,10 +2,10 @@ import { SvelteComponentTyped } from "svelte";
|
|
|
2
2
|
declare const __propDef: {
|
|
3
3
|
props: {
|
|
4
4
|
[x: string]: any;
|
|
5
|
-
colorful?: boolean | undefined;
|
|
6
5
|
disabled?: boolean | undefined;
|
|
7
|
-
vertical?: boolean | undefined;
|
|
8
6
|
selectedValue?: string | undefined;
|
|
7
|
+
vertical?: boolean | undefined;
|
|
8
|
+
variant?: string | undefined;
|
|
9
9
|
blur?: (() => void) | undefined;
|
|
10
10
|
focus?: ((options?: FocusOptions) => void) | undefined;
|
|
11
11
|
selectFirstTab?: (() => boolean) | undefined;
|
|
@@ -49,6 +49,7 @@ declare const __propDef: {
|
|
|
49
49
|
default: {
|
|
50
50
|
disabled: boolean;
|
|
51
51
|
selectedValue: string | undefined;
|
|
52
|
+
variant: string;
|
|
52
53
|
vertical: boolean;
|
|
53
54
|
};
|
|
54
55
|
};
|
package/TabList.types.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import type { Readable, Writable } from 'svelte/store';
|
|
2
|
+
/**
|
|
3
|
+
* The context for a TabList and its tabs.
|
|
4
|
+
*/
|
|
2
5
|
export type TabListContext = {
|
|
3
|
-
|
|
6
|
+
/** When true, the tablist and its tabs are disabled. */
|
|
4
7
|
disabled: Readable<boolean>;
|
|
8
|
+
/** The value of the currently selected tab. */
|
|
5
9
|
selectedValue: Writable<string | undefined>;
|
|
10
|
+
/** When true, the tabs are displayed vertically. */
|
|
6
11
|
vertical: Readable<boolean>;
|
|
7
12
|
};
|
package/TextArea.svelte
CHANGED
|
@@ -1,49 +1,58 @@
|
|
|
1
|
-
<script>import { onMount } from
|
|
1
|
+
<script>import { onMount } from 'svelte';
|
|
2
|
+
// ----- Props ----- //
|
|
2
3
|
export let disabled = false;
|
|
3
|
-
export let value =
|
|
4
|
+
export let value = '';
|
|
5
|
+
/** When true, the text area will resize itself vertically to fit text.*/
|
|
4
6
|
export let autoHeight = false;
|
|
5
|
-
|
|
6
|
-
export let resize =
|
|
7
|
+
/** Sets the resize handle direction. */
|
|
8
|
+
export let resize = 'none';
|
|
9
|
+
/** Additional class names to apply. */
|
|
10
|
+
export let variant = '';
|
|
11
|
+
// ----- State ----- //
|
|
7
12
|
let textAreaRef;
|
|
8
13
|
const autoSetHeight = () => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
14
|
+
if (autoHeight && textAreaRef) {
|
|
15
|
+
// the style must be directly set to avoid re-rendering looping latency
|
|
16
|
+
// setting to auto for a moment allows the textarea to shrink
|
|
17
|
+
textAreaRef.style.height = 'auto';
|
|
18
|
+
textAreaRef.style.height = `${textAreaRef.scrollHeight}px`;
|
|
19
|
+
}
|
|
13
20
|
};
|
|
21
|
+
// ----- Event Handlers ----- //
|
|
14
22
|
const onInput = () => {
|
|
15
|
-
|
|
23
|
+
autoSetHeight();
|
|
16
24
|
};
|
|
17
|
-
$:
|
|
18
|
-
autoHeight, autoSetHeight();
|
|
25
|
+
$: autoHeight, autoSetHeight();
|
|
19
26
|
onMount(() => {
|
|
20
|
-
|
|
27
|
+
autoSetHeight();
|
|
21
28
|
});
|
|
29
|
+
// ----- Methods ----- //
|
|
22
30
|
export const blur = () => {
|
|
23
|
-
|
|
31
|
+
textAreaRef?.blur();
|
|
24
32
|
};
|
|
25
33
|
export const click = () => {
|
|
26
|
-
|
|
34
|
+
textAreaRef?.click();
|
|
27
35
|
};
|
|
28
36
|
export const focus = (options) => {
|
|
29
|
-
|
|
37
|
+
textAreaRef?.focus();
|
|
30
38
|
};
|
|
31
39
|
export const select = () => {
|
|
32
|
-
|
|
40
|
+
textAreaRef?.select();
|
|
33
41
|
};
|
|
34
42
|
export const setSelectionRange = (start, end, direction) => {
|
|
35
|
-
|
|
43
|
+
textAreaRef?.setSelectionRange(start, end, direction);
|
|
36
44
|
};
|
|
37
45
|
export const setRangeText = (replacement, start, end, selectionMode) => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
46
|
+
if (start && end) {
|
|
47
|
+
textAreaRef?.setRangeText(replacement, start, end, selectionMode);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
textAreaRef?.setRangeText(replacement);
|
|
51
|
+
}
|
|
43
52
|
};
|
|
44
53
|
</script>
|
|
45
54
|
|
|
46
|
-
<div class=
|
|
55
|
+
<div class={`sterling-text-area ${variant}`} class:disabled>
|
|
47
56
|
<textarea
|
|
48
57
|
bind:this={textAreaRef}
|
|
49
58
|
bind:value
|
|
@@ -87,109 +96,3 @@ export const setRangeText = (replacement, start, end, selectionMode) => {
|
|
|
87
96
|
{...$$restProps}
|
|
88
97
|
/>
|
|
89
98
|
</div>
|
|
90
|
-
|
|
91
|
-
<style>
|
|
92
|
-
.sterling-text-area {
|
|
93
|
-
position: relative;
|
|
94
|
-
height: 100%;
|
|
95
|
-
width: 100%;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
textarea {
|
|
99
|
-
background-color: var(--stsv-input__background-color);
|
|
100
|
-
border-color: var(--stsv-input__border-color);
|
|
101
|
-
border-radius: var(--stsv-input__border-radius);
|
|
102
|
-
border-style: var(--stsv-input__border-style);
|
|
103
|
-
border-width: var(--stsv-input__border-width);
|
|
104
|
-
box-sizing: border-box;
|
|
105
|
-
color: var(--stsv-input__color);
|
|
106
|
-
display: block;
|
|
107
|
-
font: inherit;
|
|
108
|
-
line-height: inherit;
|
|
109
|
-
height: 100%;
|
|
110
|
-
outline: none;
|
|
111
|
-
padding: 0.5em;
|
|
112
|
-
margin: 0;
|
|
113
|
-
min-height: 3em;
|
|
114
|
-
overflow: hidden;
|
|
115
|
-
resize: var(--TextArea__resize, none);
|
|
116
|
-
transition: background-color 250ms, color 250ms, border-color 250ms;
|
|
117
|
-
width: 100%;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
textarea:hover {
|
|
121
|
-
background-color: var(--stsv-input__background-color--hover);
|
|
122
|
-
border-color: var(--stsv-input__border-color--hover);
|
|
123
|
-
color: var(--stsv-input__color--hover);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
textarea:focus {
|
|
127
|
-
background-color: var(--stsv-input__background-color--focus);
|
|
128
|
-
border-color: var(--stsv-input__border-color--focus);
|
|
129
|
-
color: var(--stsv-input__color--focus);
|
|
130
|
-
outline-color: var(--stsv-common__outline-color);
|
|
131
|
-
outline-offset: var(--stsv-common__outline-offset);
|
|
132
|
-
outline-style: var(--stsv-common__outline-style);
|
|
133
|
-
outline-width: var(--stsv-common__outline-width);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
.sterling-text-area.colorful textarea {
|
|
137
|
-
background-color: var(--stsv-input--colorful__background-color);
|
|
138
|
-
border-color: var(--stsv-input--colorful__border-color);
|
|
139
|
-
color: var(--stsv-input--colorful__color);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
.sterling-text-area.colorful textarea:hover {
|
|
143
|
-
background-color: var(--stsv-input--colorful__background-color--hover);
|
|
144
|
-
border-color: var(--stsv-input--colorful__border-color--hover);
|
|
145
|
-
color: var(--stsv-input--colorful__color--hover);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
.sterling-text-area.colorful textarea:focus {
|
|
149
|
-
background-color: var(--stsv-input--colorful__background-color--focus);
|
|
150
|
-
border-color: var(--stsv-input--colorful__border-color--focus);
|
|
151
|
-
color: var(--stsv-input--colorful__color--focus);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
.sterling-text-area:disabled {
|
|
155
|
-
cursor: not-allowed;
|
|
156
|
-
outline: none;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
.sterling-text-area::after {
|
|
160
|
-
background: repeating-linear-gradient(
|
|
161
|
-
var(--stsv-common--disabled__stripe-angle),
|
|
162
|
-
var(--stsv-common--disabled__stripe-color),
|
|
163
|
-
var(--stsv-common--disabled__stripe-color) var(--stsv-common--disabled__stripe-width),
|
|
164
|
-
var(--stsv-common--disabled__stripe-color--alt) var(--stsv-common--disabled__stripe-width),
|
|
165
|
-
var(--stsv-common--disabled__stripe-color--alt)
|
|
166
|
-
calc(2 * var(--stsv-common--disabled__stripe-width))
|
|
167
|
-
);
|
|
168
|
-
bottom: 0;
|
|
169
|
-
content: '';
|
|
170
|
-
left: 0;
|
|
171
|
-
opacity: 0;
|
|
172
|
-
position: absolute;
|
|
173
|
-
right: 0;
|
|
174
|
-
top: 0;
|
|
175
|
-
pointer-events: none;
|
|
176
|
-
transition: opacity 250ms;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
.sterling-text-area.disabled::after {
|
|
180
|
-
opacity: 1;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
textarea::placeholder {
|
|
184
|
-
color: var(--stsv-common__color--subtle);
|
|
185
|
-
transition: background-color 250ms, color 250ms, border-color 250ms;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
@media (prefers-reduced-motion) {
|
|
189
|
-
textarea,
|
|
190
|
-
.sterling-text-area,
|
|
191
|
-
.sterling-text-area::after {
|
|
192
|
-
transition: none;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
</style>
|
package/TextArea.svelte.d.ts
CHANGED
|
@@ -5,8 +5,8 @@ declare const __propDef: {
|
|
|
5
5
|
disabled?: boolean | undefined;
|
|
6
6
|
value?: string | undefined;
|
|
7
7
|
autoHeight?: boolean | undefined;
|
|
8
|
-
colorful?: boolean | undefined;
|
|
9
8
|
resize?: "none" | "vertical" | "horizontal" | "both" | undefined;
|
|
9
|
+
variant?: string | undefined;
|
|
10
10
|
blur?: (() => void) | undefined;
|
|
11
11
|
click?: (() => void) | undefined;
|
|
12
12
|
focus?: ((options?: FocusOptions) => void) | undefined;
|