@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.
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 +91 -187
  11. package/Dialog.svelte.d.ts +3 -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/Input.svelte CHANGED
@@ -1,47 +1,53 @@
1
- <script>import { idGenerator } from "./idGenerator";
1
+ <script>import { idGenerator } from './idGenerator';
2
+ import { usingKeyboard } from './mediaQueries/usingKeyboard';
3
+ // ----- Props ----- //
2
4
  export let disabled = false;
3
- export let id = void 0;
4
- export let value = "";
5
- export let colorful = false;
6
- export let composed = false;
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
- if ($$slots.default && id === void 0) {
10
- id = idGenerator.nextId("Input");
11
- }
12
+ if ($$slots.default && id === undefined) {
13
+ id = idGenerator.nextId('Input');
14
+ }
12
15
  }
16
+ // ----- Methods ----- //
13
17
  export const blur = () => {
14
- inputRef?.blur();
18
+ inputRef?.blur();
15
19
  };
16
20
  export const click = () => {
17
- inputRef?.click();
21
+ inputRef?.click();
18
22
  };
19
23
  export const focus = (options) => {
20
- inputRef?.focus();
24
+ inputRef?.focus();
21
25
  };
22
26
  export const select = () => {
23
- inputRef?.select();
27
+ inputRef?.select();
24
28
  };
25
29
  export const setSelectionRange = (start, end, direction) => {
26
- inputRef?.setSelectionRange(start, end, direction);
30
+ inputRef?.setSelectionRange(start, end, direction);
27
31
  };
28
32
  export const setRangeText = (replacement, start, end, selectionMode) => {
29
- if (start && end) {
30
- inputRef?.setRangeText(replacement, start, end, selectionMode);
31
- } else {
32
- inputRef?.setRangeText(replacement);
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 {composed} {disabled} {value} />
43
+ <label class={`sterling-input-label ${variant}`} for={id}>
44
+ <slot {disabled} {value} {variant} />
40
45
  </label>
41
46
  {/if}
42
- <div class="sterling-input" class:colorful class:composed class:disabled>
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
- colorful?: boolean | undefined;
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
  };
@@ -1 +1,2 @@
1
1
  export declare const LABEL_STATUSES: string[];
2
+ export declare const LABEL_VARIANTS: readonly ["regular", "container", "inline"];
@@ -1 +1,2 @@
1
1
  export const LABEL_STATUSES = ['none', 'info', 'success', 'warning', 'danger'];
2
+ export const LABEL_VARIANTS = ['regular', 'container', 'inline'];
package/Label.svelte CHANGED
@@ -1,88 +1,122 @@
1
- <script>import Tooltip from "./Tooltip.svelte";
2
- import { usingKeyboard } from "./stores/usingKeyboard";
3
- let htmlFor = void 0;
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
- export let text = void 0;
7
- export let message = void 0;
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
- export let requiredReason = "required";
10
- export let status = "none";
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
- let candidate = null;
16
- if (htmlFor) {
17
- candidate = labelRef?.querySelector(`[id="${htmlFor}"]`);
18
- }
19
- if (!candidate) {
20
- candidate = labelRef?.querySelector(
21
- 'a[href], audio[controls], button, details, div[contenteditable], form, input, select, textarea, video[controls], [tabindex]:not([tabindex="-1"])'
22
- );
23
- }
24
- targetRef = candidate;
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
- if (element) {
28
- return element.getAttribute("aria-disabled") === "true" || element?.matches(":disabled") || element?.disabled === true || element?.classList.contains("disabled");
29
- }
30
- return false;
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
- targetDisabled = isElementDisabled(targetRef);
60
+ targetDisabled = isElementDisabled(targetRef);
36
61
  }
37
62
  const mutationCallback = (mutations) => {
38
- let disabled = void 0;
39
- for (let i = 0; i < mutations.length; i++) {
40
- const mutation = mutations[i];
41
- if (mutation.type === "attributes") {
42
- if (mutation.attributeName === "aria-disabled" || mutation.attributeName === "disabled" || mutation.attributeName === "class") {
43
- if (isElementDisabled(targetRef)) {
44
- disabled = true;
45
- break;
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
- if (disabled !== void 0) {
52
- targetDisabled = disabled;
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
- mutationObserver.disconnect();
58
- if (targetRef) {
59
- mutationObserver.observe(targetRef, {
60
- attributes: true
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
- labelRef?.click();
96
+ labelRef?.click();
66
97
  };
67
98
  export const blur = () => {
68
- labelRef?.blur();
99
+ labelRef?.blur();
69
100
  };
70
101
  export const focus = (options) => {
71
- labelRef?.focus(options);
102
+ labelRef?.focus(options);
72
103
  };
104
+ // ----- Event Handlers ----- //
73
105
  const onClick = () => {
74
- if (forwardClick) {
75
- targetRef?.click();
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="sterling-label"
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 name="text" disabled={targetDisabled} for={htmlFor} {forwardClick} {text} {required}>
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 {};