@xds/svelte 1.0.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (207) hide show
  1. .diffend-unextracted-0 +2 -1
  2. package/dist/Accordion.svelte +7 -2
  3. package/dist/Avatar.svelte +10 -2
  4. package/dist/AvatarStack.svelte +11 -1
  5. package/dist/Badge.svelte +14 -3
  6. package/dist/Banner.svelte +6 -1
  7. package/dist/Breadcrumb.svelte +53 -0
  8. package/dist/Breadcrumb.svelte.d.ts +11 -0
  9. package/dist/Button.svelte +30 -2
  10. package/dist/Button.svelte.d.ts +10 -1
  11. package/dist/Card.svelte +16 -2
  12. package/dist/Checkbox.svelte +62 -10
  13. package/dist/Checkbox.svelte.d.ts +14 -3
  14. package/dist/Chip.svelte +3 -1
  15. package/dist/ChipBar.svelte +3 -2
  16. package/dist/Combobox.svelte +194 -0
  17. package/dist/Combobox.svelte.d.ts +37 -0
  18. package/dist/CountBadge.svelte +4 -2
  19. package/dist/DatePicker.svelte +16 -5
  20. package/dist/DateRangePicker.svelte +6 -1
  21. package/dist/Dialog.svelte +9 -2
  22. package/dist/Divider.svelte +7 -3
  23. package/dist/EmptyState.svelte +15 -3
  24. package/dist/Icon.svelte +11 -2
  25. package/dist/IconButton.svelte +30 -2
  26. package/dist/IconButton.svelte.d.ts +10 -1
  27. package/dist/Labels.svelte +29 -0
  28. package/dist/Labels.svelte.d.ts +17 -0
  29. package/dist/Link.svelte +86 -0
  30. package/dist/Link.svelte.d.ts +26 -0
  31. package/dist/MediaCard.svelte +4 -1
  32. package/dist/Menu.svelte +21 -2
  33. package/dist/Pagination.svelte +108 -0
  34. package/dist/Pagination.svelte.d.ts +14 -0
  35. package/dist/PlaceRow.svelte +6 -1
  36. package/dist/Popover.svelte +91 -0
  37. package/dist/Popover.svelte.d.ts +21 -0
  38. package/dist/PopoverSurface.svelte +77 -0
  39. package/dist/PopoverSurface.svelte.d.ts +21 -0
  40. package/dist/ProgressBar.svelte +3 -1
  41. package/dist/RadioGroup.svelte +23 -8
  42. package/dist/RadioGroup.svelte.d.ts +4 -2
  43. package/dist/SearchField.svelte +65 -18
  44. package/dist/SearchField.svelte.d.ts +14 -4
  45. package/dist/SectionHeader.svelte +7 -2
  46. package/dist/SegmentedControl.svelte +21 -7
  47. package/dist/SegmentedControl.svelte.d.ts +3 -2
  48. package/dist/Select.svelte +64 -12
  49. package/dist/Select.svelte.d.ts +9 -2
  50. package/dist/Sidebar.svelte +3 -0
  51. package/dist/Skeleton.svelte +10 -2
  52. package/dist/Slider.svelte +23 -7
  53. package/dist/Slider.svelte.d.ts +2 -2
  54. package/dist/Spinner.svelte +3 -2
  55. package/dist/Switch.svelte +53 -9
  56. package/dist/Switch.svelte.d.ts +13 -3
  57. package/dist/Table.svelte +92 -0
  58. package/dist/Table.svelte.d.ts +17 -0
  59. package/dist/Tabs.svelte +21 -6
  60. package/dist/Tabs.svelte.d.ts +2 -1
  61. package/dist/Text.svelte +3 -1
  62. package/dist/TextField.svelte +59 -14
  63. package/dist/TextField.svelte.d.ts +13 -3
  64. package/dist/Thumbnail.svelte +7 -1
  65. package/dist/TimePicker.svelte +222 -0
  66. package/dist/TimePicker.svelte.d.ts +20 -0
  67. package/dist/Toast.svelte +12 -2
  68. package/dist/ToastQueue.svelte +57 -0
  69. package/dist/ToastQueue.svelte.d.ts +20 -0
  70. package/dist/Tooltip.svelte +9 -2
  71. package/dist/TooltipOverlay.svelte +9 -2
  72. package/dist/base.d.ts +14 -0
  73. package/dist/base.js +27 -0
  74. package/dist/controllable.svelte.d.ts +28 -0
  75. package/dist/controllable.svelte.js +41 -0
  76. package/dist/index.d.ts +12 -2
  77. package/dist/index.js +12 -0
  78. package/dist/labels.svelte.d.ts +13 -0
  79. package/dist/labels.svelte.js +24 -0
  80. package/dist/modal-popover.svelte.js +5 -1
  81. package/dist/presence.svelte.js +5 -2
  82. package/dist/preview/Component.svelte +8 -3
  83. package/dist/preview/Preview.svelte +8 -2
  84. package/dist/preview/Preview.svelte.d.ts +2 -0
  85. package/dist/preview/components.d.ts +9 -2
  86. package/dist/preview/components.js +18 -1
  87. package/dist/preview/index.d.ts +1 -0
  88. package/dist/root.d.ts +4 -2
  89. package/eject/files/Accordion.svelte +100 -0
  90. package/eject/files/AccordionPanel.svelte +48 -0
  91. package/eject/files/Avatar.svelte +51 -0
  92. package/eject/files/AvatarStack.svelte +61 -0
  93. package/eject/files/Badge.svelte +52 -0
  94. package/eject/files/Banner.svelte +94 -0
  95. package/eject/files/Breadcrumb.svelte +52 -0
  96. package/eject/files/Button.svelte +126 -0
  97. package/eject/files/Card.svelte +112 -0
  98. package/eject/files/Checkbox.svelte +121 -0
  99. package/eject/files/Chip.svelte +51 -0
  100. package/eject/files/ChipBar.svelte +39 -0
  101. package/eject/files/Combobox.svelte +198 -0
  102. package/eject/files/CountBadge.svelte +51 -0
  103. package/eject/files/DatePicker.svelte +213 -0
  104. package/eject/files/DateRangePicker.svelte +294 -0
  105. package/eject/files/Dialog.svelte +119 -0
  106. package/eject/files/Divider.svelte +27 -0
  107. package/eject/files/EmptyState.svelte +52 -0
  108. package/eject/files/Icon.svelte +51 -0
  109. package/eject/files/IconButton.svelte +99 -0
  110. package/eject/files/Link.svelte +85 -0
  111. package/eject/files/ListRow.svelte +33 -0
  112. package/eject/files/MediaCard.svelte +117 -0
  113. package/eject/files/Menu.svelte +183 -0
  114. package/eject/files/Pagination.svelte +109 -0
  115. package/eject/files/PlaceRow.svelte +75 -0
  116. package/eject/files/Popover.svelte +100 -0
  117. package/eject/files/PopoverSurface.svelte +85 -0
  118. package/eject/files/ProgressBar.svelte +38 -0
  119. package/eject/files/RadioGroup.svelte +133 -0
  120. package/eject/files/SearchField.svelte +154 -0
  121. package/eject/files/SectionHeader.svelte +67 -0
  122. package/eject/files/SegmentedControl.svelte +85 -0
  123. package/eject/files/Select.svelte +276 -0
  124. package/eject/files/Sidebar.svelte +130 -0
  125. package/eject/files/SidebarRailButton.svelte +32 -0
  126. package/eject/files/Skeleton.svelte +55 -0
  127. package/eject/files/Slider.svelte +136 -0
  128. package/eject/files/Spinner.svelte +41 -0
  129. package/eject/files/Switch.svelte +105 -0
  130. package/eject/files/Table.svelte +90 -0
  131. package/eject/files/Tabs.svelte +85 -0
  132. package/eject/files/Text.svelte +43 -0
  133. package/eject/files/TextField.svelte +222 -0
  134. package/eject/files/Thumbnail.svelte +88 -0
  135. package/eject/files/TimePicker.svelte +237 -0
  136. package/eject/files/Toast.svelte +98 -0
  137. package/eject/files/ToastQueue.svelte +61 -0
  138. package/eject/files/Tooltip.svelte +51 -0
  139. package/eject/files/TooltipOverlay.svelte +88 -0
  140. package/eject/files/accordion.css +89 -0
  141. package/eject/files/accordion.ts +67 -0
  142. package/eject/files/avatar-stack.ts +57 -0
  143. package/eject/files/avatar.ts +42 -0
  144. package/eject/files/badge.ts +30 -0
  145. package/eject/files/banner.ts +71 -0
  146. package/eject/files/base.css +38 -0
  147. package/eject/files/breadcrumb.css +51 -0
  148. package/eject/files/breadcrumb.ts +42 -0
  149. package/eject/files/button.css +241 -0
  150. package/eject/files/button.ts +106 -0
  151. package/eject/files/card.ts +58 -0
  152. package/eject/files/checkbox.ts +52 -0
  153. package/eject/files/chip-bar.ts +16 -0
  154. package/eject/files/chip.ts +35 -0
  155. package/eject/files/combobox.css +269 -0
  156. package/eject/files/combobox.ts +85 -0
  157. package/eject/files/count-badge.ts +32 -0
  158. package/eject/files/date-picker.css +375 -0
  159. package/eject/files/date-picker.ts +280 -0
  160. package/eject/files/date-range-picker.ts +338 -0
  161. package/eject/files/dialog.css +139 -0
  162. package/eject/files/dialog.ts +15 -0
  163. package/eject/files/divider.ts +5 -0
  164. package/eject/files/empty-state.ts +22 -0
  165. package/eject/files/icon.ts +36 -0
  166. package/eject/files/link.css +64 -0
  167. package/eject/files/link.ts +63 -0
  168. package/eject/files/list-row.ts +66 -0
  169. package/eject/files/media-card.ts +66 -0
  170. package/eject/files/menu.css +192 -0
  171. package/eject/files/menu.ts +84 -0
  172. package/eject/files/overlay.css +40 -0
  173. package/eject/files/pagination.css +106 -0
  174. package/eject/files/pagination.ts +68 -0
  175. package/eject/files/parts.ts +17 -0
  176. package/eject/files/popover.css +101 -0
  177. package/eject/files/popover.ts +37 -0
  178. package/eject/files/progress-bar.ts +26 -0
  179. package/eject/files/radio-group.css +184 -0
  180. package/eject/files/radio-group.ts +30 -0
  181. package/eject/files/section-header.ts +32 -0
  182. package/eject/files/segmented-control.ts +33 -0
  183. package/eject/files/select.css +347 -0
  184. package/eject/files/select.ts +77 -0
  185. package/eject/files/sidebar.ts +75 -0
  186. package/eject/files/skeleton.ts +51 -0
  187. package/eject/files/slider.css +160 -0
  188. package/eject/files/slider.ts +80 -0
  189. package/eject/files/spinner.ts +22 -0
  190. package/eject/files/switch.ts +45 -0
  191. package/eject/files/table.css +107 -0
  192. package/eject/files/table.ts +84 -0
  193. package/eject/files/tabs.css +120 -0
  194. package/eject/files/tabs.ts +37 -0
  195. package/eject/files/text-field.css +225 -0
  196. package/eject/files/text-field.ts +64 -0
  197. package/eject/files/text.ts +38 -0
  198. package/eject/files/thumbnail.ts +51 -0
  199. package/eject/files/time-picker.ts +113 -0
  200. package/eject/files/toast-queue.ts +64 -0
  201. package/eject/files/toast.ts +31 -0
  202. package/eject/files/tooltip.css +111 -0
  203. package/eject/files/tooltip.ts +21 -0
  204. package/eject/manifest.json +1053 -0
  205. package/package.json +12 -4
  206. package/styles.css +1064 -169
  207. package/tailwind.css +1295 -218
@@ -0,0 +1,222 @@
1
+ <!--
2
+ @component
3
+ A field for choosing a time of day. Closed, it looks like a Select with a clock: the chosen time
4
+ on the locale's own clock ("9:30 AM", "09:30"). Pressed, it opens the times from `min` to `max`,
5
+ `step` minutes apart, under itself, with the chosen one in view; choosing one calls `onChange`
6
+ with it as `HH:MM` and closes the list.
7
+
8
+ The field is a button that says it opens a list box, as a Select's does: the arrow keys move,
9
+ typing the hour jumps to it, and Enter chooses. Without `value` it keeps its own choice, from
10
+ `defaultValue`.
11
+ -->
12
+ <script module lang="ts">
13
+ import type { IsoTime, TimePickerBaseProps } from "@xds/core";
14
+ import type { RootProps } from "./root.js";
15
+
16
+ export type { IsoTime } from "@xds/core";
17
+
18
+ export type TimePickerProps = TimePickerBaseProps &
19
+ RootProps & {
20
+ /** Called with the chosen time, as `HH:MM` on a 24-hour clock. */
21
+ onChange?: (value: IsoTime) => void;
22
+ };
23
+ </script>
24
+
25
+ <script lang="ts">
26
+ import { space } from "@xds/tokens";
27
+ import {
28
+ classes,
29
+ createItemPropsCache,
30
+ keepListKeys,
31
+ readCssPx,
32
+ rootAttributes,
33
+ type SelectOption,
34
+ timeOptions,
35
+ timePickerIds,
36
+ timePickerLocale,
37
+ underlayLayerStyle,
38
+ } from "@xds/core";
39
+ import * as select from "@zag-js/select";
40
+ import { mergeProps, normalizeProps, useMachine } from "@zag-js/svelte";
41
+ import type { HTMLAttributes, HTMLLabelAttributes } from "svelte/elements";
42
+ import { controllable, followFormReset } from "./controllable.svelte.js";
43
+ import Icon from "./Icon.svelte";
44
+ import { modalPopover } from "./modal-popover.svelte.js";
45
+ import Portal from "./Portal.svelte";
46
+ import { createPresence } from "./presence.svelte.js";
47
+
48
+ type KeyHandler = (event: KeyboardEvent) => void;
49
+
50
+ // `value` stays in the rest, where whether it is given at all can be asked.
51
+ let {
52
+ label,
53
+ defaultValue,
54
+ min,
55
+ max,
56
+ step,
57
+ placeholder,
58
+ description,
59
+ error,
60
+ name,
61
+ disabled,
62
+ locale,
63
+ onChange,
64
+ class: className,
65
+ style,
66
+ ...rest
67
+ }: TimePickerProps = $props();
68
+
69
+ const control = controllable<IsoTime | undefined, IsoTime>(
70
+ () => rest,
71
+ "value",
72
+ () => rest.value,
73
+ () => defaultValue,
74
+ () => onChange,
75
+ );
76
+ const value = $derived(control.current);
77
+ let root = $state<HTMLDivElement>();
78
+ followFormReset(() => root, control);
79
+
80
+ const id = $props.id();
81
+ const ids = timePickerIds(id);
82
+ const invalid = $derived(error !== undefined);
83
+ const options = $derived(timeOptions({ min, max, step, value }, timePickerLocale(locale)));
84
+ const collection = $derived(
85
+ select.collection<SelectOption<IsoTime>>({
86
+ items: options,
87
+ itemToValue: (option) => option.value,
88
+ itemToString: (option) => option.label,
89
+ }),
90
+ );
91
+ const service = useMachine(select.machine, () => ({
92
+ id,
93
+ collection,
94
+ value: value === undefined ? [] : [value],
95
+ onValueChange: (details: select.ValueChangeDetails<SelectOption<IsoTime>>) => {
96
+ const next = details.value[0];
97
+ if (next !== undefined) control.set(next);
98
+ },
99
+ disabled,
100
+ invalid,
101
+ positioning: {
102
+ placement: "bottom-start" as const,
103
+ gutter: readCssPx(null, "--xds-space-1", space[1]),
104
+ sameWidth: true,
105
+ overflowPadding: readCssPx(null, "--xds-space-3", space[3]),
106
+ },
107
+ }));
108
+ const api = $derived(select.connect(service, normalizeProps));
109
+ // The rows' props as they last were while they draw the same, so that a step of the highlight
110
+ // sets the attributes and the handlers of the two rows it moves between, not of every row.
111
+ const keep = createItemPropsCache();
112
+ // As in Select: a handler taken from the machine when the key comes reads whether a search by
113
+ // typing is still under way.
114
+ const current = () => select.connect(service, normalizeProps);
115
+ // A span: the field is a button, which a <label> cannot point at.
116
+ const labelProps = $derived.by(() => {
117
+ const { for: _, ...rest } = api.getLabelProps() as HTMLLabelAttributes;
118
+ return rest as HTMLAttributes<HTMLSpanElement>;
119
+ });
120
+ const triggerProps = $derived.by(() => {
121
+ const {
122
+ role: _role,
123
+ "aria-invalid": _invalid,
124
+ "aria-required": _required,
125
+ onkeydown: _onKeyDown,
126
+ ...rest
127
+ } = api.getTriggerProps();
128
+ return {
129
+ ...rest,
130
+ onkeydown: (event: KeyboardEvent) => {
131
+ if (!api.open && (event.key === "Home" || event.key === "End")) return;
132
+ (current().getTriggerProps().onkeydown as KeyHandler | undefined)?.(event);
133
+ },
134
+ };
135
+ });
136
+ let positioner = $state<HTMLDivElement>();
137
+ let surface = $state<HTMLDivElement>();
138
+ modalPopover(
139
+ () => api.open,
140
+ () => positioner,
141
+ );
142
+ const present = createPresence(
143
+ () => api.open,
144
+ () => [surface],
145
+ );
146
+ const content = $derived.by(() => {
147
+ const { onkeydown: _onKeyDown, ...rest } = api.getContentProps();
148
+ return mergeProps(rest, {
149
+ onkeydown: (event: KeyboardEvent) => {
150
+ keepListKeys(event, surface, ".xds-time-picker__item:not([data-disabled])", (value) =>
151
+ api.setHighlightedValue(value),
152
+ );
153
+ (current().getContentProps().onkeydown as KeyHandler | undefined)?.(event);
154
+ },
155
+ });
156
+ });
157
+ </script>
158
+
159
+ <!-- Merged, so that the app's style joins any the machine writes on the root. -->
160
+ <div
161
+ bind:this={root}
162
+ {...mergeProps(api.getRootProps(), {
163
+ ...rootAttributes(rest),
164
+ class: classes("xds-time-picker", className),
165
+ style,
166
+ })}
167
+ >
168
+ <span {...labelProps} class="xds-time-picker__label">{label}</span>
169
+ <button
170
+ {...triggerProps}
171
+ aria-labelledby={`${ids.value} ${labelProps.id}`}
172
+ aria-describedby={invalid ? ids.error : description ? ids.description : undefined}
173
+ class="xds-time-picker__trigger"
174
+ >
175
+ <span {...api.getValueTextProps()} id={ids.value} class="xds-time-picker__value"
176
+ >{api.valueAsString || placeholder}</span
177
+ >
178
+ <Icon name="clock" size="sm" class="text-xds-field-placeholder" />
179
+ </button>
180
+ <div class="xds-time-picker__footer">
181
+ {#if !invalid && description}
182
+ <span id={ids.description} class="xds-time-picker__description">{description}</span>
183
+ {/if}
184
+ <span id={ids.error} class="xds-time-picker__error" aria-live="polite">{error}</span>
185
+ </div>
186
+ <!-- What a form submits: the time as HH:MM, where the field shows it on the locale's clock. -->
187
+ {#if name !== undefined}
188
+ <input type="hidden" {name} value={value ?? ""} />
189
+ {/if}
190
+ <Portal>
191
+ {#if api.open}
192
+ <!-- svelte-ignore a11y_no_static_element_interactions -->
193
+ <div
194
+ class="xds-time-picker__underlay"
195
+ style:--layer-index={underlayLayerStyle(api.getPositionerProps().style)?.["--layer-index"]}
196
+ onmousedown={(event) => event.preventDefault()}
197
+ ></div>
198
+ {/if}
199
+ <div {...api.getPositionerProps()} bind:this={positioner} class="xds-time-picker__positioner">
200
+ <div {...content} bind:this={surface} hidden={!present()} class="xds-time-picker__content">
201
+ <div {...api.getListProps()} class="xds-time-picker__list">
202
+ {#each collection.items as option (option.value)}
203
+ <div
204
+ {...keep(`item:${option.value}`, api.getItemProps({ item: option }))}
205
+ class="xds-time-picker__item"
206
+ >
207
+ <span class="xds-time-picker__item-words">
208
+ <span
209
+ {...keep(`text:${option.value}`, api.getItemTextProps({ item: option }))}
210
+ class="xds-time-picker__item-label">{option.label}</span
211
+ >
212
+ </span>
213
+ {#if api.getItemState({ item: option }).selected}
214
+ <Icon name="check" size="sm" />
215
+ {/if}
216
+ </div>
217
+ {/each}
218
+ </div>
219
+ </div>
220
+ </div>
221
+ </Portal>
222
+ </div>
@@ -0,0 +1,20 @@
1
+ import type { IsoTime, TimePickerBaseProps } from "@xds/core";
2
+ import type { RootProps } from "./root.js";
3
+ export type { IsoTime } from "@xds/core";
4
+ export type TimePickerProps = TimePickerBaseProps & RootProps & {
5
+ /** Called with the chosen time, as `HH:MM` on a 24-hour clock. */
6
+ onChange?: (value: IsoTime) => void;
7
+ };
8
+ /**
9
+ * A field for choosing a time of day. Closed, it looks like a Select with a clock: the chosen time
10
+ * on the locale's own clock ("9:30 AM", "09:30"). Pressed, it opens the times from `min` to `max`,
11
+ * `step` minutes apart, under itself, with the chosen one in view; choosing one calls `onChange`
12
+ * with it as `HH:MM` and closes the list.
13
+ *
14
+ * The field is a button that says it opens a list box, as a Select's does: the arrow keys move,
15
+ * typing the hour jumps to it, and Enter chooses. Without `value` it keeps its own choice, from
16
+ * `defaultValue`.
17
+ */
18
+ declare const TimePicker: import("svelte").Component<TimePickerProps, {}, "">;
19
+ type TimePicker = ReturnType<typeof TimePicker>;
20
+ export default TimePicker;
package/dist/Toast.svelte CHANGED
@@ -20,10 +20,19 @@
20
20
 
21
21
  <script lang="ts">
22
22
  import { motion } from "@xds/tokens";
23
- import { classes, readCssMs, rootPart, TOAST_PARTS } from "@xds/core";
23
+ import { classes, readCssMs, rootAttributes, rootPart, TOAST_PARTS } from "@xds/core";
24
24
  import type { Attachment } from "svelte/attachments";
25
25
 
26
- let { open, message, action, duration, onClose, class: className, style }: ToastProps = $props();
26
+ let {
27
+ open,
28
+ message,
29
+ action,
30
+ duration,
31
+ onClose,
32
+ class: className,
33
+ style,
34
+ ...rest
35
+ }: ToastProps = $props();
27
36
 
28
37
  let regionElement = $state<HTMLDivElement>();
29
38
  // The toast the pointer is over and the one focus is in. A toast that closed under the pointer
@@ -60,6 +69,7 @@
60
69
  <!-- Hover and focus only pause the timer; the action inside is a real button. -->
61
70
  <!-- svelte-ignore a11y_no_static_element_interactions -->
62
71
  <div
72
+ {...rootAttributes(rest)}
63
73
  onpointerenter={(event) => (hovered = event.currentTarget)}
64
74
  onpointerleave={() => (hovered = undefined)}
65
75
  onfocusin={(event) => (focused = event.currentTarget)}
@@ -0,0 +1,57 @@
1
+ <!--
2
+ @component
3
+ Shows the app's toasts one at a time, in their order: the first of `toasts`, which stays for its
4
+ own `duration` or until its action is taken, and then the next, `motion.duration.normal` after the
5
+ one before has gone, so that each is read and announced as a message of its own. Add a toast
6
+ with `queueToast`, which keeps at most three waiting, and take one out in `onClose`. Put one
7
+ where a single Toast would go.
8
+ -->
9
+ <script module lang="ts">
10
+ import type { QueuedToast, ToastQueueBaseProps } from "@xds/core";
11
+ import type { RootProps } from "./root.js";
12
+
13
+ /** `class`, `style`, `id` and `data-*` go on the toast shown, as Toast takes them. */
14
+ export type ToastQueueProps = ToastQueueBaseProps &
15
+ RootProps & {
16
+ /**
17
+ * Called with a toast's id when its time is up or its action was taken. Take it out of
18
+ * `toasts` in it.
19
+ */
20
+ onClose: (id: QueuedToast["id"]) => void;
21
+ };
22
+ </script>
23
+
24
+ <script lang="ts">
25
+ import { motion } from "@xds/tokens";
26
+ import { readCssMs, toastQueueStep } from "@xds/core";
27
+ import Toast from "./Toast.svelte";
28
+
29
+ let { toasts, onClose, ...root }: ToastQueueProps = $props();
30
+
31
+ let visible = $state<QueuedToast["id"]>();
32
+ const step = $derived(toastQueueStep(toasts, visible));
33
+ const shown = $derived(step === "keep" ? toasts[0] : undefined);
34
+
35
+ $effect(() => {
36
+ const first = toasts[0];
37
+ if (step === "close") {
38
+ visible = undefined;
39
+ return;
40
+ }
41
+ if (step !== "wait" || first === undefined) return;
42
+ const gap = readCssMs(null, "--xds-motion-duration-normal", motion.duration.normal);
43
+ const timer = setTimeout(() => (visible = first.id), gap);
44
+ return () => clearTimeout(timer);
45
+ });
46
+ </script>
47
+
48
+ <Toast
49
+ {...root}
50
+ open={shown !== undefined}
51
+ message={shown?.message ?? ""}
52
+ action={shown?.action}
53
+ duration={shown?.duration}
54
+ onClose={() => {
55
+ if (shown !== undefined) onClose(shown.id);
56
+ }}
57
+ />
@@ -0,0 +1,20 @@
1
+ import type { QueuedToast, ToastQueueBaseProps } from "@xds/core";
2
+ import type { RootProps } from "./root.js";
3
+ /** `class`, `style`, `id` and `data-*` go on the toast shown, as Toast takes them. */
4
+ export type ToastQueueProps = ToastQueueBaseProps & RootProps & {
5
+ /**
6
+ * Called with a toast's id when its time is up or its action was taken. Take it out of
7
+ * `toasts` in it.
8
+ */
9
+ onClose: (id: QueuedToast["id"]) => void;
10
+ };
11
+ /**
12
+ * Shows the app's toasts one at a time, in their order: the first of `toasts`, which stays for its
13
+ * own `duration` or until its action is taken, and then the next, `motion.duration.normal` after the
14
+ * one before has gone, so that each is read and announced as a message of its own. Add a toast
15
+ * with `queueToast`, which keeps at most three waiting, and take one out in `onClose`. Put one
16
+ * where a single Toast would go.
17
+ */
18
+ declare const ToastQueue: import("svelte").Component<ToastQueueProps, {}, "">;
19
+ type ToastQueue = ReturnType<typeof ToastQueue>;
20
+ export default ToastQueue;
@@ -21,6 +21,7 @@
21
21
  </script>
22
22
 
23
23
  <script lang="ts">
24
+ import { rootAttributes } from "@xds/core";
24
25
  import TooltipOverlay from "./TooltipOverlay.svelte";
25
26
 
26
27
  let {
@@ -30,11 +31,17 @@
30
31
  class: className,
31
32
  style,
32
33
  children,
34
+ ...rest
33
35
  }: TooltipProps = $props();
34
36
  </script>
35
37
 
36
38
  <!-- The overlay gives the root part, `xds-tooltip`, to every tooltip, a collapsed Sidebar's
37
39
  too. -->
38
- <TooltipOverlay {label} {shortcut} placement={() => placement} class={className} {style}
39
- >{@render children()}</TooltipOverlay
40
+ <TooltipOverlay
41
+ {...rootAttributes(rest)}
42
+ {label}
43
+ {shortcut}
44
+ placement={() => placement}
45
+ class={className}
46
+ {style}>{@render children()}</TooltipOverlay
40
47
  >
@@ -6,7 +6,7 @@
6
6
  -->
7
7
  <script lang="ts">
8
8
  import { motion, space } from "@xds/tokens";
9
- import { classes, readCssMs, readCssPx } from "@xds/core";
9
+ import { classes, readCssMs, readCssPx, rootAttributes } from "@xds/core";
10
10
  import { mergeProps, normalizeProps, useMachine } from "@zag-js/svelte";
11
11
  import * as tooltip from "@zag-js/tooltip";
12
12
  import type { Snippet } from "svelte";
@@ -22,6 +22,7 @@
22
22
  class: className,
23
23
  style,
24
24
  children,
25
+ ...rest
25
26
  }: RootProps & {
26
27
  label: string;
27
28
  shortcut?: string | undefined;
@@ -32,6 +33,8 @@
32
33
  const id = $props.id();
33
34
  const service = useMachine(tooltip.machine, () => ({
34
35
  id,
36
+ // The app's id names the tooltip, and the control's aria-describedby points there.
37
+ ids: rest.id === undefined ? undefined : { content: rest.id },
35
38
  openDelay: readCssMs(
36
39
  null,
37
40
  "--xds-motion-duration-tooltip-delay",
@@ -59,7 +62,11 @@
59
62
  <div {...api.getPositionerProps()} class="xds-tooltip__positioner">
60
63
  <!-- Shown until its exit animation ends; Zag would hide it as it closes. -->
61
64
  <div
62
- {...mergeProps(api.getContentProps(), { class: classes("xds-tooltip", className), style })}
65
+ {...mergeProps(api.getContentProps(), {
66
+ ...rootAttributes(rest),
67
+ class: classes("xds-tooltip", className),
68
+ style,
69
+ })}
63
70
  bind:this={content}
64
71
  hidden={false}
65
72
  >
package/dist/base.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ export { default as PlaceRow } from "./PlaceRow.svelte";
2
+ export { default as Portal } from "./Portal.svelte";
3
+ export { default as TooltipOverlay } from "./TooltipOverlay.svelte";
4
+ export { controllable, followFormReset } from "./controllable.svelte.js";
5
+ export { keepChecked, keepValue } from "./controlled.js";
6
+ export { useDefaults } from "./defaults.svelte.js";
7
+ export { useLabels } from "./labels.svelte.js";
8
+ export { modalPopover } from "./modal-popover.svelte.js";
9
+ export { createPicture } from "./picture.svelte.js";
10
+ export { createPresence } from "./presence.svelte.js";
11
+ export type { RootProps } from "./root.js";
12
+ export { provideTrigger, resetTrigger, type TriggerProps, withTrigger } from "./trigger.svelte.js";
13
+ export { type IconName, icons, motion, space } from "@xds/tokens";
14
+ export { AVATAR_SIZE, type AvatarSize, afterAnimations, buttonClass, type ComponentLabels, createItemPropsCache, DEFAULT_LABELS, focusWithoutRing, type IconSize, initials, keepListKeys, leaveEscapeToFields, PEER_FOCUS, PRESSABLE_ROW, pictureClass, readCssMs, readCssPx, type SelectOption, selectOptionIds, rootAttributes, switchClass, switchLabelClass, type ThumbnailRatio, type ToastAction, tooltipEndSide, underlayLayerStyle, } from "@xds/core";
package/dist/base.js ADDED
@@ -0,0 +1,27 @@
1
+ // What an ejected component takes from the library: the hooks and types the components share,
2
+ // the parts of a component that another draws, the classes and helpers of @xds/ui-core that a
3
+ // component's own recipe does not hold, and the token values a component reads. `xds eject`
4
+ // copies a component's own sources into an app; every other import of the copy comes from here
5
+ // (`@xds/svelte/base` once published), so the copy keeps working as the library moves on.
6
+ //
7
+ // What is here is public: a release that removes or changes a name breaks the apps that ejected
8
+ // a component that uses it, as a change to a component's props does.
9
+ // @if template
10
+ // npm/web/eject.test.ts fails when a copy imports a name that is not here, and when a name here
11
+ // is used by no copy.
12
+ // @endif
13
+ // keep-sorted start block=yes by_regex=['from "([^"]+)"']
14
+ export { default as PlaceRow } from "./PlaceRow.svelte";
15
+ export { default as Portal } from "./Portal.svelte";
16
+ export { default as TooltipOverlay } from "./TooltipOverlay.svelte";
17
+ export { controllable, followFormReset } from "./controllable.svelte.js";
18
+ export { keepChecked, keepValue } from "./controlled.js";
19
+ export { useDefaults } from "./defaults.svelte.js";
20
+ export { useLabels } from "./labels.svelte.js";
21
+ export { modalPopover } from "./modal-popover.svelte.js";
22
+ export { createPicture } from "./picture.svelte.js";
23
+ export { createPresence } from "./presence.svelte.js";
24
+ export { provideTrigger, resetTrigger, withTrigger } from "./trigger.svelte.js";
25
+ export { icons, motion, space } from "@xds/tokens";
26
+ export { AVATAR_SIZE, afterAnimations, buttonClass, createItemPropsCache, DEFAULT_LABELS, focusWithoutRing, initials, keepListKeys, leaveEscapeToFields, PEER_FOCUS, PRESSABLE_ROW, pictureClass, readCssMs, readCssPx, selectOptionIds, rootAttributes, switchClass, switchLabelClass, tooltipEndSide, underlayLayerStyle, } from "@xds/core";
27
+ // keep-sorted end
@@ -0,0 +1,28 @@
1
+ /**
2
+ * The state of a control that the app may keep or leave to it (see `controllable`). A change is
3
+ * an `S`, which may be narrower than the state: a group with nothing chosen is changed only to a
4
+ * choice.
5
+ */
6
+ export type Controllable<T, S extends T = T> = {
7
+ /** Whether the app keeps the state: it gives the prop, even as `undefined`. */
8
+ readonly controlled: boolean;
9
+ /** The app's value while it keeps it, the control's own otherwise. */
10
+ readonly current: T;
11
+ /** Takes a change: the control keeps it unless the app does, and `onChange` hears it. */
12
+ set(next: S): void;
13
+ /** Puts the control's own state back to its default. */
14
+ reset(): void;
15
+ };
16
+ /**
17
+ * The state of a control that the app may keep or leave to it. It is the app's while `props`,
18
+ * the component's rest props, hold `name`, even as `undefined`, and the control's own otherwise,
19
+ * starting from `initial`. Either way a change goes to `onChange`. Call it while the component is
20
+ * set up.
21
+ */
22
+ export declare function controllable<T, S extends T = T>(props: () => object, name: string, given: () => T, initial: () => T, onChange: () => ((value: S) => void) | undefined): Controllable<T, S>;
23
+ /**
24
+ * Sets a control that keeps its own state back to its default when its form is reset, as the
25
+ * form sets the native field back. A controlled one shows what its owner gives it, whatever the
26
+ * form does. Call it while the component is set up.
27
+ */
28
+ export declare function followFormReset(element: () => Element | undefined, state: Pick<Controllable<unknown>, "controlled" | "reset">): void;
@@ -0,0 +1,41 @@
1
+ import { isControlled, onFormReset } from "@xds/core";
2
+ /**
3
+ * The state of a control that the app may keep or leave to it. It is the app's while `props`,
4
+ * the component's rest props, hold `name`, even as `undefined`, and the control's own otherwise,
5
+ * starting from `initial`. Either way a change goes to `onChange`. Call it while the component is
6
+ * set up.
7
+ */
8
+ export function controllable(props, name, given, initial, onChange) {
9
+ // Asked again on each read: Svelte's props answer `in` from what the owner passes now.
10
+ const controlled = $derived(isControlled(props(), name));
11
+ let own = $state.raw(initial());
12
+ const current = $derived(controlled ? given() : own);
13
+ return {
14
+ get controlled() {
15
+ return controlled;
16
+ },
17
+ get current() {
18
+ return current;
19
+ },
20
+ set(next) {
21
+ if (!controlled)
22
+ own = next;
23
+ onChange()?.(next);
24
+ },
25
+ reset() {
26
+ own = initial();
27
+ },
28
+ };
29
+ }
30
+ /**
31
+ * Sets a control that keeps its own state back to its default when its form is reset, as the
32
+ * form sets the native field back. A controlled one shows what its owner gives it, whatever the
33
+ * form does. Call it while the component is set up.
34
+ */
35
+ export function followFormReset(element, state) {
36
+ $effect(() => {
37
+ if (state.controlled)
38
+ return;
39
+ return onFormReset(element(), () => state.reset());
40
+ });
41
+ }
package/dist/index.d.ts CHANGED
@@ -1,14 +1,15 @@
1
- export type { IconName, IconSize, TextTone, TextVariant } from "@xds/core";
2
1
  export { default as Accordion, type AccordionItem, type AccordionProps } from "./Accordion.svelte";
3
2
  export { default as Avatar, type AvatarProps, type AvatarSize } from "./Avatar.svelte";
4
3
  export { default as AvatarStack, type AvatarStackProps } from "./AvatarStack.svelte";
5
4
  export { default as Badge, type BadgeProps, type BadgeTone } from "./Badge.svelte";
6
5
  export { default as Banner, type BannerProps, type BannerTone } from "./Banner.svelte";
6
+ export { type BreadcrumbItem, type BreadcrumbProps, default as Breadcrumb, } from "./Breadcrumb.svelte";
7
7
  export { default as Button, type ButtonProps, type ButtonVariant, type ControlSize, } from "./Button.svelte";
8
8
  export { default as Card, type CardProps } from "./Card.svelte";
9
9
  export { default as Checkbox, type CheckboxProps } from "./Checkbox.svelte";
10
10
  export { default as Chip, type ChipProps } from "./Chip.svelte";
11
11
  export { default as ChipBar, type ChipBarProps } from "./ChipBar.svelte";
12
+ export { default as Combobox, type ComboboxProps } from "./Combobox.svelte";
12
13
  export { default as CountBadge, type CountBadgeProps } from "./CountBadge.svelte";
13
14
  export { default as DatePicker, type DatePickerProps, type IsoDate } from "./DatePicker.svelte";
14
15
  export { type DateRange, default as DateRangePicker, type DateRangePickerProps, } from "./DateRangePicker.svelte";
@@ -18,12 +19,15 @@ export { default as Divider, type DividerProps } from "./Divider.svelte";
18
19
  export { default as EmptyState, type EmptyStateProps } from "./EmptyState.svelte";
19
20
  export { default as Icon, type IconProps } from "./Icon.svelte";
20
21
  export { default as IconButton, type IconButtonProps } from "./IconButton.svelte";
22
+ export { type ComponentLabels, default as Labels, type LabelsProps } from "./Labels.svelte";
23
+ export { default as Link, type LinkProps } from "./Link.svelte";
21
24
  export { default as ListRow, type ListRowProps } from "./ListRow.svelte";
22
25
  export { default as MediaCard, type MediaCardProps } from "./MediaCard.svelte";
23
26
  export { default as Menu, type MenuItem, type MenuProps } from "./Menu.svelte";
27
+ export { default as Pagination, type PaginationProps } from "./Pagination.svelte";
28
+ export { default as Popover, type PopoverProps } from "./Popover.svelte";
24
29
  export { default as ProgressBar, type ProgressBarProps } from "./ProgressBar.svelte";
25
30
  export { default as RadioGroup, type RadioGroupProps, type RadioOption } from "./RadioGroup.svelte";
26
- export type { RootProps } from "./root.js";
27
31
  export { default as SearchField, type SearchFieldProps } from "./SearchField.svelte";
28
32
  export { default as SectionHeader, type SectionHeaderProps } from "./SectionHeader.svelte";
29
33
  export { default as SegmentedControl, type SegmentedControlProps } from "./SegmentedControl.svelte";
@@ -33,9 +37,15 @@ export { default as Skeleton, type SkeletonProps } from "./Skeleton.svelte";
33
37
  export { default as Slider, type SliderProps } from "./Slider.svelte";
34
38
  export { default as Spinner, type SpinnerProps } from "./Spinner.svelte";
35
39
  export { default as Switch, type SwitchProps } from "./Switch.svelte";
40
+ export { type SortDirection, default as Table, type TableColumn, type TableProps, type TableRow, type TableSort, } from "./Table.svelte";
36
41
  export { default as Tabs, type TabsProps } from "./Tabs.svelte";
37
42
  export { default as Text, type TextProps } from "./Text.svelte";
38
43
  export { default as TextField, type TextFieldProps } from "./TextField.svelte";
39
44
  export { default as Thumbnail, type ThumbnailProps, type ThumbnailRatio } from "./Thumbnail.svelte";
45
+ export { type IsoTime, default as TimePicker, type TimePickerProps } from "./TimePicker.svelte";
40
46
  export { default as Toast, type ToastProps } from "./Toast.svelte";
47
+ export { default as ToastQueue, type ToastQueueProps } from "./ToastQueue.svelte";
41
48
  export { default as Tooltip, type TooltipProps } from "./Tooltip.svelte";
49
+ export type { RootProps } from "./root.js";
50
+ export type { IconName, IconSize, TextTone, TextVariant } from "@xds/core";
51
+ export { type QueuedToast, queueToast } from "@xds/core";
package/dist/index.js CHANGED
@@ -6,16 +6,19 @@
6
6
  // @xds/ui-vue, the React Native ones in @xds/ui-native, the GPUI ones in the xds-ui crate and
7
7
  // the Compose ones under kotlin/ui. All of them take the same variants, sizes and tones, and draw
8
8
  // them from the same design tokens.
9
+ // keep-sorted start block=yes by_regex=['from "([^"]+)"']
9
10
  export { default as Accordion } from "./Accordion.svelte";
10
11
  export { default as Avatar } from "./Avatar.svelte";
11
12
  export { default as AvatarStack } from "./AvatarStack.svelte";
12
13
  export { default as Badge } from "./Badge.svelte";
13
14
  export { default as Banner } from "./Banner.svelte";
15
+ export { default as Breadcrumb, } from "./Breadcrumb.svelte";
14
16
  export { default as Button, } from "./Button.svelte";
15
17
  export { default as Card } from "./Card.svelte";
16
18
  export { default as Checkbox } from "./Checkbox.svelte";
17
19
  export { default as Chip } from "./Chip.svelte";
18
20
  export { default as ChipBar } from "./ChipBar.svelte";
21
+ export { default as Combobox } from "./Combobox.svelte";
19
22
  export { default as CountBadge } from "./CountBadge.svelte";
20
23
  export { default as DatePicker } from "./DatePicker.svelte";
21
24
  export { default as DateRangePicker, } from "./DateRangePicker.svelte";
@@ -25,9 +28,13 @@ export { default as Divider } from "./Divider.svelte";
25
28
  export { default as EmptyState } from "./EmptyState.svelte";
26
29
  export { default as Icon } from "./Icon.svelte";
27
30
  export { default as IconButton } from "./IconButton.svelte";
31
+ export { default as Labels } from "./Labels.svelte";
32
+ export { default as Link } from "./Link.svelte";
28
33
  export { default as ListRow } from "./ListRow.svelte";
29
34
  export { default as MediaCard } from "./MediaCard.svelte";
30
35
  export { default as Menu } from "./Menu.svelte";
36
+ export { default as Pagination } from "./Pagination.svelte";
37
+ export { default as Popover } from "./Popover.svelte";
31
38
  export { default as ProgressBar } from "./ProgressBar.svelte";
32
39
  export { default as RadioGroup } from "./RadioGroup.svelte";
33
40
  export { default as SearchField } from "./SearchField.svelte";
@@ -39,9 +46,14 @@ export { default as Skeleton } from "./Skeleton.svelte";
39
46
  export { default as Slider } from "./Slider.svelte";
40
47
  export { default as Spinner } from "./Spinner.svelte";
41
48
  export { default as Switch } from "./Switch.svelte";
49
+ export { default as Table, } from "./Table.svelte";
42
50
  export { default as Tabs } from "./Tabs.svelte";
43
51
  export { default as Text } from "./Text.svelte";
44
52
  export { default as TextField } from "./TextField.svelte";
45
53
  export { default as Thumbnail } from "./Thumbnail.svelte";
54
+ export { default as TimePicker } from "./TimePicker.svelte";
46
55
  export { default as Toast } from "./Toast.svelte";
56
+ export { default as ToastQueue } from "./ToastQueue.svelte";
47
57
  export { default as Tooltip } from "./Tooltip.svelte";
58
+ export { queueToast } from "@xds/core";
59
+ // keep-sorted end
@@ -0,0 +1,13 @@
1
+ import { type ComponentLabels } from "@xds/core";
2
+ type Labels = () => ComponentLabels;
3
+ /**
4
+ * For Labels: gives the components inside it the labels around it, with those of `own`
5
+ * replaced. Call it while the component is set up.
6
+ */
7
+ export declare function provideLabels(own: () => Partial<ComponentLabels>): void;
8
+ /**
9
+ * For a component with labels of its own: the labels of the closest Labels, or the English ones.
10
+ * Call it while the component is set up; the result follows the providers' values.
11
+ */
12
+ export declare function useLabels(): Labels;
13
+ export {};