@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.
Files changed (215) hide show
  1. package/@types/clickOutside.d.ts +11 -7
  2. package/Button.svelte +11 -183
  3. package/Button.svelte.d.ts +2 -6
  4. package/Callout.svelte +107 -146
  5. package/Callout.svelte.d.ts +1 -1
  6. package/Checkbox.svelte +15 -177
  7. package/Checkbox.svelte.d.ts +2 -2
  8. package/ColorPicker.svelte +204 -223
  9. package/ColorPicker.svelte.d.ts +1 -2
  10. package/Dialog.svelte +90 -187
  11. package/Dialog.svelte.d.ts +2 -1
  12. package/Dropdown.svelte +52 -220
  13. package/Dropdown.svelte.d.ts +4 -8
  14. package/HexColorSliders.svelte +77 -145
  15. package/HexColorSliders.svelte.d.ts +28 -1
  16. package/HslColorSliders.svelte +99 -179
  17. package/HslColorSliders.svelte.d.ts +28 -1
  18. package/Input.svelte +27 -136
  19. package/Input.svelte.d.ts +2 -3
  20. package/Label.constants.d.ts +1 -0
  21. package/Label.constants.js +1 -0
  22. package/Label.svelte +96 -169
  23. package/Label.svelte.d.ts +6 -1
  24. package/Label.types.d.ts +3 -1
  25. package/Link.svelte +9 -106
  26. package/Link.svelte.d.ts +0 -1
  27. package/List.svelte +142 -230
  28. package/List.svelte.d.ts +2 -3
  29. package/List.types.d.ts +6 -1
  30. package/ListItem.svelte +25 -94
  31. package/ListItem.svelte.d.ts +2 -0
  32. package/Menu.svelte +48 -65
  33. package/Menu.svelte.d.ts +4 -1
  34. package/MenuBar.svelte +84 -86
  35. package/MenuBar.svelte.d.ts +4 -1
  36. package/MenuButton.svelte +66 -73
  37. package/MenuButton.svelte.d.ts +7 -3
  38. package/MenuItem.svelte +256 -288
  39. package/MenuItem.svelte.d.ts +2 -2
  40. package/MenuItemDisplay.svelte +12 -116
  41. package/MenuItemDisplay.svelte.d.ts +21 -7
  42. package/MenuSeparator.svelte +6 -45
  43. package/MenuSeparator.svelte.d.ts +8 -78
  44. package/Popover.constants.d.ts +1 -1
  45. package/Popover.constants.js +1 -1
  46. package/Popover.svelte +66 -80
  47. package/Popover.svelte.d.ts +5 -1
  48. package/Progress.svelte +28 -126
  49. package/Progress.svelte.d.ts +4 -3
  50. package/Radio.svelte +49 -192
  51. package/Radio.svelte.d.ts +2 -2
  52. package/RgbColorSliders.svelte +48 -137
  53. package/RgbColorSliders.svelte.d.ts +5 -5
  54. package/Select.svelte +122 -250
  55. package/Select.svelte.d.ts +6 -2
  56. package/Slider.svelte +90 -259
  57. package/Slider.svelte.d.ts +1 -2
  58. package/Switch.svelte +24 -259
  59. package/Switch.svelte.d.ts +3 -1
  60. package/Tab.svelte +27 -175
  61. package/Tab.svelte.d.ts +6 -4
  62. package/TabList.svelte +146 -171
  63. package/TabList.svelte.d.ts +3 -2
  64. package/TabList.types.d.ts +6 -1
  65. package/TextArea.svelte +32 -129
  66. package/TextArea.svelte.d.ts +1 -1
  67. package/Tooltip.svelte +46 -47
  68. package/Tooltip.svelte.d.ts +8 -3
  69. package/Tree.constants.d.ts +0 -1
  70. package/Tree.constants.js +0 -1
  71. package/Tree.svelte +35 -119
  72. package/Tree.svelte.d.ts +4 -4
  73. package/Tree.types.d.ts +1 -3
  74. package/TreeChevron.svelte +18 -98
  75. package/TreeChevron.svelte.d.ts +1 -0
  76. package/TreeItem.constants.d.ts +1 -0
  77. package/TreeItem.constants.js +1 -0
  78. package/TreeItem.svelte +251 -211
  79. package/TreeItem.svelte.d.ts +7 -3
  80. package/TreeItem.types.d.ts +1 -1
  81. package/TreeItemDisplay.svelte +20 -104
  82. package/TreeItemDisplay.svelte.d.ts +2 -2
  83. package/actions/applyLightDarkMode.d.ts +10 -0
  84. package/actions/applyLightDarkMode.js +36 -0
  85. package/actions/forwardEvents.js +3 -3
  86. package/css/Button.base.css +74 -0
  87. package/css/Button.colorful.css +17 -0
  88. package/css/Button.css +7 -0
  89. package/css/Button.secondary.colorful.css +15 -0
  90. package/css/Button.secondary.css +11 -0
  91. package/css/Button.shapes.css +14 -0
  92. package/css/Button.tool.colorful.css +13 -0
  93. package/css/Button.tool.css +18 -0
  94. package/css/Callout.base.css +43 -0
  95. package/css/Callout.colorful.css +5 -0
  96. package/css/Callout.css +2 -0
  97. package/css/Checkbox.base.css +145 -0
  98. package/css/Checkbox.colorful.css +17 -0
  99. package/css/Checkbox.css +2 -0
  100. package/css/ColorPicker.base.css +23 -0
  101. package/css/ColorPicker.css +1 -0
  102. package/css/Dialog.base.css +116 -0
  103. package/css/Dialog.css +1 -0
  104. package/css/Dropdown.base.css +147 -0
  105. package/css/Dropdown.colorful.css +23 -0
  106. package/css/Dropdown.css +2 -0
  107. package/css/HexColorSliders.base.css +106 -0
  108. package/css/HexColorSliders.css +1 -0
  109. package/css/HslColorSliders.base.css +124 -0
  110. package/css/HslColorSliders.css +1 -0
  111. package/css/Input.base.css +100 -0
  112. package/css/Input.colorful.css +22 -0
  113. package/css/Input.composed.css +8 -0
  114. package/css/Input.css +3 -0
  115. package/css/Label.base.css +119 -0
  116. package/css/Label.boxed.colorful.css +21 -0
  117. package/css/Label.boxed.css +31 -0
  118. package/css/Label.colorful.css +3 -0
  119. package/css/Label.css +4 -0
  120. package/css/Link.base.css +52 -0
  121. package/css/Link.colorful.css +15 -0
  122. package/css/Link.css +6 -0
  123. package/css/Link.ghost.colorful.css +7 -0
  124. package/css/Link.ghost.css +11 -0
  125. package/css/Link.undecorated.colorful.css +6 -0
  126. package/css/Link.undecorated.css +6 -0
  127. package/css/List.base.css +98 -0
  128. package/css/List.css +1 -0
  129. package/css/ListItem.base.css +59 -0
  130. package/css/ListItem.css +1 -0
  131. package/css/Menu.base.css +21 -0
  132. package/css/Menu.css +1 -0
  133. package/css/MenuBar.base.css +9 -0
  134. package/css/MenuBar.css +1 -0
  135. package/css/MenuButton.base.css +13 -0
  136. package/css/MenuButton.css +1 -0
  137. package/css/MenuItem.base.css +48 -0
  138. package/css/MenuItem.css +1 -0
  139. package/css/MenuItemDisplay.base.css +104 -0
  140. package/css/MenuItemDisplay.css +1 -0
  141. package/css/MenuSeparator.base.css +5 -0
  142. package/css/MenuSeparator.css +1 -0
  143. package/css/Popover copy.css +21 -0
  144. package/css/Popover.css +21 -0
  145. package/css/Progress.base.css +99 -0
  146. package/css/Progress.css +1 -0
  147. package/css/Radio.base.css +135 -0
  148. package/css/Radio.colorful.css +18 -0
  149. package/css/Radio.css +2 -0
  150. package/css/RgbColorSliders.base.css +94 -0
  151. package/css/RgbColorSliders.css +1 -0
  152. package/css/Select.base.css +127 -0
  153. package/css/Select.colorful.css +24 -0
  154. package/css/Select.composed.css +12 -0
  155. package/css/Select.css +3 -0
  156. package/css/Slider.base.css +182 -0
  157. package/css/Slider.colorful.css +11 -0
  158. package/css/Slider.composed.css +8 -0
  159. package/css/Slider.css +3 -0
  160. package/css/Switch.base.css +193 -0
  161. package/css/Switch.colorful.css +39 -0
  162. package/css/Switch.css +2 -0
  163. package/css/Tab.base.css +135 -0
  164. package/css/Tab.colorful.css +13 -0
  165. package/css/Tab.css +2 -0
  166. package/css/TabList.base.css +34 -0
  167. package/css/TabList.css +1 -0
  168. package/css/TextArea.base.css +85 -0
  169. package/css/TextArea.colorful.css +17 -0
  170. package/css/TextArea.composed.css +8 -0
  171. package/css/TextArea.css +3 -0
  172. package/css/Tooltip.base.css +6 -0
  173. package/css/Tooltip.css +1 -0
  174. package/css/Tree.base.css +74 -0
  175. package/css/Tree.composed.css +8 -0
  176. package/css/Tree.css +2 -0
  177. package/css/TreeChevron.base.css +86 -0
  178. package/css/TreeChevron.css +1 -0
  179. package/css/TreeItem.base.css +3 -0
  180. package/css/TreeItem.css +1 -0
  181. package/css/TreeItemDisplay.base.css +74 -0
  182. package/css/TreeItemDisplay.colorful.css +9 -0
  183. package/css/TreeItemDisplay.css +1 -0
  184. package/css/dark-mode.css +134 -0
  185. package/css/light-mode.css +134 -0
  186. package/css/sterling.css +37 -0
  187. package/index.d.ts +9 -13
  188. package/index.js +8 -12
  189. package/mediaQueries/prefersColorSchemeDark.d.ts +2 -0
  190. package/mediaQueries/prefersColorSchemeDark.js +10 -0
  191. package/{stores → mediaQueries}/prefersReducedMotion.d.ts +1 -0
  192. package/{stores → mediaQueries}/usingKeyboard.d.ts +1 -0
  193. package/package.json +121 -13
  194. package/Link.constants.d.ts +0 -1
  195. package/Link.constants.js +0 -1
  196. package/Link.types.d.ts +0 -4
  197. package/Link.types.js +0 -1
  198. package/theme/applyDarkTheme.d.ts +0 -7
  199. package/theme/applyDarkTheme.js +0 -11
  200. package/theme/applyLightTheme.d.ts +0 -7
  201. package/theme/applyLightTheme.js +0 -11
  202. package/theme/applyTheme.d.ts +0 -7
  203. package/theme/applyTheme.js +0 -20
  204. package/theme/colors.d.ts +0 -54
  205. package/theme/colors.js +0 -82
  206. package/theme/darkTheme.d.ts +0 -2
  207. package/theme/darkTheme.js +0 -142
  208. package/theme/lightTheme.d.ts +0 -2
  209. package/theme/lightTheme.js +0 -119
  210. package/theme/toggleDarkTheme.d.ts +0 -18
  211. package/theme/toggleDarkTheme.js +0 -53
  212. package/theme/types.d.ts +0 -21
  213. package/theme/types.js +0 -1
  214. /package/{stores → mediaQueries}/prefersReducedMotion.js +0 -0
  215. /package/{stores → mediaQueries}/usingKeyboard.js +0 -0
package/Link.svelte CHANGED
@@ -1,26 +1,26 @@
1
1
  <script>export let href;
2
2
  export let disabled = false;
3
- export let colorful = false;
4
- export let variant = "regular";
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
- linkRef?.blur();
10
+ linkRef?.blur();
8
11
  };
9
12
  export const click = () => {
10
- linkRef?.click();
13
+ linkRef?.click();
11
14
  };
12
15
  export const focus = (options) => {
13
- linkRef?.focus();
16
+ linkRef?.focus();
14
17
  };
15
18
  </script>
16
19
 
17
20
  <a
18
21
  bind:this={linkRef}
19
- class="sterling-link"
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
@@ -4,7 +4,6 @@ declare const __propDef: {
4
4
  [x: string]: any;
5
5
  href: string;
6
6
  disabled?: boolean | undefined;
7
- colorful?: boolean | undefined;
8
7
  variant?: string | undefined;
9
8
  blur?: (() => void) | undefined;
10
9
  click?: (() => void) | undefined;
package/List.svelte CHANGED
@@ -1,180 +1,192 @@
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 "./stores/usingKeyboard";
5
- export let colorful = false;
6
- export let composed = false;
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
- export let selectedValue = void 0;
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
- colorfulStore.set(colorful);
21
+ disabledStore.set(disabled);
18
22
  }
19
23
  $: {
20
- disabledStore.set(disabled);
24
+ horizontalStore.set(horizontal);
21
25
  }
22
26
  $: {
23
- horizontalStore.set(horizontal);
27
+ selectedValueStore.set(selectedValue);
24
28
  }
25
29
  $: {
26
- selectedValueStore.set(selectedValue);
27
- }
28
- $: {
29
- selectedValue = $selectedValueStore;
30
+ selectedValue = $selectedValueStore;
30
31
  }
32
+ // ----- Events ----- //
31
33
  const dispatch = createEventDispatcher();
32
34
  const raiseSelect = (value) => {
33
- dispatch("select", { value });
35
+ dispatch('select', { value });
34
36
  };
35
37
  $: {
36
- raiseSelect(selectedValue);
38
+ raiseSelect(selectedValue);
37
39
  }
40
+ // ----- Methods ----- //
38
41
  export const blur = () => {
39
- listRef?.blur();
42
+ listRef?.blur();
40
43
  };
41
44
  export const click = () => {
42
- listRef?.click();
45
+ listRef?.click();
43
46
  };
44
47
  export const focus = (options) => {
45
- listRef?.focus();
48
+ listRef?.focus();
46
49
  };
47
50
  export const scrollToSelectedItem = () => {
48
- const element = getSelectedItemElement();
49
- element?.scrollIntoView({ block: "nearest", inline: "nearest" });
51
+ const element = getSelectedItemElement();
52
+ element?.scrollIntoView({ block: 'nearest', inline: 'nearest' });
50
53
  };
54
+ // ----- Focus ----- //
55
+ // ----- Selection ----- //
51
56
  const isElementListItem = (candidate) => {
52
- return candidate && candidate.getAttribute("data-value") !== null && candidate.getAttribute("data-value") !== void 0 && candidate.getAttribute("role") === "listitem";
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
- if (isElementListItem(lastSelectedItemRef) && lastSelectedItemRef?.getAttribute("data-value") === selectedValue && lastSelectedItemRef?.closest('[role="list"]') === listRef) {
56
- return lastSelectedItemRef;
57
- } else {
58
- return listRef?.querySelector("[data-value][aria-selected=true]");
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
- selectedValueStore.set(value);
63
- lastSelectedItemRef = element;
64
- element.scrollIntoView({ block: "nearest", inline: "nearest" });
73
+ selectedValueStore.set(value);
74
+ lastSelectedItemRef = element;
75
+ element.scrollIntoView({ block: 'nearest', inline: 'nearest' });
65
76
  };
66
77
  export const selectFirstItem = () => {
67
- let candidate = listRef?.firstElementChild;
68
- while (candidate && !isElementListItem(candidate)) {
69
- candidate = candidate.nextElementSibling;
70
- }
71
- let candidateValue = candidate?.getAttribute("data-value");
72
- if (candidateValue && candidate) {
73
- selectItem(candidateValue, candidate);
74
- return true;
75
- }
76
- return false;
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
- let selectedItem = getSelectedItemElement();
80
- let candidate = selectedItem?.previousElementSibling;
81
- while (candidate && !isElementListItem(candidate)) {
82
- candidate = candidate.previousElementSibling;
83
- }
84
- let candidateValue = candidate?.getAttribute("data-value");
85
- if (candidateValue && candidate) {
86
- selectItem(candidateValue, candidate);
87
- return true;
88
- }
89
- return false;
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
- let selectedItem = getSelectedItemElement();
93
- let candidate = selectedItem?.nextElementSibling;
94
- while (candidate && !isElementListItem(candidate)) {
95
- candidate = candidate.nextElementSibling;
96
- }
97
- let candidateValue = candidate?.getAttribute("data-value");
98
- if (candidateValue && candidate) {
99
- selectItem(candidateValue, candidate);
100
- return true;
101
- }
102
- return false;
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
- let candidate = listRef?.lastElementChild;
106
- while (candidate && !isElementListItem(candidate)) {
107
- candidate = candidate.previousElementSibling;
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
- selectItem(candidateValue, candidate);
122
+ selectItem(candidateValue, candidate);
123
+ return true;
126
124
  }
127
- }
125
+ return false;
128
126
  };
129
- const onKeydown = (event) => {
130
- if (!disabled && !event.ctrlKey && !event.shiftKey && !event.altKey && !event.metaKey) {
131
- switch (event.key) {
132
- case "Home":
133
- selectFirstItem();
134
- event.preventDefault();
135
- event.stopPropagation();
136
- return false;
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
- event.preventDefault();
154
- event.stopPropagation();
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
- event.preventDefault();
161
- event.stopPropagation();
162
- return false;
163
- case "ArrowDown":
164
- if (!horizontal) {
165
- selectedValue !== void 0 ? selectNextItem() : selectFirstItem();
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
- colorful: colorfulStore,
175
- disabled: disabledStore,
176
- selectedValue: selectedValueStore,
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="sterling-list"
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 {composed} {disabled} {horizontal} {selectedValue} />
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
- colorful?: Readable<boolean>;
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
  };