@human-kit/ui 1.0.0-beta.6 → 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 (223) hide show
  1. package/dist/FOCUS_STATE_CONTRACT.md +15 -4
  2. package/dist/FOCUS_STATE_REVIEW_TEMPLATE.md +8 -8
  3. package/dist/autocomplete/item/autocomplete-item.svelte +10 -0
  4. package/dist/avatar/README.md +52 -0
  5. package/dist/avatar/count/avatar-count.svelte +56 -0
  6. package/dist/avatar/count/avatar-count.svelte.d.ts +4 -0
  7. package/dist/avatar/fallback/avatar-fallback.svelte +67 -0
  8. package/dist/avatar/fallback/avatar-fallback.svelte.d.ts +4 -0
  9. package/dist/avatar/group/avatar-group.svelte +65 -0
  10. package/dist/avatar/group/avatar-group.svelte.d.ts +4 -0
  11. package/dist/avatar/group/context.d.ts +15 -0
  12. package/dist/avatar/group/context.js +15 -0
  13. package/dist/avatar/image/avatar-image.svelte +104 -0
  14. package/dist/avatar/image/avatar-image.svelte.d.ts +4 -0
  15. package/dist/avatar/index.d.ts +22 -0
  16. package/dist/avatar/index.js +10 -0
  17. package/dist/avatar/index.parts.d.ts +5 -0
  18. package/dist/avatar/index.parts.js +5 -0
  19. package/dist/avatar/root/avatar-root.svelte +79 -0
  20. package/dist/avatar/root/avatar-root.svelte.d.ts +4 -0
  21. package/dist/avatar/root/context.d.ts +14 -0
  22. package/dist/avatar/root/context.js +15 -0
  23. package/dist/avatar/types.d.ts +84 -0
  24. package/dist/avatar/types.js +1 -0
  25. package/dist/breadcrumbs/README.md +65 -0
  26. package/dist/breadcrumbs/ellipsis/breadcrumbs-ellipsis.svelte +62 -0
  27. package/dist/breadcrumbs/ellipsis/breadcrumbs-ellipsis.svelte.d.ts +4 -0
  28. package/dist/breadcrumbs/index.d.ts +23 -0
  29. package/dist/breadcrumbs/index.js +10 -0
  30. package/dist/breadcrumbs/index.parts.d.ts +6 -0
  31. package/dist/breadcrumbs/index.parts.js +6 -0
  32. package/dist/breadcrumbs/item/breadcrumbs-item.svelte +42 -0
  33. package/dist/breadcrumbs/item/breadcrumbs-item.svelte.d.ts +4 -0
  34. package/dist/breadcrumbs/link/breadcrumbs-link.svelte +47 -0
  35. package/dist/breadcrumbs/link/breadcrumbs-link.svelte.d.ts +4 -0
  36. package/dist/breadcrumbs/list/breadcrumbs-list.svelte +31 -0
  37. package/dist/breadcrumbs/list/breadcrumbs-list.svelte.d.ts +4 -0
  38. package/dist/breadcrumbs/root/breadcrumbs-root.svelte +112 -0
  39. package/dist/breadcrumbs/root/breadcrumbs-root.svelte.d.ts +4 -0
  40. package/dist/breadcrumbs/root/context.d.ts +19 -0
  41. package/dist/breadcrumbs/root/context.js +15 -0
  42. package/dist/breadcrumbs/separator/breadcrumbs-separator.svelte +35 -0
  43. package/dist/breadcrumbs/separator/breadcrumbs-separator.svelte.d.ts +4 -0
  44. package/dist/breadcrumbs/types.d.ts +80 -0
  45. package/dist/breadcrumbs/types.js +1 -0
  46. package/dist/button/root/button-root.svelte +9 -0
  47. package/dist/calendar/body-cell/calendar-body-cell.svelte +7 -0
  48. package/dist/checkbox/indicator/checkbox-indicator.svelte +1 -0
  49. package/dist/checkbox/indicator/checkbox-indicator.svelte.d.ts +1 -0
  50. package/dist/checkbox/root/checkbox-root.svelte +106 -30
  51. package/dist/checkbox/root/checkbox-root.svelte.d.ts +5 -0
  52. package/dist/checkbox-group/README.md +95 -0
  53. package/dist/checkbox-group/index.d.ts +15 -0
  54. package/dist/checkbox-group/index.js +6 -0
  55. package/dist/checkbox-group/index.parts.d.ts +4 -0
  56. package/dist/checkbox-group/index.parts.js +7 -0
  57. package/dist/checkbox-group/label/checkbox-group-label.svelte +36 -0
  58. package/dist/checkbox-group/label/checkbox-group-label.svelte.d.ts +4 -0
  59. package/dist/checkbox-group/root/checkbox-group-root.svelte +118 -0
  60. package/dist/checkbox-group/root/checkbox-group-root.svelte.d.ts +4 -0
  61. package/dist/checkbox-group/root/context.svelte.d.ts +52 -0
  62. package/dist/checkbox-group/root/context.svelte.js +251 -0
  63. package/dist/checkbox-group/types.d.ts +57 -0
  64. package/dist/checkbox-group/types.js +1 -0
  65. package/dist/combobox/popover/combobox-popover.svelte +4 -56
  66. package/dist/dialog/root/dialog-root.svelte +15 -2
  67. package/dist/drawer/root/drawer-root.svelte +15 -2
  68. package/dist/index.d.ts +18 -0
  69. package/dist/index.js +17 -0
  70. package/dist/internal/localized-strings.d.ts +48 -0
  71. package/dist/internal/localized-strings.js +48 -0
  72. package/dist/internal/number-precision.d.ts +9 -0
  73. package/dist/internal/number-precision.js +27 -0
  74. package/dist/menu/root/focus-state.d.ts +2 -2
  75. package/dist/menu/root/focus-state.js +8 -32
  76. package/dist/menu/root/menu-state.svelte.js +5 -1
  77. package/dist/numberfield/root/number-utils.js +1 -20
  78. package/dist/popover/root/focus-state.d.ts +2 -2
  79. package/dist/popover/root/focus-state.js +7 -34
  80. package/dist/primitives/contain-wheel.d.ts +9 -0
  81. package/dist/primitives/contain-wheel.js +41 -0
  82. package/dist/primitives/floating.d.ts +6 -0
  83. package/dist/primitives/floating.js +26 -5
  84. package/dist/primitives/focus-visible.svelte.d.ts +14 -0
  85. package/dist/primitives/focus-visible.svelte.js +19 -0
  86. package/dist/primitives/index.d.ts +1 -0
  87. package/dist/primitives/index.js +1 -0
  88. package/dist/primitives/input-modality.d.ts +7 -0
  89. package/dist/primitives/input-modality.js +32 -5
  90. package/dist/primitives/keyboard-navigation.d.ts +6 -0
  91. package/dist/primitives/keyboard-navigation.js +2 -1
  92. package/dist/primitives/trigger-focus-state.d.ts +29 -0
  93. package/dist/primitives/trigger-focus-state.js +57 -0
  94. package/dist/progress/README.md +54 -0
  95. package/dist/progress/index.d.ts +21 -0
  96. package/dist/progress/index.js +9 -0
  97. package/dist/progress/index.parts.d.ts +5 -0
  98. package/dist/progress/index.parts.js +5 -0
  99. package/dist/progress/indicator/progress-indicator.svelte +37 -0
  100. package/dist/progress/indicator/progress-indicator.svelte.d.ts +4 -0
  101. package/dist/progress/label/progress-label.svelte +34 -0
  102. package/dist/progress/label/progress-label.svelte.d.ts +4 -0
  103. package/dist/progress/root/context.d.ts +26 -0
  104. package/dist/progress/root/context.js +15 -0
  105. package/dist/progress/root/progress-root.svelte +136 -0
  106. package/dist/progress/root/progress-root.svelte.d.ts +4 -0
  107. package/dist/progress/root/progress-utils.d.ts +12 -0
  108. package/dist/progress/root/progress-utils.js +41 -0
  109. package/dist/progress/track/progress-track.svelte +27 -0
  110. package/dist/progress/track/progress-track.svelte.d.ts +4 -0
  111. package/dist/progress/types.d.ts +81 -0
  112. package/dist/progress/types.js +1 -0
  113. package/dist/progress/value/progress-value.svelte +36 -0
  114. package/dist/progress/value/progress-value.svelte.d.ts +4 -0
  115. package/dist/radio-group/README.md +103 -0
  116. package/dist/radio-group/index.d.ts +18 -0
  117. package/dist/radio-group/index.js +9 -0
  118. package/dist/radio-group/index.parts.d.ts +4 -0
  119. package/dist/radio-group/index.parts.js +4 -0
  120. package/dist/radio-group/indicator/radio-group-indicator.svelte +43 -0
  121. package/dist/radio-group/indicator/radio-group-indicator.svelte.d.ts +12 -0
  122. package/dist/radio-group/item/context.d.ts +18 -0
  123. package/dist/radio-group/item/context.js +15 -0
  124. package/dist/radio-group/item/radio-group-item.svelte +377 -0
  125. package/dist/radio-group/item/radio-group-item.svelte.d.ts +35 -0
  126. package/dist/radio-group/label/radio-group-label.svelte +37 -0
  127. package/dist/radio-group/label/radio-group-label.svelte.d.ts +4 -0
  128. package/dist/radio-group/root/context.svelte.d.ts +57 -0
  129. package/dist/radio-group/root/context.svelte.js +284 -0
  130. package/dist/radio-group/root/radio-group-root.svelte +193 -0
  131. package/dist/radio-group/root/radio-group-root.svelte.d.ts +4 -0
  132. package/dist/radio-group/types.d.ts +50 -0
  133. package/dist/radio-group/types.js +1 -0
  134. package/dist/select/README.md +129 -0
  135. package/dist/select/index.d.ts +30 -0
  136. package/dist/select/index.js +16 -0
  137. package/dist/select/index.parts.d.ts +8 -0
  138. package/dist/select/index.parts.js +9 -0
  139. package/dist/select/item/select-item.svelte +68 -0
  140. package/dist/select/item/select-item.svelte.d.ts +10 -0
  141. package/dist/select/item-indicator/select-item-indicator.svelte +55 -0
  142. package/dist/select/item-indicator/select-item-indicator.svelte.d.ts +4 -0
  143. package/dist/select/label/select-label.svelte +46 -0
  144. package/dist/select/label/select-label.svelte.d.ts +4 -0
  145. package/dist/select/list/select-list.svelte +241 -0
  146. package/dist/select/list/select-list.svelte.d.ts +62 -0
  147. package/dist/select/popover/select-popover.svelte +80 -0
  148. package/dist/select/popover/select-popover.svelte.d.ts +9 -0
  149. package/dist/select/root/context.d.ts +106 -0
  150. package/dist/select/root/context.js +22 -0
  151. package/dist/select/root/select-root.svelte +544 -0
  152. package/dist/select/root/select-root.svelte.d.ts +25 -0
  153. package/dist/select/trigger/select-trigger.svelte +192 -0
  154. package/dist/select/trigger/select-trigger.svelte.d.ts +4 -0
  155. package/dist/select/types.d.ts +133 -0
  156. package/dist/select/types.js +1 -0
  157. package/dist/select/value/select-value.svelte +61 -0
  158. package/dist/select/value/select-value.svelte.d.ts +4 -0
  159. package/dist/separator/README.md +35 -0
  160. package/dist/separator/index.d.ts +7 -0
  161. package/dist/separator/index.js +3 -0
  162. package/dist/separator/separator.svelte +254 -0
  163. package/dist/separator/separator.svelte.d.ts +45 -0
  164. package/dist/separator/types.d.ts +1 -0
  165. package/dist/separator/types.js +1 -0
  166. package/dist/slider/README.md +61 -0
  167. package/dist/slider/fill/slider-fill.svelte +40 -0
  168. package/dist/slider/fill/slider-fill.svelte.d.ts +4 -0
  169. package/dist/slider/index.d.ts +9 -0
  170. package/dist/slider/index.js +8 -0
  171. package/dist/slider/index.parts.d.ts +6 -0
  172. package/dist/slider/index.parts.js +6 -0
  173. package/dist/slider/label/slider-label.svelte +44 -0
  174. package/dist/slider/label/slider-label.svelte.d.ts +4 -0
  175. package/dist/slider/output/slider-output.svelte +46 -0
  176. package/dist/slider/output/slider-output.svelte.d.ts +4 -0
  177. package/dist/slider/root/context.d.ts +106 -0
  178. package/dist/slider/root/context.js +15 -0
  179. package/dist/slider/root/slider-root.svelte +545 -0
  180. package/dist/slider/root/slider-root.svelte.d.ts +4 -0
  181. package/dist/slider/root/slider-utils.d.ts +57 -0
  182. package/dist/slider/root/slider-utils.js +88 -0
  183. package/dist/slider/thumb/slider-thumb.svelte +276 -0
  184. package/dist/slider/thumb/slider-thumb.svelte.d.ts +4 -0
  185. package/dist/slider/track/slider-track.svelte +60 -0
  186. package/dist/slider/track/slider-track.svelte.d.ts +4 -0
  187. package/dist/slider/types.d.ts +144 -0
  188. package/dist/slider/types.js +1 -0
  189. package/dist/switch/root/switch-root.svelte +9 -0
  190. package/dist/table/column-header-cell/table-column-header-cell.svelte +24 -0
  191. package/dist/table/root/table-root.svelte +29 -6
  192. package/dist/timepicker/input/time-picker-input.svelte +12 -4
  193. package/dist/timepicker/input/time-picker-input.svelte.d.ts +12 -4
  194. package/dist/toggle/root/toggle-root.svelte +28 -0
  195. package/dist/toggle/root/toggle-root.svelte.d.ts +19 -0
  196. package/dist/toggle-group/README.md +6 -4
  197. package/dist/toggle-group/index.d.ts +2 -0
  198. package/dist/toggle-group/index.parts.d.ts +1 -0
  199. package/dist/toggle-group/index.parts.js +4 -0
  200. package/dist/tooltip/README.md +53 -0
  201. package/dist/tooltip/arrow/tooltip-arrow.svelte +36 -0
  202. package/dist/tooltip/arrow/tooltip-arrow.svelte.d.ts +4 -0
  203. package/dist/tooltip/content/tooltip-content.svelte +148 -0
  204. package/dist/tooltip/content/tooltip-content.svelte.d.ts +4 -0
  205. package/dist/tooltip/index.d.ts +8 -0
  206. package/dist/tooltip/index.js +7 -0
  207. package/dist/tooltip/index.parts.d.ts +5 -0
  208. package/dist/tooltip/index.parts.js +5 -0
  209. package/dist/tooltip/provider/tooltip-provider.svelte +36 -0
  210. package/dist/tooltip/provider/tooltip-provider.svelte.d.ts +4 -0
  211. package/dist/tooltip/root/context.d.ts +46 -0
  212. package/dist/tooltip/root/context.js +22 -0
  213. package/dist/tooltip/root/safe-polygon.d.ts +26 -0
  214. package/dist/tooltip/root/safe-polygon.js +66 -0
  215. package/dist/tooltip/root/tooltip-group.d.ts +26 -0
  216. package/dist/tooltip/root/tooltip-group.js +41 -0
  217. package/dist/tooltip/root/tooltip-root.svelte +454 -0
  218. package/dist/tooltip/root/tooltip-root.svelte.d.ts +4 -0
  219. package/dist/tooltip/trigger/tooltip-trigger.svelte +52 -0
  220. package/dist/tooltip/trigger/tooltip-trigger.svelte.d.ts +4 -0
  221. package/dist/tooltip/types.d.ts +105 -0
  222. package/dist/tooltip/types.js +1 -0
  223. package/package.json +46 -1
@@ -8,6 +8,20 @@ let currentModality = 'virtual';
8
8
  const RECENT_INPUT_WINDOW_MS = 50;
9
9
  let lastInputEventTime = Number.NEGATIVE_INFINITY;
10
10
  const listenedWindows = new WeakSet();
11
+ /**
12
+ * Notified whenever the modality changes. `data-focus-visible` is otherwise a snapshot taken
13
+ * when the element took focus, so a pointer press followed by a key press left the ring off
14
+ * while the browser had already flipped `:focus-visible` back on.
15
+ */
16
+ const modalityListeners = new Set();
17
+ function setModality(next) {
18
+ if (currentModality === next)
19
+ return;
20
+ currentModality = next;
21
+ for (const listener of [...modalityListeners]) {
22
+ listener(next);
23
+ }
24
+ }
11
25
  let forcedFocusTarget = null;
12
26
  let forcedFocusModality = null;
13
27
  function isModifierOnlyKey(event) {
@@ -29,11 +43,11 @@ function ensureWindowListeners(win) {
29
43
  lastInputEventTime = Date.now();
30
44
  if (!isKeyboardModalityKey(event))
31
45
  return;
32
- currentModality = 'keyboard';
46
+ setModality('keyboard');
33
47
  };
34
48
  const onPointerDown = () => {
35
49
  lastInputEventTime = Date.now();
36
- currentModality = 'pointer';
50
+ setModality('pointer');
37
51
  };
38
52
  const onFocusIn = (event) => {
39
53
  // A programmatic focus with an explicit modality (`focusWithModality`) must keep it —
@@ -45,7 +59,7 @@ function ensureWindowListeners(win) {
45
59
  return;
46
60
  // No recent keyboard/pointer input: this focus move came from an assistive technology
47
61
  // (or a script), so focus rings must show again.
48
- currentModality = 'virtual';
62
+ setModality('virtual');
49
63
  };
50
64
  win.addEventListener('keydown', onKeyDown, true);
51
65
  win.addEventListener('pointerdown', onPointerDown, true);
@@ -90,12 +104,25 @@ export function trackInteractionModality(event, target) {
90
104
  initInputModality(target);
91
105
  const inferred = inferModalityFromEvent(event);
92
106
  if (inferred) {
93
- currentModality = inferred;
107
+ setModality(inferred);
94
108
  }
95
109
  }
96
110
  export function getInteractionModality() {
97
111
  return currentModality;
98
112
  }
113
+ /**
114
+ * Calls `listener` whenever the interaction modality changes, and returns the unsubscribe
115
+ * function. Components use it to re-read `shouldShowFocusVisible` for an element that already
116
+ * holds focus: the browser re-evaluates `:focus-visible` on its own, and this is what lets a
117
+ * component notice.
118
+ */
119
+ export function subscribeInputModality(listener) {
120
+ initInputModality();
121
+ modalityListeners.add(listener);
122
+ return () => {
123
+ modalityListeners.delete(listener);
124
+ };
125
+ }
99
126
  export function shouldShowFocusVisible(target) {
100
127
  if (!target)
101
128
  return false;
@@ -111,7 +138,7 @@ export function focusWithModality(target, modality, options) {
111
138
  // If it is consumed later, currentModality still preserves the same modality as fallback.
112
139
  forcedFocusTarget = target;
113
140
  forcedFocusModality = modality;
114
- currentModality = modality;
141
+ setModality(modality);
115
142
  if (modality === 'pointer') {
116
143
  const pointerFocusOptions = {
117
144
  ...(options ?? {}),
@@ -79,6 +79,12 @@ export type KeyboardNavigationReturn = {
79
79
  setCurrentId: (id: string | number | null) => void;
80
80
  /** Update items (call after DOM changes) */
81
81
  updateItems: () => void;
82
+ /**
83
+ * Searches with a printable character, the same as a key press on the container. For a
84
+ * widget that opens on a character typed outside the container, such as a select: the
85
+ * character is applied once the items exist.
86
+ */
87
+ typeahead: (char: string) => void;
82
88
  };
83
89
  /**
84
90
  * Creates a keyboard navigation controller for list-like components.
@@ -358,7 +358,8 @@ export function createKeyboardNavigation(options = {}) {
358
358
  focusLast,
359
359
  focusById,
360
360
  setCurrentId,
361
- updateItems
361
+ updateItems,
362
+ typeahead: handleTypeahead
362
363
  };
363
364
  }
364
365
  /**
@@ -0,0 +1,29 @@
1
+ /**
2
+ * The focus state of a trigger after its floating panel closes.
3
+ *
4
+ * Shared by Popover and Menu, whose close reasons differ only in which of them return the
5
+ * focus to the trigger. The rule for the attributes is the same for both: the trigger shows
6
+ * `data-focused` and `data-focus-visible` only while it holds the focus. Written by hand for
7
+ * a trigger that does not hold it, they would clear only on a blur of the trigger — and a
8
+ * trigger that never took the focus never blurs.
9
+ */
10
+ export declare function clearTriggerFocusState(trigger: HTMLElement): void;
11
+ /**
12
+ * Whether the last interaction left the focus on nothing: the body, or no element at all.
13
+ *
14
+ * An outside press on a heading, on a paragraph or on the background moves the focus to the
15
+ * body, and a keyboard user then has nowhere to continue from — Space and Enter open nothing.
16
+ * The focus returns to the trigger in that case, and only in that case: a press on a button or
17
+ * an input keeps the focus the user just gave it.
18
+ */
19
+ export declare function focusFellToBody(): boolean;
20
+ export type ApplyTriggerCloseFocusStateOptions = {
21
+ /**
22
+ * Whether the close reason returns the focus to the trigger on its own. An outside press
23
+ * never does, and it is handled here: the focus returns only when the press left it on
24
+ * nothing.
25
+ */
26
+ refocus: boolean;
27
+ };
28
+ export declare function applyTriggerCloseFocusState(trigger: HTMLElement, reason: string, event: Event | undefined, options: ApplyTriggerCloseFocusStateOptions): void;
29
+ export declare function addTriggerBlurCleanup(trigger: HTMLElement, once?: boolean): () => void;
@@ -0,0 +1,57 @@
1
+ import { focusWithModality, resolveCloseInteractionModality } from './input-modality.js';
2
+ /**
3
+ * The focus state of a trigger after its floating panel closes.
4
+ *
5
+ * Shared by Popover and Menu, whose close reasons differ only in which of them return the
6
+ * focus to the trigger. The rule for the attributes is the same for both: the trigger shows
7
+ * `data-focused` and `data-focus-visible` only while it holds the focus. Written by hand for
8
+ * a trigger that does not hold it, they would clear only on a blur of the trigger — and a
9
+ * trigger that never took the focus never blurs.
10
+ */
11
+ export function clearTriggerFocusState(trigger) {
12
+ delete trigger.dataset.focused;
13
+ delete trigger.dataset.focusVisible;
14
+ }
15
+ /**
16
+ * Whether the last interaction left the focus on nothing: the body, or no element at all.
17
+ *
18
+ * An outside press on a heading, on a paragraph or on the background moves the focus to the
19
+ * body, and a keyboard user then has nowhere to continue from — Space and Enter open nothing.
20
+ * The focus returns to the trigger in that case, and only in that case: a press on a button or
21
+ * an input keeps the focus the user just gave it.
22
+ */
23
+ export function focusFellToBody() {
24
+ const active = document.activeElement;
25
+ return !active || active === document.body || active === document.documentElement;
26
+ }
27
+ export function applyTriggerCloseFocusState(trigger, reason, event, options) {
28
+ const closeModality = resolveCloseInteractionModality(reason, event);
29
+ if (options.refocus || (reason === 'outside-press' && focusFellToBody())) {
30
+ focusWithModality(trigger, closeModality);
31
+ }
32
+ const holdsFocus = document.activeElement === trigger;
33
+ if (holdsFocus) {
34
+ trigger.dataset.focused = 'true';
35
+ }
36
+ else {
37
+ delete trigger.dataset.focused;
38
+ }
39
+ if (holdsFocus && closeModality === 'keyboard') {
40
+ trigger.dataset.focusVisible = 'true';
41
+ }
42
+ else {
43
+ delete trigger.dataset.focusVisible;
44
+ }
45
+ }
46
+ export function addTriggerBlurCleanup(trigger, once = false) {
47
+ const handleBlur = () => {
48
+ clearTriggerFocusState(trigger);
49
+ if (once) {
50
+ trigger.removeEventListener('blur', handleBlur);
51
+ }
52
+ };
53
+ trigger.addEventListener('blur', handleBlur);
54
+ return () => {
55
+ trigger.removeEventListener('blur', handleBlur);
56
+ };
57
+ }
@@ -0,0 +1,54 @@
1
+ # Progress
2
+
3
+ ## Description
4
+
5
+ `Progress` shows the status of a task that takes time. It holds a value between `min` and `max`, or no value while the end of the task is not known. A screen reader reads its name and its value.
6
+
7
+ ## Anatomy
8
+
9
+ - `Progress.Root`
10
+ - `Progress.Label`
11
+ - `Progress.Track`
12
+ - `Progress.Indicator`
13
+ - `Progress.Value`
14
+
15
+ ```svelte
16
+ <Progress.Root value={31}>
17
+ <Progress.Label>Export data</Progress.Label>
18
+ <Progress.Value />
19
+ <Progress.Track>
20
+ <Progress.Indicator />
21
+ </Progress.Track>
22
+ </Progress.Root>
23
+ ```
24
+
25
+ ## Usage guidelines
26
+
27
+ - Give the bar a name with `Progress.Label`, or with `aria-label` on the root.
28
+ - Give `value={null}` while the end of the task is not known. Animate the indicator with CSS on `data-indeterminate`.
29
+ - Give `format` to show the value in a unit. Without it, the text is the position in the range as a percentage.
30
+ - Read `percent` and `status` from `bind:context` for a shape of your own, such as a ring.
31
+ - Put `aria-busy="true"` on the region that the task fills. The bar says how far the task is; it does not say what the task changes.
32
+
33
+ ## API reference
34
+
35
+ - `Progress.Root`
36
+ - `value: number | null`
37
+ - `min?: number` (0), `max?: number` (100)
38
+ - `format?: Intl.NumberFormatOptions`
39
+ - `getValueText?: (formattedValue, value) => string`
40
+ - `aria-valuetext?: string`
41
+ - `orientation?: 'horizontal' | 'vertical'` (horizontal)
42
+ - `element?`, `context?`
43
+ - `Progress.Value`
44
+ - `children?: Snippet<[{ formattedValue, value, status }]>`
45
+
46
+ ## Accessibility
47
+
48
+ - `Progress.Root` has `role="progressbar"` with `aria-valuemin`, `aria-valuemax`, `aria-valuenow` and `aria-valuetext`.
49
+ - An indeterminate progress has no `aria-valuenow` and no `aria-valuetext`. A number for a task with no known end would be false.
50
+ - `Progress.Label` writes `aria-labelledby` on the bar. An `aria-labelledby` that you give stands.
51
+ - `Progress.Value` is `aria-hidden`: the bar already gives the value to the screen reader.
52
+ - The value follows the locale of `LocaleProvider`, and the runtime locale without one.
53
+ - The bar takes no focus, and it has no focus state. It is not in the focus contract.
54
+ - The indicator fills from the start edge of the text direction: a right-to-left page fills from the right.
@@ -0,0 +1,21 @@
1
+ import type { ComponentProps } from 'svelte';
2
+ import type ProgressIndicatorComponent from './indicator/progress-indicator.svelte';
3
+ import type ProgressLabelComponent from './label/progress-label.svelte';
4
+ import type ProgressRootComponent from './root/progress-root.svelte';
5
+ import type ProgressTrackComponent from './track/progress-track.svelte';
6
+ import type ProgressValueComponent from './value/progress-value.svelte';
7
+ export * as Progress from './index.parts.js';
8
+ export { default as ProgressRoot } from './root/progress-root.svelte';
9
+ export { default as ProgressLabel } from './label/progress-label.svelte';
10
+ export { default as ProgressTrack } from './track/progress-track.svelte';
11
+ export { default as ProgressIndicator } from './indicator/progress-indicator.svelte';
12
+ export { default as ProgressValue } from './value/progress-value.svelte';
13
+ export type ProgressRootProps = ComponentProps<typeof ProgressRootComponent>;
14
+ export type ProgressLabelProps = ComponentProps<typeof ProgressLabelComponent>;
15
+ export type ProgressTrackProps = ComponentProps<typeof ProgressTrackComponent>;
16
+ export type ProgressIndicatorProps = ComponentProps<typeof ProgressIndicatorComponent>;
17
+ export type ProgressValueProps = ComponentProps<typeof ProgressValueComponent>;
18
+ export type { ProgressValueState } from './types.js';
19
+ export { getProgressContext, setProgressContext, useProgressContext, type ProgressContext, type ProgressOrientation, type ProgressStatus } from './root/context.js';
20
+ import * as ProgressParts from './index.parts.js';
21
+ export default ProgressParts;
@@ -0,0 +1,9 @@
1
+ export * as Progress from './index.parts.js';
2
+ export { default as ProgressRoot } from './root/progress-root.svelte';
3
+ export { default as ProgressLabel } from './label/progress-label.svelte';
4
+ export { default as ProgressTrack } from './track/progress-track.svelte';
5
+ export { default as ProgressIndicator } from './indicator/progress-indicator.svelte';
6
+ export { default as ProgressValue } from './value/progress-value.svelte';
7
+ export { getProgressContext, setProgressContext, useProgressContext } from './root/context.js';
8
+ import * as ProgressParts from './index.parts.js';
9
+ export default ProgressParts;
@@ -0,0 +1,5 @@
1
+ export { default as Root } from './root/progress-root.svelte';
2
+ export { default as Label } from './label/progress-label.svelte';
3
+ export { default as Track } from './track/progress-track.svelte';
4
+ export { default as Indicator } from './indicator/progress-indicator.svelte';
5
+ export { default as Value } from './value/progress-value.svelte';
@@ -0,0 +1,5 @@
1
+ export { default as Root } from './root/progress-root.svelte';
2
+ export { default as Label } from './label/progress-label.svelte';
3
+ export { default as Track } from './track/progress-track.svelte';
4
+ export { default as Indicator } from './indicator/progress-indicator.svelte';
5
+ export { default as Value } from './value/progress-value.svelte';
@@ -0,0 +1,37 @@
1
+ <script lang="ts">
2
+ import type { ProgressIndicatorProps } from '../types.js';
3
+ import { useProgressContext } from '../root/context';
4
+
5
+ /**
6
+ * Progress.Indicator — the part of the track that the task has done.
7
+ *
8
+ * It sizes itself to the percentage: the width from the start edge of a horizontal track, and
9
+ * the height from the bottom of a vertical one. The start edge follows the direction of the
10
+ * text, thus a right-to-left page fills from the right. An indeterminate progress gets no
11
+ * size: your CSS animates it.
12
+ */
13
+ let { children, class: className = '', style, ...restProps }: ProgressIndicatorProps = $props();
14
+
15
+ const progress = useProgressContext('Progress.Indicator');
16
+
17
+ const sizeStyle = $derived.by(() => {
18
+ if (progress.percent === null) return '';
19
+ if (progress.orientation === 'vertical') {
20
+ return `position: absolute; inset-inline: 0; bottom: 0; height: ${progress.percent}%;`;
21
+ }
22
+ return `position: absolute; inset-block: 0; inset-inline-start: 0; width: ${progress.percent}%;`;
23
+ });
24
+ </script>
25
+
26
+ <div
27
+ {...restProps}
28
+ class={className}
29
+ style="{sizeStyle}{style ? ` ${style}` : ''}"
30
+ data-progress-indicator="true"
31
+ data-orientation={progress.orientation}
32
+ data-progressing={progress.status === 'progressing' || undefined}
33
+ data-complete={progress.status === 'complete' || undefined}
34
+ data-indeterminate={progress.status === 'indeterminate' || undefined}
35
+ >
36
+ {@render children?.()}
37
+ </div>
@@ -0,0 +1,4 @@
1
+ import type { ProgressIndicatorProps } from '../types.js';
2
+ declare const ProgressIndicator: import("svelte").Component<ProgressIndicatorProps, {}, "">;
3
+ type ProgressIndicator = ReturnType<typeof ProgressIndicator>;
4
+ export default ProgressIndicator;
@@ -0,0 +1,34 @@
1
+ <script lang="ts">
2
+ import type { ProgressLabelProps } from '../types.js';
3
+ import { useProgressContext } from '../root/context';
4
+
5
+ /**
6
+ * Progress.Label — the name of the task.
7
+ *
8
+ * It registers its id with the root, which gives it to the progress bar as `aria-labelledby`.
9
+ * A bare text beside the bar leaves the bar unnamed: a `role="progressbar"` takes its name
10
+ * from `aria-labelledby` or `aria-label`, never from the text near it. It renders a `<span>`
11
+ * and not a `<label>`, because a `<label>` names a form control, and a progress bar is none.
12
+ */
13
+ let { children, class: className = '', id: idProp, ...restProps }: ProgressLabelProps = $props();
14
+
15
+ const progress = useProgressContext('Progress.Label');
16
+ const generatedId = $props.id();
17
+ const id = $derived(idProp ?? generatedId);
18
+
19
+ // The returned unregister runs on destroy, and again whenever the id changes.
20
+ $effect(() => progress.registerLabel(id));
21
+ </script>
22
+
23
+ <span
24
+ {...restProps}
25
+ {id}
26
+ class={className}
27
+ data-progress-label="true"
28
+ data-orientation={progress.orientation}
29
+ data-progressing={progress.status === 'progressing' || undefined}
30
+ data-complete={progress.status === 'complete' || undefined}
31
+ data-indeterminate={progress.status === 'indeterminate' || undefined}
32
+ >
33
+ {@render children?.()}
34
+ </span>
@@ -0,0 +1,4 @@
1
+ import type { ProgressLabelProps } from '../types.js';
2
+ declare const ProgressLabel: import("svelte").Component<ProgressLabelProps, {}, "">;
3
+ type ProgressLabel = ReturnType<typeof ProgressLabel>;
4
+ export default ProgressLabel;
@@ -0,0 +1,26 @@
1
+ import type { ProgressStatus } from './progress-utils';
2
+ export type ProgressOrientation = 'horizontal' | 'vertical';
3
+ export type ProgressContext = {
4
+ /** The id of the root element. */
5
+ id: string;
6
+ /** The value, held in the range. `null` while the progress is indeterminate. */
7
+ value: number | null;
8
+ min: number;
9
+ max: number;
10
+ /** The position in the range, from 0 to 100. `null` while the progress is indeterminate. */
11
+ percent: number | null;
12
+ status: ProgressStatus;
13
+ orientation: ProgressOrientation;
14
+ /** The value as text, for the user. Empty while the progress is indeterminate. */
15
+ formattedValue: string;
16
+ /** The text a screen reader gets for the value. */
17
+ valueText: string | undefined;
18
+ /** The ids of the registered labels, for `aria-labelledby`. */
19
+ labelledBy: string | undefined;
20
+ /** Registers a label id; the returned function unregisters it. */
21
+ registerLabel: (id: string) => () => void;
22
+ };
23
+ export declare function setProgressContext(context: ProgressContext): void;
24
+ export declare function getProgressContext(): ProgressContext | undefined;
25
+ export declare function useProgressContext(part?: string): ProgressContext;
26
+ export type { ProgressStatus };
@@ -0,0 +1,15 @@
1
+ import { getContext, setContext } from 'svelte';
2
+ const KEY = Symbol('progress');
3
+ export function setProgressContext(context) {
4
+ setContext(KEY, context);
5
+ }
6
+ export function getProgressContext() {
7
+ return getContext(KEY);
8
+ }
9
+ export function useProgressContext(part = 'Progress') {
10
+ const context = getProgressContext();
11
+ if (!context) {
12
+ throw new Error(`${part} must be used within Progress.Root.`);
13
+ }
14
+ return context;
15
+ }
@@ -0,0 +1,136 @@
1
+ <script lang="ts">
2
+ import { untrack } from 'svelte';
3
+ import { readable } from 'svelte/store';
4
+ import { useLocaleContextOptional } from '../../locale-provider/context';
5
+ import type { ProgressRootProps } from '../types.js';
6
+ import { setProgressContext, type ProgressContext } from './context';
7
+ import {
8
+ clampProgressValue,
9
+ formatProgressValue,
10
+ getProgressPercent,
11
+ getProgressStatus,
12
+ normalizeProgressValue
13
+ } from './progress-utils';
14
+
15
+ /**
16
+ * Progress.Root — the status of a task that takes time.
17
+ *
18
+ * It is the `role="progressbar"` element, and it holds the numbers for the parts in it. A
19
+ * screen reader reads its name and its value; it does not read the parts. The value is
20
+ * `aria-valuenow` with `aria-valuetext`, or nothing at all while the end of the task is not
21
+ * known: a number for an indeterminate progress would be a lie.
22
+ */
23
+ const generatedId = $props.id();
24
+
25
+ let {
26
+ id: idProp,
27
+ value: valueProp,
28
+ min = 0,
29
+ max = 100,
30
+ format,
31
+ getValueText,
32
+ 'aria-valuetext': ariaValueTextProp,
33
+ 'aria-labelledby': ariaLabelledBy,
34
+ orientation = 'horizontal',
35
+ children,
36
+ class: className = '',
37
+ element = $bindable<HTMLDivElement | null>(null),
38
+ context = $bindable(),
39
+ ...restProps
40
+ }: ProgressRootProps = $props();
41
+
42
+ const instanceId = untrack(() => idProp) ?? generatedId;
43
+
44
+ const localeContext = useLocaleContextOptional();
45
+ const emptyLocaleStore = readable<string | undefined>(undefined);
46
+ const localeStore = localeContext?.locale ?? emptyLocaleStore;
47
+
48
+ let rootRef: HTMLDivElement | null = $state(null);
49
+ let labelIds = $state<string[]>([]);
50
+
51
+ const rawValue = $derived(normalizeProgressValue(valueProp));
52
+ const value = $derived(rawValue === null ? null : clampProgressValue(rawValue, min, max));
53
+ const percent = $derived(rawValue === null ? null : getProgressPercent(rawValue, min, max));
54
+ const status = $derived(getProgressStatus(rawValue, min, max));
55
+ const formattedValue = $derived(formatProgressValue(rawValue, min, max, $localeStore, format));
56
+ const valueText = $derived.by(() => {
57
+ if (value === null) return undefined;
58
+ if (ariaValueTextProp !== undefined) return ariaValueTextProp;
59
+ if (getValueText) return getValueText(formattedValue, value);
60
+ return formattedValue;
61
+ });
62
+ const labelledBy = $derived(
63
+ ariaLabelledBy ?? (labelIds.length > 0 ? labelIds.join(' ') : undefined)
64
+ );
65
+
66
+ const progress: ProgressContext = {
67
+ get id() {
68
+ return instanceId;
69
+ },
70
+ get value() {
71
+ return value;
72
+ },
73
+ get min() {
74
+ return min;
75
+ },
76
+ get max() {
77
+ return max;
78
+ },
79
+ get percent() {
80
+ return percent;
81
+ },
82
+ get status() {
83
+ return status;
84
+ },
85
+ get orientation() {
86
+ return orientation;
87
+ },
88
+ get formattedValue() {
89
+ return formattedValue;
90
+ },
91
+ get valueText() {
92
+ return valueText;
93
+ },
94
+ get labelledBy() {
95
+ return labelledBy;
96
+ },
97
+ // `untrack` because the caller registers from an effect: reading `labelIds` here would
98
+ // make that effect depend on what it writes, and the pair would run without end.
99
+ registerLabel(id: string) {
100
+ untrack(() => {
101
+ labelIds = [...labelIds, id];
102
+ });
103
+ return () =>
104
+ untrack(() => {
105
+ labelIds = labelIds.filter((candidate) => candidate !== id);
106
+ });
107
+ }
108
+ };
109
+
110
+ setProgressContext(progress);
111
+ context = progress;
112
+
113
+ $effect(() => {
114
+ element = rootRef;
115
+ });
116
+ </script>
117
+
118
+ <div
119
+ {...restProps}
120
+ bind:this={rootRef}
121
+ id={instanceId}
122
+ role="progressbar"
123
+ aria-labelledby={labelledBy}
124
+ aria-valuemin={min}
125
+ aria-valuemax={max}
126
+ aria-valuenow={value ?? undefined}
127
+ aria-valuetext={valueText}
128
+ class={className}
129
+ data-progress-root="true"
130
+ data-orientation={orientation}
131
+ data-progressing={status === 'progressing' || undefined}
132
+ data-complete={status === 'complete' || undefined}
133
+ data-indeterminate={status === 'indeterminate' || undefined}
134
+ >
135
+ {@render children?.()}
136
+ </div>
@@ -0,0 +1,4 @@
1
+ import type { ProgressRootProps } from '../types.js';
2
+ declare const ProgressRoot: import("svelte").Component<ProgressRootProps, {}, "element" | "context">;
3
+ type ProgressRoot = ReturnType<typeof ProgressRoot>;
4
+ export default ProgressRoot;
@@ -0,0 +1,12 @@
1
+ export type ProgressStatus = 'progressing' | 'complete' | 'indeterminate';
2
+ /** A finite number is a value. Anything else keeps the progress indeterminate. */
3
+ export declare function normalizeProgressValue(value: number | null | undefined): number | null;
4
+ export declare function clampProgressValue(value: number, min: number, max: number): number;
5
+ /** The position of a value in the range, from 0 to 100. An empty range reads as 0. */
6
+ export declare function getProgressPercent(value: number, min: number, max: number): number;
7
+ export declare function getProgressStatus(value: number | null, min: number, max: number): ProgressStatus;
8
+ /**
9
+ * The text for a value. With `format`, it is the value in that format. Without it, it is the
10
+ * position in the range as a percentage: `31%` for 31 of 100, and for 62 of 200.
11
+ */
12
+ export declare function formatProgressValue(value: number | null, min: number, max: number, locale: string | undefined, format: Intl.NumberFormatOptions | undefined): string;
@@ -0,0 +1,41 @@
1
+ /** A finite number is a value. Anything else keeps the progress indeterminate. */
2
+ export function normalizeProgressValue(value) {
3
+ return typeof value === 'number' && Number.isFinite(value) ? value : null;
4
+ }
5
+ export function clampProgressValue(value, min, max) {
6
+ if (max < min)
7
+ return min;
8
+ return Math.min(max, Math.max(min, value));
9
+ }
10
+ /** The position of a value in the range, from 0 to 100. An empty range reads as 0. */
11
+ export function getProgressPercent(value, min, max) {
12
+ const span = max - min;
13
+ if (!(span > 0))
14
+ return 0;
15
+ const percent = ((clampProgressValue(value, min, max) - min) / span) * 100;
16
+ return Math.min(100, Math.max(0, percent));
17
+ }
18
+ export function getProgressStatus(value, min, max) {
19
+ if (value === null)
20
+ return 'indeterminate';
21
+ return clampProgressValue(value, min, max) >= max ? 'complete' : 'progressing';
22
+ }
23
+ function createFormatter(locale, options) {
24
+ try {
25
+ return new Intl.NumberFormat(locale, options);
26
+ }
27
+ catch {
28
+ return new Intl.NumberFormat(undefined, options);
29
+ }
30
+ }
31
+ /**
32
+ * The text for a value. With `format`, it is the value in that format. Without it, it is the
33
+ * position in the range as a percentage: `31%` for 31 of 100, and for 62 of 200.
34
+ */
35
+ export function formatProgressValue(value, min, max, locale, format) {
36
+ if (value === null)
37
+ return '';
38
+ if (format)
39
+ return createFormatter(locale, format).format(clampProgressValue(value, min, max));
40
+ return createFormatter(locale, { style: 'percent' }).format(getProgressPercent(value, min, max) / 100);
41
+ }
@@ -0,0 +1,27 @@
1
+ <script lang="ts">
2
+ import type { ProgressTrackProps } from '../types.js';
3
+ import { useProgressContext } from '../root/context';
4
+
5
+ /**
6
+ * Progress.Track — the full length of the task. The indicator fills a part of it.
7
+ *
8
+ * It is `position: relative` with `overflow: hidden`, thus the indicator takes its place in
9
+ * it with an inset, and an animated indeterminate indicator stays in it.
10
+ */
11
+ let { children, class: className = '', style, ...restProps }: ProgressTrackProps = $props();
12
+
13
+ const progress = useProgressContext('Progress.Track');
14
+ </script>
15
+
16
+ <div
17
+ {...restProps}
18
+ class={className}
19
+ style="position: relative; overflow: hidden;{style ? ` ${style}` : ''}"
20
+ data-progress-track="true"
21
+ data-orientation={progress.orientation}
22
+ data-progressing={progress.status === 'progressing' || undefined}
23
+ data-complete={progress.status === 'complete' || undefined}
24
+ data-indeterminate={progress.status === 'indeterminate' || undefined}
25
+ >
26
+ {@render children?.()}
27
+ </div>
@@ -0,0 +1,4 @@
1
+ import type { ProgressTrackProps } from '../types.js';
2
+ declare const ProgressTrack: import("svelte").Component<ProgressTrackProps, {}, "">;
3
+ type ProgressTrack = ReturnType<typeof ProgressTrack>;
4
+ export default ProgressTrack;