@human-kit/ui 1.0.0-beta.7 → 1.0.0-beta.9

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 (203) hide show
  1. package/dist/FOCUS_STATE_CONTRACT.md +15 -4
  2. package/dist/FOCUS_STATE_REVIEW_TEMPLATE.md +8 -8
  3. package/dist/avatar/README.md +52 -0
  4. package/dist/avatar/count/avatar-count.svelte +56 -0
  5. package/dist/avatar/count/avatar-count.svelte.d.ts +4 -0
  6. package/dist/avatar/fallback/avatar-fallback.svelte +67 -0
  7. package/dist/avatar/fallback/avatar-fallback.svelte.d.ts +4 -0
  8. package/dist/avatar/group/avatar-group.svelte +65 -0
  9. package/dist/avatar/group/avatar-group.svelte.d.ts +4 -0
  10. package/dist/avatar/group/context.d.ts +15 -0
  11. package/dist/avatar/group/context.js +15 -0
  12. package/dist/avatar/image/avatar-image.svelte +104 -0
  13. package/dist/avatar/image/avatar-image.svelte.d.ts +4 -0
  14. package/dist/avatar/index.d.ts +22 -0
  15. package/dist/avatar/index.js +10 -0
  16. package/dist/avatar/index.parts.d.ts +5 -0
  17. package/dist/avatar/index.parts.js +5 -0
  18. package/dist/avatar/root/avatar-root.svelte +79 -0
  19. package/dist/avatar/root/avatar-root.svelte.d.ts +4 -0
  20. package/dist/avatar/root/context.d.ts +14 -0
  21. package/dist/avatar/root/context.js +15 -0
  22. package/dist/avatar/types.d.ts +84 -0
  23. package/dist/avatar/types.js +1 -0
  24. package/dist/breadcrumbs/README.md +65 -0
  25. package/dist/breadcrumbs/ellipsis/breadcrumbs-ellipsis.svelte +62 -0
  26. package/dist/breadcrumbs/ellipsis/breadcrumbs-ellipsis.svelte.d.ts +4 -0
  27. package/dist/breadcrumbs/index.d.ts +23 -0
  28. package/dist/breadcrumbs/index.js +10 -0
  29. package/dist/breadcrumbs/index.parts.d.ts +6 -0
  30. package/dist/breadcrumbs/index.parts.js +6 -0
  31. package/dist/breadcrumbs/item/breadcrumbs-item.svelte +42 -0
  32. package/dist/breadcrumbs/item/breadcrumbs-item.svelte.d.ts +4 -0
  33. package/dist/breadcrumbs/link/breadcrumbs-link.svelte +47 -0
  34. package/dist/breadcrumbs/link/breadcrumbs-link.svelte.d.ts +4 -0
  35. package/dist/breadcrumbs/list/breadcrumbs-list.svelte +31 -0
  36. package/dist/breadcrumbs/list/breadcrumbs-list.svelte.d.ts +4 -0
  37. package/dist/breadcrumbs/root/breadcrumbs-root.svelte +112 -0
  38. package/dist/breadcrumbs/root/breadcrumbs-root.svelte.d.ts +4 -0
  39. package/dist/breadcrumbs/root/context.d.ts +19 -0
  40. package/dist/breadcrumbs/root/context.js +15 -0
  41. package/dist/breadcrumbs/separator/breadcrumbs-separator.svelte +35 -0
  42. package/dist/breadcrumbs/separator/breadcrumbs-separator.svelte.d.ts +4 -0
  43. package/dist/breadcrumbs/types.d.ts +80 -0
  44. package/dist/breadcrumbs/types.js +1 -0
  45. package/dist/combobox/popover/combobox-popover.svelte +4 -56
  46. package/dist/dialog/root/dialog-root.svelte +15 -2
  47. package/dist/drawer/root/drawer-root.svelte +15 -2
  48. package/dist/index.d.ts +16 -0
  49. package/dist/index.js +15 -0
  50. package/dist/internal/localized-strings.d.ts +72 -0
  51. package/dist/internal/localized-strings.js +72 -0
  52. package/dist/internal/number-precision.d.ts +9 -0
  53. package/dist/internal/number-precision.js +27 -0
  54. package/dist/menu/root/focus-state.d.ts +2 -2
  55. package/dist/menu/root/focus-state.js +8 -32
  56. package/dist/menu/root/menu-state.svelte.js +5 -1
  57. package/dist/numberfield/root/number-utils.js +1 -20
  58. package/dist/popover/root/focus-state.d.ts +2 -2
  59. package/dist/popover/root/focus-state.js +7 -34
  60. package/dist/primitives/aria-hide-outside.d.ts +13 -0
  61. package/dist/primitives/aria-hide-outside.js +7 -1
  62. package/dist/primitives/contain-wheel.d.ts +9 -0
  63. package/dist/primitives/contain-wheel.js +41 -0
  64. package/dist/primitives/floating.d.ts +6 -0
  65. package/dist/primitives/floating.js +26 -5
  66. package/dist/primitives/focus-trap.d.ts +2 -0
  67. package/dist/primitives/focus-trap.js +7 -1
  68. package/dist/primitives/keyboard-navigation.d.ts +6 -0
  69. package/dist/primitives/keyboard-navigation.js +2 -1
  70. package/dist/primitives/presence.svelte.js +6 -1
  71. package/dist/primitives/trigger-focus-state.d.ts +29 -0
  72. package/dist/primitives/trigger-focus-state.js +57 -0
  73. package/dist/progress/README.md +54 -0
  74. package/dist/progress/index.d.ts +21 -0
  75. package/dist/progress/index.js +9 -0
  76. package/dist/progress/index.parts.d.ts +5 -0
  77. package/dist/progress/index.parts.js +5 -0
  78. package/dist/progress/indicator/progress-indicator.svelte +37 -0
  79. package/dist/progress/indicator/progress-indicator.svelte.d.ts +4 -0
  80. package/dist/progress/label/progress-label.svelte +34 -0
  81. package/dist/progress/label/progress-label.svelte.d.ts +4 -0
  82. package/dist/progress/root/context.d.ts +26 -0
  83. package/dist/progress/root/context.js +15 -0
  84. package/dist/progress/root/progress-root.svelte +136 -0
  85. package/dist/progress/root/progress-root.svelte.d.ts +4 -0
  86. package/dist/progress/root/progress-utils.d.ts +12 -0
  87. package/dist/progress/root/progress-utils.js +41 -0
  88. package/dist/progress/track/progress-track.svelte +27 -0
  89. package/dist/progress/track/progress-track.svelte.d.ts +4 -0
  90. package/dist/progress/types.d.ts +81 -0
  91. package/dist/progress/types.js +1 -0
  92. package/dist/progress/value/progress-value.svelte +36 -0
  93. package/dist/progress/value/progress-value.svelte.d.ts +4 -0
  94. package/dist/select/README.md +129 -0
  95. package/dist/select/index.d.ts +30 -0
  96. package/dist/select/index.js +16 -0
  97. package/dist/select/index.parts.d.ts +8 -0
  98. package/dist/select/index.parts.js +9 -0
  99. package/dist/select/item/select-item.svelte +68 -0
  100. package/dist/select/item/select-item.svelte.d.ts +10 -0
  101. package/dist/select/item-indicator/select-item-indicator.svelte +55 -0
  102. package/dist/select/item-indicator/select-item-indicator.svelte.d.ts +4 -0
  103. package/dist/select/label/select-label.svelte +46 -0
  104. package/dist/select/label/select-label.svelte.d.ts +4 -0
  105. package/dist/select/list/select-list.svelte +241 -0
  106. package/dist/select/list/select-list.svelte.d.ts +62 -0
  107. package/dist/select/popover/select-popover.svelte +80 -0
  108. package/dist/select/popover/select-popover.svelte.d.ts +9 -0
  109. package/dist/select/root/context.d.ts +106 -0
  110. package/dist/select/root/context.js +22 -0
  111. package/dist/select/root/select-root.svelte +544 -0
  112. package/dist/select/root/select-root.svelte.d.ts +25 -0
  113. package/dist/select/trigger/select-trigger.svelte +192 -0
  114. package/dist/select/trigger/select-trigger.svelte.d.ts +4 -0
  115. package/dist/select/types.d.ts +133 -0
  116. package/dist/select/types.js +1 -0
  117. package/dist/select/value/select-value.svelte +61 -0
  118. package/dist/select/value/select-value.svelte.d.ts +4 -0
  119. package/dist/separator/README.md +35 -0
  120. package/dist/separator/index.d.ts +7 -0
  121. package/dist/separator/index.js +3 -0
  122. package/dist/separator/separator.svelte +254 -0
  123. package/dist/separator/separator.svelte.d.ts +45 -0
  124. package/dist/separator/types.d.ts +1 -0
  125. package/dist/separator/types.js +1 -0
  126. package/dist/slider/README.md +61 -0
  127. package/dist/slider/fill/slider-fill.svelte +40 -0
  128. package/dist/slider/fill/slider-fill.svelte.d.ts +4 -0
  129. package/dist/slider/index.d.ts +9 -0
  130. package/dist/slider/index.js +8 -0
  131. package/dist/slider/index.parts.d.ts +6 -0
  132. package/dist/slider/index.parts.js +6 -0
  133. package/dist/slider/label/slider-label.svelte +44 -0
  134. package/dist/slider/label/slider-label.svelte.d.ts +4 -0
  135. package/dist/slider/output/slider-output.svelte +46 -0
  136. package/dist/slider/output/slider-output.svelte.d.ts +4 -0
  137. package/dist/slider/root/context.d.ts +106 -0
  138. package/dist/slider/root/context.js +15 -0
  139. package/dist/slider/root/slider-root.svelte +545 -0
  140. package/dist/slider/root/slider-root.svelte.d.ts +4 -0
  141. package/dist/slider/root/slider-utils.d.ts +57 -0
  142. package/dist/slider/root/slider-utils.js +88 -0
  143. package/dist/slider/thumb/slider-thumb.svelte +276 -0
  144. package/dist/slider/thumb/slider-thumb.svelte.d.ts +4 -0
  145. package/dist/slider/track/slider-track.svelte +60 -0
  146. package/dist/slider/track/slider-track.svelte.d.ts +4 -0
  147. package/dist/slider/types.d.ts +144 -0
  148. package/dist/slider/types.js +1 -0
  149. package/dist/toast/README.md +75 -0
  150. package/dist/toast/action/toast-action.svelte +42 -0
  151. package/dist/toast/action/toast-action.svelte.d.ts +4 -0
  152. package/dist/toast/close/toast-close.svelte +41 -0
  153. package/dist/toast/close/toast-close.svelte.d.ts +4 -0
  154. package/dist/toast/content/toast-content.svelte +24 -0
  155. package/dist/toast/content/toast-content.svelte.d.ts +4 -0
  156. package/dist/toast/description/toast-description.svelte +41 -0
  157. package/dist/toast/description/toast-description.svelte.d.ts +4 -0
  158. package/dist/toast/index.d.ts +34 -0
  159. package/dist/toast/index.js +15 -0
  160. package/dist/toast/index.parts.d.ts +9 -0
  161. package/dist/toast/index.parts.js +9 -0
  162. package/dist/toast/positioner/toast-positioner.svelte +75 -0
  163. package/dist/toast/positioner/toast-positioner.svelte.d.ts +4 -0
  164. package/dist/toast/provider/context.d.ts +36 -0
  165. package/dist/toast/provider/context.js +22 -0
  166. package/dist/toast/provider/toast-manager.svelte.d.ts +113 -0
  167. package/dist/toast/provider/toast-manager.svelte.js +210 -0
  168. package/dist/toast/provider/toast-provider.svelte +98 -0
  169. package/dist/toast/provider/toast-provider.svelte.d.ts +4 -0
  170. package/dist/toast/root/context.d.ts +18 -0
  171. package/dist/toast/root/context.js +15 -0
  172. package/dist/toast/root/toast-root.svelte +296 -0
  173. package/dist/toast/root/toast-root.svelte.d.ts +4 -0
  174. package/dist/toast/title/toast-title.svelte +38 -0
  175. package/dist/toast/title/toast-title.svelte.d.ts +4 -0
  176. package/dist/toast/types.d.ts +100 -0
  177. package/dist/toast/types.js +1 -0
  178. package/dist/toast/viewport/toast-viewport.svelte +389 -0
  179. package/dist/toast/viewport/toast-viewport.svelte.d.ts +4 -0
  180. package/dist/tooltip/README.md +53 -0
  181. package/dist/tooltip/arrow/tooltip-arrow.svelte +36 -0
  182. package/dist/tooltip/arrow/tooltip-arrow.svelte.d.ts +4 -0
  183. package/dist/tooltip/content/tooltip-content.svelte +148 -0
  184. package/dist/tooltip/content/tooltip-content.svelte.d.ts +4 -0
  185. package/dist/tooltip/index.d.ts +8 -0
  186. package/dist/tooltip/index.js +7 -0
  187. package/dist/tooltip/index.parts.d.ts +5 -0
  188. package/dist/tooltip/index.parts.js +5 -0
  189. package/dist/tooltip/provider/tooltip-provider.svelte +36 -0
  190. package/dist/tooltip/provider/tooltip-provider.svelte.d.ts +4 -0
  191. package/dist/tooltip/root/context.d.ts +46 -0
  192. package/dist/tooltip/root/context.js +22 -0
  193. package/dist/tooltip/root/safe-polygon.d.ts +26 -0
  194. package/dist/tooltip/root/safe-polygon.js +66 -0
  195. package/dist/tooltip/root/tooltip-group.d.ts +26 -0
  196. package/dist/tooltip/root/tooltip-group.js +41 -0
  197. package/dist/tooltip/root/tooltip-root.svelte +454 -0
  198. package/dist/tooltip/root/tooltip-root.svelte.d.ts +4 -0
  199. package/dist/tooltip/trigger/tooltip-trigger.svelte +52 -0
  200. package/dist/tooltip/trigger/tooltip-trigger.svelte.d.ts +4 -0
  201. package/dist/tooltip/types.d.ts +105 -0
  202. package/dist/tooltip/types.js +1 -0
  203. package/package.json +41 -1
@@ -0,0 +1,192 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from 'svelte';
3
+ import { untrack } from 'svelte';
4
+ import { ButtonRoot } from '../../button/index.js';
5
+ import {
6
+ shouldShowFocusVisible,
7
+ trackInteractionModality
8
+ } from '../../primitives/input-modality';
9
+ import { watchFocusVisible } from '../../primitives/focus-visible.svelte';
10
+ import { useSelectContext } from '../root/context';
11
+ import type { SelectTriggerProps, SelectTriggerRenderState } from '../types';
12
+
13
+ /**
14
+ * Select.Trigger — the button that opens the list and shows the value.
15
+ *
16
+ * It carries `role="combobox"` with `aria-haspopup="listbox"`, the same as a native select
17
+ * in the accessibility tree. Its name comes from `Select.Label`
18
+ * and from `Select.Value` together, thus a screen reader announces the field and the
19
+ * selection in one go.
20
+ */
21
+ let {
22
+ children,
23
+ class: className = '',
24
+ element = $bindable<HTMLButtonElement | null>(null),
25
+ onclick: onClickExternal,
26
+ onkeydown: onKeyDownExternal,
27
+ onfocus: onFocusExternal,
28
+ onblur: onBlurExternal,
29
+ ...restProps
30
+ }: SelectTriggerProps = $props();
31
+
32
+ const ctx = useSelectContext('Select.Trigger');
33
+
34
+ let buttonRef: HTMLButtonElement | null = $state(null);
35
+ let focused = $state(false);
36
+
37
+ // The ring must come back when a key press follows a pointer press, and only the modality
38
+ // changes there: no focus event fires to re-read it.
39
+ watchFocusVisible({
40
+ isFocused: () => focused,
41
+ element: () => buttonRef,
42
+ set: (visible) => ctx.setFocusVisible(visible)
43
+ });
44
+
45
+ const hasSelection = $derived(ctx.selectedKeys.size > 0);
46
+ const renderState = $derived<SelectTriggerRenderState>({
47
+ open: ctx.isOpen,
48
+ placeholder: !hasSelection,
49
+ disabled: ctx.isDisabled
50
+ });
51
+
52
+ // The name is the label and the value, in that order: "Fruit, Apple". A caller's
53
+ // `aria-labelledby` replaces the label. A caller's `aria-label` sits on this element, and the
54
+ // list names the trigger itself, so the algorithm reads that text for it. Without any
55
+ // label, the content of the button is the name, and `Select.Value` is in it.
56
+ const labelSource = $derived(
57
+ ctx.ariaLabelledBy ?? ctx.labelId ?? (ctx.ariaLabel ? ctx.triggerId : null)
58
+ );
59
+ const ariaLabelledBy = $derived(
60
+ labelSource ? `${labelSource} ${ctx.valueId ?? ctx.triggerId}` : undefined
61
+ );
62
+
63
+ $effect(() => {
64
+ const node = buttonRef;
65
+ element = node;
66
+ if (node) {
67
+ untrack(() => ctx.setTriggerRef(node));
68
+ }
69
+ return () => {
70
+ untrack(() => {
71
+ if (node && ctx.triggerRef === node) {
72
+ ctx.setTriggerRef(null);
73
+ }
74
+ });
75
+ };
76
+ });
77
+
78
+ function isPrintableKey(event: KeyboardEvent) {
79
+ return (
80
+ event.key.length === 1 &&
81
+ event.key !== ' ' &&
82
+ !event.ctrlKey &&
83
+ !event.metaKey &&
84
+ !event.altKey
85
+ );
86
+ }
87
+
88
+ function handleClick(event: MouseEvent & { currentTarget: EventTarget & HTMLButtonElement }) {
89
+ onClickExternal?.(event);
90
+ if (event.defaultPrevented) return;
91
+ if (ctx.isDisabled || ctx.isReadOnly) return;
92
+ ctx.toggle('trigger-press', event);
93
+ }
94
+
95
+ function handleKeyDown(
96
+ event: KeyboardEvent & { currentTarget: EventTarget & HTMLButtonElement }
97
+ ) {
98
+ onKeyDownExternal?.(event);
99
+ if (event.defaultPrevented) return;
100
+ if (ctx.isDisabled) return;
101
+ if (event.isComposing || event.keyCode === 229) return;
102
+ trackInteractionModality(event, buttonRef);
103
+ if (ctx.isReadOnly || ctx.isOpen) return;
104
+
105
+ // The APG select-only combobox: every one of these opens the list, and the focus goes
106
+ // to the selection, or to the first or the last option when there is none. Enter and
107
+ // Space are handled here, and not through the click of the button, so the list is
108
+ // open before the key comes up and the option under the focus does not take it.
109
+ switch (event.key) {
110
+ case 'ArrowDown':
111
+ case 'Enter':
112
+ case ' ':
113
+ event.preventDefault();
114
+ ctx.open('trigger-press', event, 'selected');
115
+ return;
116
+ case 'ArrowUp':
117
+ event.preventDefault();
118
+ ctx.open('trigger-press', event, hasSelection ? 'selected' : 'last');
119
+ return;
120
+ case 'Home':
121
+ event.preventDefault();
122
+ ctx.open('trigger-press', event, 'first');
123
+ return;
124
+ case 'End':
125
+ event.preventDefault();
126
+ ctx.open('trigger-press', event, 'last');
127
+ return;
128
+ }
129
+
130
+ if (isPrintableKey(event)) {
131
+ event.preventDefault();
132
+ ctx.openWithTypeahead(event.key, event);
133
+ }
134
+ }
135
+
136
+ function handleFocus(event: FocusEvent & { currentTarget: EventTarget & HTMLButtonElement }) {
137
+ focused = true;
138
+ ctx.setFocusWithin(true);
139
+ ctx.setFocusVisible(shouldShowFocusVisible(buttonRef));
140
+ onFocusExternal?.(event);
141
+ }
142
+
143
+ function handleBlur(event: FocusEvent & { currentTarget: EventTarget & HTMLButtonElement }) {
144
+ focused = false;
145
+ // The list takes the focus while the popover is open, and that is still inside the
146
+ // select. The check waits for the new focus to land.
147
+ queueMicrotask(() => {
148
+ const active = document.activeElement;
149
+ const inTrigger = !!buttonRef && (active === buttonRef || buttonRef.contains(active));
150
+ const inList =
151
+ !!ctx.listboxRef && (active === ctx.listboxRef || ctx.listboxRef.contains(active));
152
+ if (!inTrigger && !inList) {
153
+ ctx.setFocusWithin(false);
154
+ }
155
+ });
156
+ onBlurExternal?.(event);
157
+ }
158
+ </script>
159
+
160
+ <ButtonRoot
161
+ {...restProps}
162
+ bind:element={buttonRef}
163
+ id={ctx.triggerId}
164
+ class={className}
165
+ type="button"
166
+ role="combobox"
167
+ disabled={ctx.isDisabled}
168
+ pressed={ctx.isOpen || undefined}
169
+ aria-haspopup="listbox"
170
+ aria-expanded={ctx.isOpen}
171
+ aria-controls={ctx.isOpen ? ctx.listboxId : undefined}
172
+ aria-label={ctx.ariaLabel}
173
+ aria-labelledby={ariaLabelledBy}
174
+ aria-describedby={ctx.ariaDescribedBy}
175
+ aria-required={ctx.isRequired || undefined}
176
+ aria-readonly={ctx.isReadOnly || undefined}
177
+ aria-invalid={ctx.isInvalid || undefined}
178
+ data-select-trigger="true"
179
+ data-state={ctx.isOpen ? 'open' : 'closed'}
180
+ data-placeholder={hasSelection ? undefined : 'true'}
181
+ data-readonly={ctx.isReadOnly || undefined}
182
+ data-required={ctx.isRequired || undefined}
183
+ data-invalid={ctx.isInvalid || undefined}
184
+ onclick={handleClick}
185
+ onkeydown={handleKeyDown}
186
+ onfocus={handleFocus}
187
+ onblur={handleBlur}
188
+ >
189
+ {#if children}
190
+ {@render (children as Snippet<[SelectTriggerRenderState]>)(renderState)}
191
+ {/if}
192
+ </ButtonRoot>
@@ -0,0 +1,4 @@
1
+ import type { SelectTriggerProps } from '../types';
2
+ declare const SelectTrigger: import("svelte").Component<SelectTriggerProps, {}, "element">;
3
+ type SelectTrigger = ReturnType<typeof SelectTrigger>;
4
+ export default SelectTrigger;
@@ -0,0 +1,133 @@
1
+ import type { Snippet } from 'svelte';
2
+ import type { FullAutoFill, HTMLAttributes, HTMLButtonAttributes, HTMLLabelAttributes } from 'svelte/elements';
3
+ import type { SelectContext, SelectOpenChangeDetails, SelectKey } from './root/context';
4
+ export type { SelectOpenChangeDetails, SelectKey };
5
+ export type SelectRootProps<T extends object = object> = {
6
+ /** A stable id, from which the component makes its internal ARIA ids. Give one on a server. */
7
+ id?: string;
8
+ /**
9
+ * The selected key or keys: one key in the single mode, and an array in the multiple mode. You
10
+ * can bind it with `bind:value`.
11
+ */
12
+ value?: SelectKey | null | SelectKey[];
13
+ /** The selection at the start, for when you give no `value`. */
14
+ defaultValue?: SelectKey | null | SelectKey[];
15
+ /**
16
+ * Give your own code full control of the selection. The component stops to write back to
17
+ * `value`, and it reports only through `onChange`. Thus the parent can refuse a change: the
18
+ * parent does not send the new value down. The default is off, because `bind:value` is the usual
19
+ * case and it needs the write-back.
20
+ */
21
+ controlledValue?: boolean;
22
+ /** The component calls it when the selection changes. */
23
+ onChange?: (value: SelectKey | null | SelectKey[]) => void;
24
+ /** The open state of the popover. You can bind it with `bind:open`. */
25
+ open?: boolean;
26
+ /** The open state at the start, for when you give no `open`. */
27
+ defaultOpen?: boolean;
28
+ /** Give your own code full control of the open state. Read `controlledValue`. */
29
+ controlledOpen?: boolean;
30
+ /** The component calls it when the open state changes. `details.cancel()` refuses the change. */
31
+ onOpenChange?: (open: boolean, details: SelectOpenChangeDetails) => void;
32
+ /** The selection mode: 'single' permits one key, and 'multiple' permits more than one. */
33
+ selectionMode?: 'single' | 'multiple';
34
+ /**
35
+ * Closes the popover after a selection. The default is true in the single mode, and false in the
36
+ * multiple mode.
37
+ */
38
+ closeOnSelect?: boolean;
39
+ /** The keys of the options that the user cannot select. */
40
+ disabledKeys?: Iterable<SelectKey>;
41
+ /**
42
+ * At the last option, the arrow keys move the focus to the first option, and at the first
43
+ * option, to the last one.
44
+ */
45
+ loop?: boolean;
46
+ /** Disables the select. The trigger is disabled natively. */
47
+ disabled?: boolean;
48
+ /** Keeps the trigger in the tab order, but the popover does not open and the value does not change. */
49
+ readonly?: boolean;
50
+ /** Tells a form that it must have a value. The hidden control gets the native `required`. */
51
+ required?: boolean;
52
+ /** Marks the value as invalid. The trigger gets `aria-invalid`. */
53
+ invalid?: boolean;
54
+ /** The name of the hidden form control. Without it, the form does not send the value. */
55
+ name?: string;
56
+ /** The id of the form that the hidden control belongs to, when the select is outside it. */
57
+ form?: string;
58
+ /** The `autocomplete` of the hidden form control, for the browser autofill. */
59
+ autocomplete?: FullAutoFill | null;
60
+ /**
61
+ * The array of the items. The component reads the text of a selected key from it. Thus the
62
+ * trigger shows the text while the popover is closed and the options are not in the DOM.
63
+ *
64
+ * Each item needs a key in `id` or `value`, and a text in `textValue`, `label` or `name`.
65
+ */
66
+ items?: T[];
67
+ /** The text of the trigger while nothing is selected. */
68
+ placeholder?: string;
69
+ /** The accessible name of the select, for when there is no `Select.Label`. */
70
+ 'aria-label'?: string;
71
+ /** The id of the element that gives the select its name, in place of `Select.Label`. */
72
+ 'aria-labelledby'?: string;
73
+ /** The id of the element that describes the select, for example an error message. */
74
+ 'aria-describedby'?: string;
75
+ /** The content: the label, the trigger and the popover. */
76
+ children?: Snippet;
77
+ /** The CSS class names of the root element. */
78
+ class?: string;
79
+ /** A bindable reference to the root element. */
80
+ element?: HTMLDivElement | null;
81
+ /** A bindable reference to the context, for a composition of your own. */
82
+ context?: SelectContext;
83
+ } & Omit<HTMLAttributes<HTMLDivElement>, 'class' | 'children' | 'id' | 'aria-label' | 'aria-labelledby' | 'aria-describedby' | 'onchange' | 'placeholder' | 'autocomplete'>;
84
+ export type SelectTriggerRenderState = {
85
+ /** Whether the popover is open. */
86
+ open: boolean;
87
+ /** Whether nothing is selected. */
88
+ placeholder: boolean;
89
+ /** Whether the select is disabled. */
90
+ disabled: boolean;
91
+ };
92
+ export type SelectTriggerProps = Omit<HTMLButtonAttributes, 'type' | 'class' | 'children' | 'disabled' | 'role' | 'aria-haspopup' | 'aria-expanded' | 'aria-controls' | 'aria-labelledby' | 'aria-required' | 'aria-readonly' | 'aria-invalid' | 'aria-describedby'> & {
93
+ /**
94
+ * The content. As a snippet with one argument, it receives the render state: `open`,
95
+ * `placeholder` and `disabled`. Put a `Select.Value` inside it.
96
+ */
97
+ children?: Snippet<[SelectTriggerRenderState]> | Snippet;
98
+ /** The CSS class names of the trigger. */
99
+ class?: string;
100
+ /** A bindable reference to the button element. */
101
+ element?: HTMLButtonElement | null;
102
+ };
103
+ export type SelectValueRenderState = {
104
+ /** The selected key, or the selected keys in the multiple mode. */
105
+ value: SelectKey | null | SelectKey[];
106
+ /** The text of the selection, or the placeholder while nothing is selected. */
107
+ label: string;
108
+ /** Whether the component shows the placeholder. */
109
+ placeholder: boolean;
110
+ };
111
+ export type SelectValueProps = Omit<HTMLAttributes<HTMLSpanElement>, 'class' | 'children'> & {
112
+ /**
113
+ * The content. As a snippet with one argument, it receives the render state: `value`, `label` and
114
+ * `placeholder`. Without it, the component shows the text of the selection.
115
+ */
116
+ children?: Snippet<[SelectValueRenderState]>;
117
+ /** The text while nothing is selected. It replaces the placeholder of the root. */
118
+ placeholder?: string;
119
+ /** The CSS class names of the element. */
120
+ class?: string;
121
+ };
122
+ export type SelectLabelProps = Omit<HTMLLabelAttributes, 'class' | 'for'> & {
123
+ /** The CSS class names of the label. */
124
+ class?: string;
125
+ };
126
+ export type SelectItemIndicatorProps = Omit<HTMLAttributes<HTMLSpanElement>, 'class' | 'children'> & {
127
+ /** The content while the option is selected. The default is a check mark icon. */
128
+ children?: Snippet;
129
+ /** Keeps the indicator in the DOM, for each selection state. */
130
+ forceMount?: boolean;
131
+ /** The CSS class names of the element. */
132
+ class?: string;
133
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,61 @@
1
+ <script lang="ts">
2
+ import { readable } from 'svelte/store';
3
+ import { getLocaleContext } from '../../locale-provider/context';
4
+ import { useSelectContext } from '../root/context';
5
+ import type { SelectValueProps, SelectValueRenderState } from '../types';
6
+
7
+ /**
8
+ * Select.Value — the text of the selection, inside the trigger.
9
+ *
10
+ * It registers its id with the root, and the trigger puts that id in its `aria-labelledby`
11
+ * after the label. Thus the value is part of the name of the field.
12
+ */
13
+ let {
14
+ children,
15
+ placeholder,
16
+ class: className = '',
17
+ id: idProp,
18
+ ...restProps
19
+ }: SelectValueProps = $props();
20
+
21
+ const ctx = useSelectContext('Select.Value');
22
+ const localeStore = getLocaleContext()?.locale ?? readable<string | undefined>(undefined);
23
+ const id = $derived(idProp ?? `select-value-${ctx.instanceId}`);
24
+
25
+ $effect(() => ctx.registerValue(id));
26
+
27
+ const selectedKeys = $derived(Array.from(ctx.selectedKeys));
28
+ const hasSelection = $derived(selectedKeys.length > 0);
29
+ const resolvedPlaceholder = $derived(placeholder ?? ctx.placeholder);
30
+ // The texts of a multiple selection are joined by the locale, not by a comma written here: a
31
+ // list separator is not the same in every language.
32
+ const listFormat = $derived(
33
+ typeof Intl.ListFormat === 'function'
34
+ ? new Intl.ListFormat($localeStore, { type: 'unit', style: 'short' })
35
+ : null
36
+ );
37
+ const label = $derived.by(() => {
38
+ if (!hasSelection) return resolvedPlaceholder;
39
+ const texts = selectedKeys.map((key) => ctx.getLabel(key));
40
+ return listFormat ? listFormat.format(texts) : texts.join(', ');
41
+ });
42
+ const renderState = $derived<SelectValueRenderState>({
43
+ value: ctx.selectionMode === 'single' ? (selectedKeys[0] ?? null) : selectedKeys,
44
+ label,
45
+ placeholder: !hasSelection
46
+ });
47
+ </script>
48
+
49
+ <span
50
+ {...restProps}
51
+ {id}
52
+ class={className}
53
+ data-select-value="true"
54
+ data-placeholder={hasSelection ? undefined : 'true'}
55
+ >
56
+ {#if children}
57
+ {@render children(renderState)}
58
+ {:else}
59
+ {label}
60
+ {/if}
61
+ </span>
@@ -0,0 +1,4 @@
1
+ import type { SelectValueProps } from '../types';
2
+ declare const SelectValue: import("svelte").Component<SelectValueProps, {}, "">;
3
+ type SelectValue = ReturnType<typeof SelectValue>;
4
+ export default SelectValue;
@@ -0,0 +1,35 @@
1
+ # Separator
2
+
3
+ ## Description
4
+
5
+ `Separator` is a line between two groups of content. A screen reader reads it as a break, the same as a native `<hr>`. It has no size of its own: give it a border or a background, and a width or a height. With a `value`, it is a window splitter the keyboard and the pointer move.
6
+
7
+ ## Anatomy
8
+
9
+ - `Separator`
10
+
11
+ ```svelte
12
+ <Separator class="h-px w-full bg-neutral-200" />
13
+ <Separator orientation="vertical" class="h-6 w-px bg-neutral-200" />
14
+ ```
15
+
16
+ ## Usage guidelines
17
+
18
+ - Use `orientation="vertical"` for a line between two items side by side, such as in a toolbar.
19
+ - Use `decorative` for a line that repeats a break the content already makes, such as a border between two sections with headings. A screen reader then skips it.
20
+ - Give the line a size with CSS. `data-orientation` is on the element for your styles.
21
+ - Give `value` with `bind:value` for a window splitter, and size the pane before it from the value. Name it with `aria-label`, and point `aria-controls` at the pane.
22
+
23
+ ## API reference
24
+
25
+ - `Separator`
26
+ - `orientation?: 'horizontal' | 'vertical'` (`'horizontal'`)
27
+ - `decorative?: boolean` (`false`)
28
+ - `value?: number` (bindable), `min?: number` (`0`), `max?: number` (`100`), `step?: number` (`1`), `largeStep?: number` (`10`), `onValueChange?: (value: number) => void`, `aria-controls?: string`, `disabled?: boolean`
29
+ - `element?: HTMLDivElement | null` (bindable)
30
+
31
+ ## Accessibility
32
+
33
+ - The element is `role="separator"`. A vertical one has `aria-orientation="vertical"`: a separator is horizontal unless it says otherwise.
34
+ - `decorative` makes it `role="none"`, which a screen reader skips.
35
+ - A plain separator is not focusable. A splitter is a tab stop with `aria-valuenow`, `aria-valuemin`, `aria-valuemax` and a name. The arrows of its axis move it by `step`, or by `largeStep` with `Shift`. `Home` and `End` send it to the ends, and `Enter` folds and unfolds the pane. The horizontal arrows flip on a right-to-left page.
@@ -0,0 +1,7 @@
1
+ import type { ComponentProps } from 'svelte';
2
+ import type SeparatorComponent from './separator.svelte';
3
+ import Separator from './separator.svelte';
4
+ export type SeparatorProps = ComponentProps<typeof SeparatorComponent>;
5
+ export type { SeparatorOrientation } from './types.js';
6
+ export { Separator };
7
+ export default Separator;
@@ -0,0 +1,3 @@
1
+ import Separator from './separator.svelte';
2
+ export { Separator };
3
+ export default Separator;