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

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 (167) 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 +14 -0
  49. package/dist/index.js +13 -0
  50. package/dist/internal/localized-strings.d.ts +48 -0
  51. package/dist/internal/localized-strings.js +48 -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/contain-wheel.d.ts +9 -0
  61. package/dist/primitives/contain-wheel.js +41 -0
  62. package/dist/primitives/floating.d.ts +6 -0
  63. package/dist/primitives/floating.js +26 -5
  64. package/dist/primitives/keyboard-navigation.d.ts +6 -0
  65. package/dist/primitives/keyboard-navigation.js +2 -1
  66. package/dist/primitives/trigger-focus-state.d.ts +29 -0
  67. package/dist/primitives/trigger-focus-state.js +57 -0
  68. package/dist/progress/README.md +54 -0
  69. package/dist/progress/index.d.ts +21 -0
  70. package/dist/progress/index.js +9 -0
  71. package/dist/progress/index.parts.d.ts +5 -0
  72. package/dist/progress/index.parts.js +5 -0
  73. package/dist/progress/indicator/progress-indicator.svelte +37 -0
  74. package/dist/progress/indicator/progress-indicator.svelte.d.ts +4 -0
  75. package/dist/progress/label/progress-label.svelte +34 -0
  76. package/dist/progress/label/progress-label.svelte.d.ts +4 -0
  77. package/dist/progress/root/context.d.ts +26 -0
  78. package/dist/progress/root/context.js +15 -0
  79. package/dist/progress/root/progress-root.svelte +136 -0
  80. package/dist/progress/root/progress-root.svelte.d.ts +4 -0
  81. package/dist/progress/root/progress-utils.d.ts +12 -0
  82. package/dist/progress/root/progress-utils.js +41 -0
  83. package/dist/progress/track/progress-track.svelte +27 -0
  84. package/dist/progress/track/progress-track.svelte.d.ts +4 -0
  85. package/dist/progress/types.d.ts +81 -0
  86. package/dist/progress/types.js +1 -0
  87. package/dist/progress/value/progress-value.svelte +36 -0
  88. package/dist/progress/value/progress-value.svelte.d.ts +4 -0
  89. package/dist/select/README.md +129 -0
  90. package/dist/select/index.d.ts +30 -0
  91. package/dist/select/index.js +16 -0
  92. package/dist/select/index.parts.d.ts +8 -0
  93. package/dist/select/index.parts.js +9 -0
  94. package/dist/select/item/select-item.svelte +68 -0
  95. package/dist/select/item/select-item.svelte.d.ts +10 -0
  96. package/dist/select/item-indicator/select-item-indicator.svelte +55 -0
  97. package/dist/select/item-indicator/select-item-indicator.svelte.d.ts +4 -0
  98. package/dist/select/label/select-label.svelte +46 -0
  99. package/dist/select/label/select-label.svelte.d.ts +4 -0
  100. package/dist/select/list/select-list.svelte +241 -0
  101. package/dist/select/list/select-list.svelte.d.ts +62 -0
  102. package/dist/select/popover/select-popover.svelte +80 -0
  103. package/dist/select/popover/select-popover.svelte.d.ts +9 -0
  104. package/dist/select/root/context.d.ts +106 -0
  105. package/dist/select/root/context.js +22 -0
  106. package/dist/select/root/select-root.svelte +544 -0
  107. package/dist/select/root/select-root.svelte.d.ts +25 -0
  108. package/dist/select/trigger/select-trigger.svelte +192 -0
  109. package/dist/select/trigger/select-trigger.svelte.d.ts +4 -0
  110. package/dist/select/types.d.ts +133 -0
  111. package/dist/select/types.js +1 -0
  112. package/dist/select/value/select-value.svelte +61 -0
  113. package/dist/select/value/select-value.svelte.d.ts +4 -0
  114. package/dist/separator/README.md +35 -0
  115. package/dist/separator/index.d.ts +7 -0
  116. package/dist/separator/index.js +3 -0
  117. package/dist/separator/separator.svelte +254 -0
  118. package/dist/separator/separator.svelte.d.ts +45 -0
  119. package/dist/separator/types.d.ts +1 -0
  120. package/dist/separator/types.js +1 -0
  121. package/dist/slider/README.md +61 -0
  122. package/dist/slider/fill/slider-fill.svelte +40 -0
  123. package/dist/slider/fill/slider-fill.svelte.d.ts +4 -0
  124. package/dist/slider/index.d.ts +9 -0
  125. package/dist/slider/index.js +8 -0
  126. package/dist/slider/index.parts.d.ts +6 -0
  127. package/dist/slider/index.parts.js +6 -0
  128. package/dist/slider/label/slider-label.svelte +44 -0
  129. package/dist/slider/label/slider-label.svelte.d.ts +4 -0
  130. package/dist/slider/output/slider-output.svelte +46 -0
  131. package/dist/slider/output/slider-output.svelte.d.ts +4 -0
  132. package/dist/slider/root/context.d.ts +106 -0
  133. package/dist/slider/root/context.js +15 -0
  134. package/dist/slider/root/slider-root.svelte +545 -0
  135. package/dist/slider/root/slider-root.svelte.d.ts +4 -0
  136. package/dist/slider/root/slider-utils.d.ts +57 -0
  137. package/dist/slider/root/slider-utils.js +88 -0
  138. package/dist/slider/thumb/slider-thumb.svelte +276 -0
  139. package/dist/slider/thumb/slider-thumb.svelte.d.ts +4 -0
  140. package/dist/slider/track/slider-track.svelte +60 -0
  141. package/dist/slider/track/slider-track.svelte.d.ts +4 -0
  142. package/dist/slider/types.d.ts +144 -0
  143. package/dist/slider/types.js +1 -0
  144. package/dist/tooltip/README.md +53 -0
  145. package/dist/tooltip/arrow/tooltip-arrow.svelte +36 -0
  146. package/dist/tooltip/arrow/tooltip-arrow.svelte.d.ts +4 -0
  147. package/dist/tooltip/content/tooltip-content.svelte +148 -0
  148. package/dist/tooltip/content/tooltip-content.svelte.d.ts +4 -0
  149. package/dist/tooltip/index.d.ts +8 -0
  150. package/dist/tooltip/index.js +7 -0
  151. package/dist/tooltip/index.parts.d.ts +5 -0
  152. package/dist/tooltip/index.parts.js +5 -0
  153. package/dist/tooltip/provider/tooltip-provider.svelte +36 -0
  154. package/dist/tooltip/provider/tooltip-provider.svelte.d.ts +4 -0
  155. package/dist/tooltip/root/context.d.ts +46 -0
  156. package/dist/tooltip/root/context.js +22 -0
  157. package/dist/tooltip/root/safe-polygon.d.ts +26 -0
  158. package/dist/tooltip/root/safe-polygon.js +66 -0
  159. package/dist/tooltip/root/tooltip-group.d.ts +26 -0
  160. package/dist/tooltip/root/tooltip-group.js +41 -0
  161. package/dist/tooltip/root/tooltip-root.svelte +454 -0
  162. package/dist/tooltip/root/tooltip-root.svelte.d.ts +4 -0
  163. package/dist/tooltip/trigger/tooltip-trigger.svelte +52 -0
  164. package/dist/tooltip/trigger/tooltip-trigger.svelte.d.ts +4 -0
  165. package/dist/tooltip/types.d.ts +105 -0
  166. package/dist/tooltip/types.js +1 -0
  167. package/package.json +36 -1
@@ -0,0 +1,276 @@
1
+ <script lang="ts">
2
+ import { untrack, type Snippet } from 'svelte';
3
+ import { readable } from 'svelte/store';
4
+ import { resolveLocalizedString } from '../../internal/localized-strings';
5
+ import { isRtl } from '../../internal/rtl';
6
+ import { getLocaleContext } from '../../locale-provider/context';
7
+ import { watchFocusVisible } from '../../primitives/focus-visible.svelte';
8
+ import {
9
+ shouldShowFocusVisible,
10
+ trackInteractionModality
11
+ } from '../../primitives/input-modality';
12
+ import { useSliderContext, type SliderChangeDetails } from '../root/context';
13
+ import type { SliderThumbProps, SliderThumbRenderState } from '../types';
14
+
15
+ /**
16
+ * Slider.Thumb — the handle of one value.
17
+ *
18
+ * The element the user sees is a `<div>` positioned along the track. Inside it, a native
19
+ * `<input type="range">` fills the thumb, invisible, and it is what has the focus and the ARIA
20
+ * state. The native input gives the role and the value to a screen reader, and it receives
21
+ * the swipe of a mobile screen reader as an `input` event. The keyboard is handled here and
22
+ * not by the input, so that the steps, the large steps and the text direction are the same in
23
+ * every browser.
24
+ */
25
+ let {
26
+ index: indexProp,
27
+ name,
28
+ 'aria-label': ariaLabel,
29
+ 'aria-labelledby': ariaLabelledBy,
30
+ children,
31
+ class: className = '',
32
+ element = $bindable<HTMLDivElement | null>(null),
33
+ style,
34
+ onpointerdown,
35
+ ...restProps
36
+ }: SliderThumbProps = $props();
37
+
38
+ const ctx = useSliderContext('Slider.Thumb');
39
+ const localeStore = getLocaleContext()?.locale ?? readable<string | undefined>(undefined);
40
+
41
+ let thumbRef: HTMLDivElement | null = $state(null);
42
+ let inputRef: HTMLInputElement | null = $state(null);
43
+
44
+ const registration = ctx.registerThumb({
45
+ index: untrack(() => indexProp),
46
+ inputRef: () => inputRef
47
+ });
48
+ const index = registration.index;
49
+ const inputId = ctx.getThumbInputId(index);
50
+
51
+ $effect(() => {
52
+ element = thumbRef;
53
+ return () => {
54
+ element = null;
55
+ };
56
+ });
57
+
58
+ $effect(() => registration.unregister);
59
+
60
+ const value = $derived(ctx.values[index] ?? ctx.min);
61
+ const percent = $derived(ctx.getPercent(value));
62
+ const text = $derived(ctx.formatValue(value));
63
+ const valueText = $derived(ctx.getValueText(value, index));
64
+ const dragging = $derived(ctx.draggingIndex === index);
65
+ const focused = $derived(ctx.focusedIndex === index);
66
+ const focusVisible = $derived(focused && ctx.isFocusVisible);
67
+ const active = $derived(ctx.activeIndex === index);
68
+
69
+ // Two thumbs with the same name are two sliders the screen reader cannot tell apart. A range
70
+ // of two gets "Minimum" and "Maximum" when the consumer gives no name of its own.
71
+ const defaultLabel = $derived.by(() => {
72
+ if (ctx.values.length !== 2) return undefined;
73
+ return resolveLocalizedString($localeStore, index === 0 ? 'slider.minimum' : 'slider.maximum');
74
+ });
75
+ const ownLabel = $derived(ariaLabel ?? (ariaLabelledBy ? undefined : defaultLabel));
76
+ const ownLabelSource = $derived(ariaLabelledBy ?? (ownLabel ? inputId : null));
77
+ // The name of the group: the label, the ids the consumer gave, or the root element itself
78
+ // when it carries an `aria-label`.
79
+ const groupLabelSource = $derived(
80
+ ctx.ariaLabelledBy ?? ctx.labelId ?? (ctx.ariaLabel ? ctx.rootId : null)
81
+ );
82
+ const inputAriaLabel = $derived(
83
+ ownLabel ?? (groupLabelSource === ctx.rootId ? ctx.ariaLabel : undefined)
84
+ );
85
+ const inputLabelledBy = $derived.by(() => {
86
+ if (!ownLabelSource) {
87
+ return groupLabelSource && groupLabelSource !== ctx.rootId ? groupLabelSource : undefined;
88
+ }
89
+ return groupLabelSource ? `${ownLabelSource} ${groupLabelSource}` : ownLabelSource;
90
+ });
91
+
92
+ // The native input keeps the value: a screen reader reads it from there, and a form sends it.
93
+ $effect(() => {
94
+ if (!inputRef) return;
95
+ const nextValue = String(value);
96
+ if (inputRef.value !== nextValue) inputRef.value = nextValue;
97
+ });
98
+
99
+ // The focus ring must appear when a pointer press is followed by a key press, and the
100
+ // modality alone changes there: no focus event fires to re-read it.
101
+ watchFocusVisible({
102
+ isFocused: () => focused,
103
+ element: () => inputRef,
104
+ set: (visible) => ctx.setFocusVisible(visible)
105
+ });
106
+
107
+ const positionStyle = $derived.by(() => {
108
+ if (ctx.orientation === 'vertical') {
109
+ return `position: absolute; bottom: ${percent}%; left: 50%; translate: -50% 50%;`;
110
+ }
111
+ // A physical `left`, because the `translate` that centers the thumb is physical too.
112
+ const left = ctx.isRtl ? 100 - percent : percent;
113
+ return `position: absolute; left: ${left}%; top: 50%; translate: -50% -50%;`;
114
+ });
115
+ // The thumb the user touched last draws above the others: two thumbs at the same value
116
+ // would hide the one that just moved.
117
+ const resolvedStyle = $derived(
118
+ `${positionStyle} touch-action: none;${active ? ' z-index: 1;' : ''}${style ? ` ${style}` : ''}`
119
+ );
120
+
121
+ // The keyboard reports `onChange` on each key press, and `onChangeEnd` one time at the
122
+ // release, thus a held key does not report an end on each repeat.
123
+ let keyboardChanged = false;
124
+
125
+ function commitKeyboard(event: Event) {
126
+ if (!keyboardChanged) return;
127
+ keyboardChanged = false;
128
+ ctx.commitValue({ reason: 'keyboard', index, event });
129
+ }
130
+
131
+ function handleKeyDown(event: KeyboardEvent) {
132
+ if (event.defaultPrevented) return;
133
+ if (event.ctrlKey || event.metaKey || event.altKey) return;
134
+
135
+ const horizontal = ctx.orientation === 'horizontal';
136
+ const rtl = horizontal && isRtl(thumbRef);
137
+ let direction: -1 | 1 | null = null;
138
+ let large = event.shiftKey;
139
+ let absolute: number | null = null;
140
+
141
+ switch (event.key) {
142
+ case 'ArrowRight':
143
+ direction = rtl ? -1 : 1;
144
+ break;
145
+ case 'ArrowLeft':
146
+ direction = rtl ? 1 : -1;
147
+ break;
148
+ case 'ArrowUp':
149
+ direction = 1;
150
+ break;
151
+ case 'ArrowDown':
152
+ direction = -1;
153
+ break;
154
+ case 'PageUp':
155
+ direction = 1;
156
+ large = true;
157
+ break;
158
+ case 'PageDown':
159
+ direction = -1;
160
+ large = true;
161
+ break;
162
+ case 'Home':
163
+ absolute = ctx.min;
164
+ break;
165
+ case 'End':
166
+ absolute = ctx.max;
167
+ break;
168
+ default:
169
+ return;
170
+ }
171
+
172
+ // The native input would step on its own, in its own amounts.
173
+ event.preventDefault();
174
+ trackInteractionModality(event, inputRef);
175
+ if (focused) ctx.setFocusVisible(true);
176
+ if (ctx.isReadOnly) return;
177
+
178
+ if (absolute !== null) {
179
+ if (ctx.setValueAt(index, absolute, { reason: 'keyboard', index, event })) {
180
+ keyboardChanged = true;
181
+ }
182
+ return;
183
+ }
184
+ if (direction !== null && ctx.stepValueAt(index, direction, { large, event })) {
185
+ keyboardChanged = true;
186
+ }
187
+ }
188
+
189
+ function handleKeyUp(event: KeyboardEvent) {
190
+ commitKeyboard(event);
191
+ }
192
+
193
+ // A change that did not come through the keyboard handler: a mobile screen reader swipe, or
194
+ // a browser feature that writes the native input.
195
+ function handleInput(event: Event) {
196
+ if (!inputRef) return;
197
+ const nextValue = Number(inputRef.value);
198
+ if (Number.isFinite(nextValue) && nextValue !== value && !ctx.isReadOnly) {
199
+ const details: SliderChangeDetails = { reason: 'input', index, event };
200
+ if (ctx.setValueAt(index, nextValue, details)) ctx.commitValue(details);
201
+ }
202
+ // Re-sync when the change was refused, or clamped by a neighbor.
203
+ inputRef.value = String(ctx.values[index] ?? ctx.min);
204
+ }
205
+
206
+ function handleFocus() {
207
+ ctx.setThumbFocus(index, true);
208
+ ctx.setFocusVisible(shouldShowFocusVisible(inputRef));
209
+ }
210
+
211
+ function handleBlur(event: FocusEvent) {
212
+ // A key still held when the focus leaves has no release to wait for.
213
+ commitKeyboard(event);
214
+ ctx.setThumbFocus(index, false);
215
+ }
216
+
217
+ function handlePointerDown(
218
+ event: PointerEvent & { currentTarget: EventTarget & HTMLDivElement }
219
+ ) {
220
+ onpointerdown?.(event);
221
+ if (event.defaultPrevented) return;
222
+ // The thumb keeps its value at the press; only a move changes it.
223
+ ctx.startDrag(event, index);
224
+ }
225
+
226
+ const renderState = $derived<SliderThumbRenderState>({ value, text, index, dragging, focused });
227
+ </script>
228
+
229
+ <div
230
+ {...restProps}
231
+ bind:this={thumbRef}
232
+ class={className}
233
+ style={resolvedStyle}
234
+ data-slider-thumb="true"
235
+ data-index={index}
236
+ data-orientation={ctx.orientation}
237
+ data-disabled={ctx.isDisabled || undefined}
238
+ data-readonly={ctx.isReadOnly || undefined}
239
+ data-invalid={ctx.isInvalid || undefined}
240
+ data-dragging={dragging || undefined}
241
+ data-focused={focused || undefined}
242
+ data-focus-visible={focusVisible || undefined}
243
+ onpointerdown={handlePointerDown}
244
+ >
245
+ <input
246
+ bind:this={inputRef}
247
+ type="range"
248
+ id={inputId}
249
+ name={name ?? ctx.name}
250
+ form={ctx.form}
251
+ min={ctx.min}
252
+ max={ctx.max}
253
+ step={ctx.step}
254
+ value={String(value)}
255
+ disabled={ctx.isDisabled}
256
+ aria-orientation={ctx.orientation}
257
+ aria-valuenow={value}
258
+ aria-valuetext={valueText}
259
+ aria-label={inputAriaLabel}
260
+ aria-labelledby={inputLabelledBy}
261
+ aria-describedby={ctx.ariaDescribedBy}
262
+ aria-readonly={ctx.isReadOnly || undefined}
263
+ aria-invalid={ctx.isInvalid || undefined}
264
+ data-slider-input="true"
265
+ data-index={index}
266
+ style="position:absolute;inset:0;width:100%;height:100%;margin:0;padding:0;border:0;opacity:0;cursor:inherit;pointer-events:none;"
267
+ onkeydown={handleKeyDown}
268
+ onkeyup={handleKeyUp}
269
+ oninput={handleInput}
270
+ onfocus={handleFocus}
271
+ onblur={handleBlur}
272
+ />
273
+ {#if children}
274
+ {@render (children as Snippet<[SliderThumbRenderState]>)(renderState)}
275
+ {/if}
276
+ </div>
@@ -0,0 +1,4 @@
1
+ import type { SliderThumbProps } from '../types';
2
+ declare const SliderThumb: import("svelte").Component<SliderThumbProps, {}, "element">;
3
+ type SliderThumb = ReturnType<typeof SliderThumb>;
4
+ export default SliderThumb;
@@ -0,0 +1,60 @@
1
+ <script lang="ts">
2
+ import { useSliderContext } from '../root/context';
3
+ import type { SliderTrackProps } from '../types';
4
+
5
+ /**
6
+ * Slider.Track — the rail, and the surface of the pointer.
7
+ *
8
+ * A press on it moves the nearest thumb to the pointer and starts a drag. The thumbs sit in
9
+ * it, positioned along it in percent of the value. It is `position: relative` for that, and
10
+ * `touch-action: none` so that a touch drag moves the thumb and not the page.
11
+ */
12
+ let {
13
+ children,
14
+ class: className = '',
15
+ element = $bindable<HTMLDivElement | null>(null),
16
+ style,
17
+ onpointerdown,
18
+ ...restProps
19
+ }: SliderTrackProps = $props();
20
+
21
+ const ctx = useSliderContext('Slider.Track');
22
+ let trackRef: HTMLDivElement | null = $state(null);
23
+
24
+ $effect(() => {
25
+ element = trackRef;
26
+ ctx.setTrackRef(trackRef);
27
+ return () => {
28
+ ctx.setTrackRef(null);
29
+ };
30
+ });
31
+
32
+ // The consumer style comes last, thus it can replace the two defaults.
33
+ const resolvedStyle = $derived(
34
+ `position: relative; touch-action: none;${style ? ` ${style}` : ''}`
35
+ );
36
+
37
+ function handlePointerDown(
38
+ event: PointerEvent & { currentTarget: EventTarget & HTMLDivElement }
39
+ ) {
40
+ onpointerdown?.(event);
41
+ if (event.defaultPrevented) return;
42
+ ctx.startDrag(event);
43
+ }
44
+ </script>
45
+
46
+ <div
47
+ {...restProps}
48
+ bind:this={trackRef}
49
+ class={className}
50
+ style={resolvedStyle}
51
+ data-slider-track="true"
52
+ data-orientation={ctx.orientation}
53
+ data-disabled={ctx.isDisabled || undefined}
54
+ data-readonly={ctx.isReadOnly || undefined}
55
+ data-invalid={ctx.isInvalid || undefined}
56
+ data-dragging={ctx.draggingIndex !== null || undefined}
57
+ onpointerdown={handlePointerDown}
58
+ >
59
+ {@render children?.()}
60
+ </div>
@@ -0,0 +1,4 @@
1
+ import type { SliderTrackProps } from '../types';
2
+ declare const SliderTrack: import("svelte").Component<SliderTrackProps, {}, "element">;
3
+ type SliderTrack = ReturnType<typeof SliderTrack>;
4
+ export default SliderTrack;
@@ -0,0 +1,144 @@
1
+ import type { Snippet } from 'svelte';
2
+ import type { HTMLAttributes } from 'svelte/elements';
3
+ import type { SliderChangeDetails, SliderContext, SliderOrientation } from './root/context';
4
+ export type { SliderChangeDetails, SliderOrientation };
5
+ export type SliderValue = number | number[];
6
+ export type SliderRootProps = {
7
+ /** A stable id, from which the component makes its internal ARIA ids. Give one on a server. */
8
+ id?: string;
9
+ /**
10
+ * The value: one number for one thumb, and an array in ascending order for a range with more
11
+ * thumbs. You can bind it with `bind:value`.
12
+ */
13
+ value?: SliderValue;
14
+ /** The value at the start, for when you give no `value`. The default is `min`. */
15
+ defaultValue?: SliderValue;
16
+ /**
17
+ * Give your own code full control of the value. The component stops to write back to `value`,
18
+ * and it reports only through `onChange`. Thus the parent can refuse a change: the parent does
19
+ * not send the new value down. The default is off, because `bind:value` is the usual case and
20
+ * it needs the write-back.
21
+ */
22
+ controlledValue?: boolean;
23
+ /** The component calls it on each change, also on each move of a drag. */
24
+ onChange?: (value: SliderValue, details: SliderChangeDetails) => void;
25
+ /**
26
+ * The component calls it when a sequence of changes ends: at the release of a key, and at the
27
+ * end of a drag. A change from assistive technology ends at once. Use it for work that must
28
+ * not run on each move.
29
+ */
30
+ onChangeEnd?: (value: SliderValue, details: SliderChangeDetails) => void;
31
+ /** The lowest value. The default is 0. */
32
+ min?: number;
33
+ /** The highest value. The default is 100. */
34
+ max?: number;
35
+ /** The distance between two values. The default is 1. */
36
+ step?: number;
37
+ /**
38
+ * The distance of `PageUp`, `PageDown` and `Shift+Arrow`. The default is one tenth of the
39
+ * range, and never less than one step.
40
+ */
41
+ largeStep?: number;
42
+ /** The steps that two thumbs of a range keep between them. The default is 0: they can meet. */
43
+ minStepsBetweenThumbs?: number;
44
+ /** The direction of the track. The default is horizontal. */
45
+ orientation?: SliderOrientation;
46
+ /** Disables the slider. The native inputs are disabled, and the thumbs leave the tab order. */
47
+ disabled?: boolean;
48
+ /** Keeps the thumbs in the tab order, but the value does not change. */
49
+ readonly?: boolean;
50
+ /** Marks the value as invalid. The thumbs get `aria-invalid`. */
51
+ invalid?: boolean;
52
+ /** The name of the native inputs. A `Slider.Thumb` can give its own. */
53
+ name?: string;
54
+ /** The id of the form that the native inputs belong to, when the slider is outside it. */
55
+ form?: string;
56
+ /** The format of the value in `Slider.Output` and in the text that a screen reader reads. */
57
+ formatOptions?: Intl.NumberFormatOptions;
58
+ /**
59
+ * The text that a screen reader reads for a value, in place of the formatted number. The
60
+ * second argument is the index of the thumb.
61
+ */
62
+ getValueText?: (value: number, index: number) => string;
63
+ /** The accessible name of the slider, for when there is no `Slider.Label`. */
64
+ 'aria-label'?: string;
65
+ /** The id of the element that gives the slider its name, in place of `Slider.Label`. */
66
+ 'aria-labelledby'?: string;
67
+ /** The id of the element that describes the slider, for example an error message. */
68
+ 'aria-describedby'?: string;
69
+ /** The content: the label, the output and the track. */
70
+ children?: Snippet;
71
+ /** The CSS class names of the root element. */
72
+ class?: string;
73
+ /** A bindable reference to the root element. */
74
+ element?: HTMLDivElement | null;
75
+ /** A bindable reference to the context, for a composition of your own. */
76
+ context?: SliderContext;
77
+ } & Omit<HTMLAttributes<HTMLDivElement>, 'class' | 'children' | 'id' | 'role' | 'aria-label' | 'aria-labelledby' | 'aria-describedby' | 'onchange'>;
78
+ export type SliderLabelProps = Omit<HTMLAttributes<HTMLSpanElement>, 'class'> & {
79
+ /** The CSS class names of the label. */
80
+ class?: string;
81
+ };
82
+ export type SliderOutputRenderState = {
83
+ /** The values, one per thumb. */
84
+ values: number[];
85
+ /** The text of each value, in the locale and the `formatOptions`. */
86
+ texts: string[];
87
+ /** The text of the whole value: one number, or a range in the locale. */
88
+ text: string;
89
+ };
90
+ export type SliderOutputProps = Omit<HTMLAttributes<HTMLOutputElement>, 'class' | 'children'> & {
91
+ /**
92
+ * The content. As a snippet with one argument, it receives the render state: `values`, `texts`
93
+ * and `text`. Without it, the component shows `text`.
94
+ */
95
+ children?: Snippet<[SliderOutputRenderState]>;
96
+ /** The CSS class names of the element. */
97
+ class?: string;
98
+ };
99
+ export type SliderTrackProps = Omit<HTMLAttributes<HTMLDivElement>, 'class'> & {
100
+ /** The CSS class names of the track. */
101
+ class?: string;
102
+ /** A bindable reference to the track element. */
103
+ element?: HTMLDivElement | null;
104
+ };
105
+ export type SliderFillProps = Omit<HTMLAttributes<HTMLDivElement>, 'class'> & {
106
+ /** The CSS class names of the fill. */
107
+ class?: string;
108
+ };
109
+ export type SliderThumbRenderState = {
110
+ /** The value of the thumb. */
111
+ value: number;
112
+ /** The text of the value. */
113
+ text: string;
114
+ /** The index of the thumb. */
115
+ index: number;
116
+ /** Whether the thumb is under a pointer drag. */
117
+ dragging: boolean;
118
+ /** Whether the native input of the thumb has the focus. */
119
+ focused: boolean;
120
+ };
121
+ export type SliderThumbProps = Omit<HTMLAttributes<HTMLDivElement>, 'class' | 'children' | 'aria-label' | 'aria-labelledby'> & {
122
+ /**
123
+ * The index of the thumb, for a range. Without it, the thumbs take the indexes in mount order.
124
+ */
125
+ index?: number;
126
+ /** The `name` of the native input of this thumb. It replaces the `name` of the root. */
127
+ name?: string;
128
+ /**
129
+ * The name of this thumb, before the name of the slider. A range of two thumbs without one
130
+ * gets "Minimum" and "Maximum" in the locale.
131
+ */
132
+ 'aria-label'?: string;
133
+ /** The id of the element that names this thumb, in place of `aria-label`. */
134
+ 'aria-labelledby'?: string;
135
+ /**
136
+ * The content. As a snippet with one argument, it receives the render state: `value`, `text`,
137
+ * `index`, `dragging` and `focused`.
138
+ */
139
+ children?: Snippet<[SliderThumbRenderState]> | Snippet;
140
+ /** The CSS class names of the thumb. */
141
+ class?: string;
142
+ /** A bindable reference to the thumb element. */
143
+ element?: HTMLDivElement | null;
144
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,53 @@
1
+ # Tooltip
2
+
3
+ ## Description
4
+
5
+ `Tooltip` shows a short description of a control when the pointer rests on it, or when the keyboard puts the focus on it. It holds text only. A screen reader reads the text after the name of the control.
6
+
7
+ ## Anatomy
8
+
9
+ - `Tooltip.Provider`
10
+ - `Tooltip.Root`
11
+ - `Tooltip.Trigger`
12
+ - `Tooltip.Content`
13
+ - `Tooltip.Arrow`
14
+
15
+ ```svelte
16
+ <Tooltip.Root>
17
+ <Tooltip.Trigger aria-label="Bold">B</Tooltip.Trigger>
18
+ <Tooltip.Content>
19
+ Bold
20
+ <Tooltip.Arrow />
21
+ </Tooltip.Content>
22
+ </Tooltip.Root>
23
+ ```
24
+
25
+ ## Usage guidelines
26
+
27
+ - Use it for a description the user can do without. A touch has no hover: a long press opens it.
28
+ - Give the trigger a name of its own. The tooltip is the description, not the name.
29
+ - Put only text in the content. It takes no focus.
30
+ - Put a `Tooltip.Provider` around a toolbar, thus every tooltip in it has the same delays.
31
+ - Give an element that is not a `Tooltip.Trigger` to `triggerRef` on the root.
32
+
33
+ ## API reference
34
+
35
+ - `Tooltip.Root`
36
+ - `open?: boolean`, `defaultOpen?: boolean`, `controlledOpen?: boolean`
37
+ - `onOpenChange?: (open, details) => void`
38
+ - `delay?: number` (600), `closeDelay?: number` (100)
39
+ - `disabled?: boolean`
40
+ - `openOnLongPress?: boolean`
41
+ - `triggerRef?: HTMLElement | null`
42
+ - `Tooltip.Provider`
43
+ - `delay?: number`, `closeDelay?: number`, `skipDelay?: number` (300)
44
+ - `Tooltip.Content`
45
+ - `placement?: ExtendedPlacement` (top), `offset?: number` (8), `shouldFlip?: boolean`, `boundaryElement?: Element | null`
46
+ - `followPointer?: 'x' | 'y' | 'both'`
47
+
48
+ ## Accessibility
49
+
50
+ - `Tooltip.Content` has `role="tooltip"`; the trigger gets `aria-describedby` while the content is in the DOM.
51
+ - A keyboard focus opens at once. A focus that a script gives opens only with the keyboard modality. A touch opens on a long press, and a tap does not.
52
+ - The pointer can cross the gap to the content in a straight line, and rest on the content. `Escape` closes, and a press on the trigger closes.
53
+ - One tooltip at most is open on the page. The next one after a close skips its delay for `skipDelay` milliseconds.
@@ -0,0 +1,36 @@
1
+ <script lang="ts">
2
+ import { useTooltipContext } from '../root/context';
3
+ import type { TooltipArrowProps } from '../types';
4
+
5
+ /**
6
+ * Tooltip.Arrow — the pointer of the panel toward the trigger.
7
+ *
8
+ * The panel moves it along the edge that faces the trigger, with `left` or `top`, and it
9
+ * writes the side in `data-placement`. The shape, the size, and the offset from the edge are
10
+ * for the CSS: for a panel above the trigger, `[data-placement="top"]` sits at the bottom edge.
11
+ */
12
+ let { children, class: className = '', style, ...restProps }: TooltipArrowProps = $props();
13
+
14
+ const ctx = useTooltipContext('Tooltip.Arrow');
15
+ let arrowRef: HTMLSpanElement | null = $state(null);
16
+
17
+ $effect(() => {
18
+ ctx.setArrowRef(arrowRef);
19
+ return () => {
20
+ ctx.setArrowRef(null);
21
+ };
22
+ });
23
+
24
+ const resolvedStyle = $derived(`position: absolute;${style ? ` ${style}` : ''}`);
25
+ </script>
26
+
27
+ <span
28
+ {...restProps}
29
+ bind:this={arrowRef}
30
+ class={className}
31
+ style={resolvedStyle}
32
+ aria-hidden="true"
33
+ data-tooltip-arrow="true"
34
+ >
35
+ {@render children?.()}
36
+ </span>
@@ -0,0 +1,4 @@
1
+ import type { TooltipArrowProps } from '../types';
2
+ declare const TooltipArrow: import("svelte").Component<TooltipArrowProps, {}, "">;
3
+ type TooltipArrow = ReturnType<typeof TooltipArrow>;
4
+ export default TooltipArrow;