@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,194 @@
1
+ <!--
2
+ @component
3
+ A field for choosing one option from a list by typing part of its name. As the person types, the
4
+ options whose label holds what was typed open under it, those that start with it first, and the
5
+ first is highlighted, so Enter chooses it. Choosing an option calls `onChange`, puts its label in
6
+ the field and closes the list. Text that names no option goes back to the chosen option's label
7
+ when the field is left. When nothing matches, the list says so. Without `value` it keeps its own
8
+ choice, from `defaultValue`.
9
+ -->
10
+ <script module lang="ts">
11
+ import type { ComboboxBaseProps } from "@xds/core";
12
+ import type { RootProps } from "./root.js";
13
+
14
+ export type ComboboxProps<Value extends string = string> = ComboboxBaseProps<Value> &
15
+ RootProps & {
16
+ onChange?: (value: Value) => void;
17
+ };
18
+ </script>
19
+
20
+ <script lang="ts" generics="Value extends string = string">
21
+ import { space } from "@xds/tokens";
22
+ import {
23
+ COMBOBOX_PARTS as PARTS,
24
+ classes,
25
+ createItemPropsCache,
26
+ matchOptions,
27
+ readCssPx,
28
+ rootAttributes,
29
+ type SelectOption,
30
+ selectOptionIds,
31
+ } from "@xds/core";
32
+ import * as combobox from "@zag-js/combobox";
33
+ import { mergeProps, normalizeProps, useMachine } from "@zag-js/svelte";
34
+ import { controllable, followFormReset } from "./controllable.svelte.js";
35
+ import Icon from "./Icon.svelte";
36
+ import { useLabels } from "./labels.svelte.js";
37
+ import Portal from "./Portal.svelte";
38
+
39
+ let {
40
+ label,
41
+ options,
42
+ defaultValue,
43
+ placeholder,
44
+ description,
45
+ error,
46
+ name,
47
+ disabled,
48
+ onChange,
49
+ emptyLabel,
50
+ class: className,
51
+ style,
52
+ ...rest
53
+ }: ComboboxProps<Value> = $props();
54
+
55
+ const labels = useLabels();
56
+ const control = controllable<Value | undefined, Value>(
57
+ () => rest,
58
+ "value",
59
+ () => rest.value,
60
+ () => defaultValue,
61
+ () => onChange,
62
+ );
63
+ const value = $derived(control.current);
64
+ let root = $state<HTMLDivElement>();
65
+ followFormReset(() => root, control);
66
+
67
+ const id = $props.id();
68
+ const descriptionId = `${id}-description`;
69
+ const errorId = `${id}-error`;
70
+ const invalid = $derived(error !== undefined);
71
+ // What the person typed, which narrows the list. Choosing an option puts its label in the field
72
+ // without narrowing it, so the list opens on every option again.
73
+ let query = $state("");
74
+ const shown = $derived(matchOptions(options, query));
75
+ const collection = $derived(
76
+ combobox.collection<SelectOption<Value>>({
77
+ items: shown,
78
+ itemToValue: (option) => option.value,
79
+ itemToString: (option) => option.label,
80
+ }),
81
+ );
82
+ const service = useMachine(combobox.machine, () => ({
83
+ id,
84
+ collection,
85
+ value: value === undefined ? [] : [value],
86
+ onValueChange: (details: combobox.ValueChangeDetails<SelectOption<Value>>) => {
87
+ const next = details.value[0];
88
+ if (next !== undefined) control.set(next as Value);
89
+ },
90
+ onInputValueChange: (details: combobox.InputValueChangeDetails) => {
91
+ if (details.reason === "input-change") query = details.inputValue;
92
+ },
93
+ onOpenChange: (details: combobox.OpenChangeDetails) => {
94
+ if (!details.open) query = "";
95
+ },
96
+ // The first match is highlighted as the person types, so Enter chooses it.
97
+ inputBehavior: "autohighlight" as const,
98
+ selectionBehavior: "replace" as const,
99
+ openOnClick: true,
100
+ disabled,
101
+ invalid,
102
+ placeholder,
103
+ positioning: {
104
+ placement: "bottom-start" as const,
105
+ gutter: readCssPx(null, "--xds-space-1", space[1]),
106
+ sameWidth: true,
107
+ overflowPadding: readCssPx(null, "--xds-space-3", space[3]),
108
+ },
109
+ }));
110
+ const api = $derived(combobox.connect(service, normalizeProps));
111
+ // The rows' props as they last were while they draw the same, so that a step of the highlight
112
+ // sets the attributes and the handlers of the two rows it moves between, not of every row.
113
+ const keep = createItemPropsCache();
114
+ // Zag puts the chosen label back only when the list closes by a press outside; after Escape,
115
+ // text that names no option would stay in a field that has left it.
116
+ const input = $derived(
117
+ mergeProps(api.getInputProps(), {
118
+ onblur: () => {
119
+ const chosen = options.find((option) => option.value === value)?.label ?? "";
120
+ const now = combobox.connect(service, normalizeProps);
121
+ if (now.inputValue !== chosen) now.setInputValue(chosen, "script");
122
+ },
123
+ }),
124
+ );
125
+ </script>
126
+
127
+ <!-- Merged, so that the app's style joins any the machine writes on the root. -->
128
+ <div
129
+ bind:this={root}
130
+ {...mergeProps(api.getRootProps(), {
131
+ ...rootAttributes(rest),
132
+ class: classes("xds-combobox", className),
133
+ style,
134
+ })}
135
+ >
136
+ <label {...api.getLabelProps()} class={PARTS.label}>{label}</label>
137
+ <div {...api.getControlProps()} class={PARTS.control}>
138
+ <input
139
+ {...input}
140
+ aria-describedby={invalid ? errorId : description ? descriptionId : undefined}
141
+ class={PARTS.input}
142
+ />
143
+ <Icon name="chevrons-up-down" size="sm" class={PARTS.icon} />
144
+ </div>
145
+ <div class={PARTS.footer}>
146
+ {#if !invalid && description}
147
+ <span id={descriptionId} class={PARTS.description}>{description}</span>
148
+ {/if}
149
+ <span id={errorId} class={PARTS.error} aria-live="polite">{error}</span>
150
+ </div>
151
+ <!-- What a form submits: the option's value, where the field holds its label. -->
152
+ {#if name !== undefined}
153
+ <input type="hidden" {name} value={value ?? ""} />
154
+ {/if}
155
+ <Portal>
156
+ <div {...api.getPositionerProps()} class={PARTS.positioner}>
157
+ <!-- Zag hides it while closed. It goes at once, with no animation out: it comes and goes as
158
+ the person types. -->
159
+ <div {...api.getContentProps()} class={PARTS.content}>
160
+ {#if shown.length === 0}
161
+ <div {...api.getEmptyProps()} class={PARTS.empty}>{emptyLabel ?? labels().noMatches}</div>
162
+ {:else}
163
+ <div {...api.getListProps()} class={PARTS.list}>
164
+ {#each shown as option, index (option.value)}
165
+ {@const ids = selectOptionIds(id, index)}
166
+ <div
167
+ {...keep(`item:${option.value}`, api.getItemProps({ item: option }))}
168
+ aria-labelledby={ids.label}
169
+ aria-describedby={option.description ? ids.description : undefined}
170
+ class={PARTS.item}
171
+ >
172
+ <span class={PARTS.itemWords}>
173
+ <span
174
+ {...keep(`text:${option.value}`, api.getItemTextProps({ item: option }))}
175
+ id={ids.label}
176
+ class={PARTS.itemLabel}>{option.label}</span
177
+ >
178
+ {#if option.description}
179
+ <span id={ids.description} class={PARTS.itemDescription}
180
+ >{option.description}</span
181
+ >
182
+ {/if}
183
+ </span>
184
+ {#if api.getItemState({ item: option }).selected}
185
+ <Icon name="check" size="sm" />
186
+ {/if}
187
+ </div>
188
+ {/each}
189
+ </div>
190
+ {/if}
191
+ </div>
192
+ </div>
193
+ </Portal>
194
+ </div>
@@ -0,0 +1,37 @@
1
+ import type { ComboboxBaseProps } from "@xds/core";
2
+ import type { RootProps } from "./root.js";
3
+ export type ComboboxProps<Value extends string = string> = ComboboxBaseProps<Value> & RootProps & {
4
+ onChange?: (value: Value) => void;
5
+ };
6
+ declare function $$render<Value extends string = string>(): {
7
+ props: ComboboxProps<Value>;
8
+ exports: {};
9
+ bindings: "";
10
+ slots: {};
11
+ events: {};
12
+ };
13
+ declare class __sveltets_Render<Value extends string = string> {
14
+ props(): ReturnType<typeof $$render<Value>>['props'];
15
+ events(): ReturnType<typeof $$render<Value>>['events'];
16
+ slots(): ReturnType<typeof $$render<Value>>['slots'];
17
+ bindings(): "";
18
+ exports(): {};
19
+ }
20
+ interface $$IsomorphicComponent {
21
+ new <Value extends string = string>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<Value>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<Value>['props']>, ReturnType<__sveltets_Render<Value>['events']>, ReturnType<__sveltets_Render<Value>['slots']>> & {
22
+ $$bindings?: ReturnType<__sveltets_Render<Value>['bindings']>;
23
+ } & ReturnType<__sveltets_Render<Value>['exports']>;
24
+ <Value extends string = string>(internal: unknown, props: ReturnType<__sveltets_Render<Value>['props']> & {}): ReturnType<__sveltets_Render<Value>['exports']>;
25
+ z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
26
+ }
27
+ /**
28
+ * A field for choosing one option from a list by typing part of its name. As the person types, the
29
+ * options whose label holds what was typed open under it, those that start with it first, and the
30
+ * first is highlighted, so Enter chooses it. Choosing an option calls `onChange`, puts its label in
31
+ * the field and closes the list. Text that names no option goes back to the chosen option's label
32
+ * when the field is left. When nothing matches, the list says so. Without `value` it keeps its own
33
+ * choice, from `defaultValue`.
34
+ */
35
+ declare const Combobox: $$IsomorphicComponent;
36
+ type Combobox<Value extends string = string> = InstanceType<typeof Combobox<Value>>;
37
+ export default Combobox;
@@ -21,10 +21,11 @@
21
21
  countBadgeAnchorClass,
22
22
  countBadgeClass,
23
23
  countBadgeText,
24
+ rootAttributes,
24
25
  rootPart,
25
26
  } from "@xds/core";
26
27
 
27
- let { count, max, label, class: className, style, children }: CountBadgeProps = $props();
28
+ let { count, max, label, class: className, style, children, ...rest }: CountBadgeProps = $props();
28
29
 
29
30
  // The root is the anchor around the child, or the badge itself when there is none.
30
31
  const root = $derived(classes(rootPart("CountBadge"), className));
@@ -33,6 +34,7 @@
33
34
  {#snippet badge(onChild: boolean)}
34
35
  {#if count > 0}
35
36
  <span
37
+ {...onChild ? {} : rootAttributes(rest)}
36
38
  role={label ? "img" : undefined}
37
39
  aria-label={label || undefined}
38
40
  class={classes(countBadgeClass(onChild), !onChild && root)}
@@ -42,7 +44,7 @@
42
44
  {/snippet}
43
45
 
44
46
  {#if children}
45
- <span class={classes(countBadgeAnchorClass, root)} {style}
47
+ <span {...rootAttributes(rest)} class={classes(countBadgeAnchorClass, root)} {style}
46
48
  >{@render children()}{@render badge(true)}</span
47
49
  >
48
50
  {:else}
@@ -39,12 +39,14 @@
39
39
  keepCalendarFocus,
40
40
  keepDayFocused,
41
41
  readCssPx,
42
+ rootAttributes,
42
43
  underlayLayerStyle,
43
44
  } from "@xds/core";
44
45
  import * as datePicker from "@zag-js/date-picker";
45
46
  import { mergeProps, normalizeProps, useMachine } from "@zag-js/svelte";
46
47
  import { untrack } from "svelte";
47
48
  import Icon from "./Icon.svelte";
49
+ import { useLabels } from "./labels.svelte.js";
48
50
  import { modalPopover } from "./modal-popover.svelte.js";
49
51
  import Portal from "./Portal.svelte";
50
52
  import { createPresence } from "./presence.svelte.js";
@@ -55,12 +57,14 @@
55
57
  const id = $props.id();
56
58
  const ids = datePickerIds(id);
57
59
  const locale = $derived(datePickerLocale(props.locale));
60
+ const labels = useLabels();
58
61
  const service = useMachine(datePicker.machine, () =>
59
62
  datePickerMachineProps(props, {
60
63
  id,
61
64
  locale,
62
65
  onChange,
63
66
  gutter: readCssPx(null, "--xds-space-1", space[1]),
67
+ labels: labels(),
64
68
  }),
65
69
  );
66
70
  const api = $derived(datePicker.connect(service, normalizeProps));
@@ -76,20 +80,27 @@
76
80
  () => api.open,
77
81
  () => [surface],
78
82
  );
79
- // Strings, so that the effect below runs only when the focused day or the month changes, not
80
- // on every change of the machine.
83
+ // Derived, so that the effect below runs only when the calendar opens or closes or the focused
84
+ // day or the month changes, not on every change of the machine.
85
+ const open = $derived(api.open);
81
86
  const focused = $derived(api.focusedValue.toString());
82
87
  const month = $derived(api.visibleRange.start.toString());
83
88
  $effect(() => {
84
- const open = api.open;
89
+ const isOpen = open;
85
90
  void focused;
86
91
  void month;
87
- untrack(() => keepDayFocused(open, surface));
92
+ untrack(() => keepDayFocused(isOpen, surface));
88
93
  });
89
94
  </script>
90
95
 
91
96
  <!-- Merged, so that the app's style joins any the machine writes on the root. -->
92
- <div {...mergeProps(api.getRootProps(), { class: classes("xds-date-picker", className), style })}>
97
+ <div
98
+ {...mergeProps(api.getRootProps(), {
99
+ ...rootAttributes(props),
100
+ class: classes("xds-date-picker", className),
101
+ style,
102
+ })}
103
+ >
93
104
  <!-- A span: the field is a button, which a <label> cannot point at. -->
94
105
  <span id={ids.label} class="xds-date-picker__label">{props.label}</span>
95
106
  <!-- What Zag places the calendar against. -->
@@ -50,6 +50,7 @@
50
50
  rangeMonthViews,
51
51
  rangeSummary,
52
52
  readCssPx,
53
+ rootAttributes,
53
54
  shownRange,
54
55
  underlayLayerStyle,
55
56
  } from "@xds/core";
@@ -57,6 +58,7 @@
57
58
  import { mergeProps, normalizeProps, useMachine } from "@zag-js/svelte";
58
59
  import { untrack } from "svelte";
59
60
  import Icon from "./Icon.svelte";
61
+ import { useLabels } from "./labels.svelte.js";
60
62
  import { modalPopover } from "./modal-popover.svelte.js";
61
63
  import Portal from "./Portal.svelte";
62
64
  import { createPresence } from "./presence.svelte.js";
@@ -67,6 +69,7 @@
67
69
  const id = $props.id();
68
70
  const ids = datePickerIds(id);
69
71
  const locale = $derived(datePickerLocale(props.locale));
72
+ const labels = useLabels();
70
73
  // A start alone while the end is chosen; null while the calendar shows the chosen range.
71
74
  let draft = $state.raw<RangeDraft | null>(null);
72
75
  let months = $state(1);
@@ -79,12 +82,13 @@
79
82
  onDraft: (next) => (draft = next),
80
83
  onChange,
81
84
  gutter: readCssPx(null, "--xds-space-1", space[1]),
85
+ labels: labels(),
82
86
  }),
83
87
  );
84
88
  const api = $derived(datePicker.connect(service, normalizeProps));
85
89
  const trigger = $derived(api.getTriggerProps());
86
90
  const invalid = $derived(props.error !== undefined);
87
- const summary = $derived(rangeSummary(shown, props, locale));
91
+ const summary = $derived(rangeSummary(shown, props, locale, labels()));
88
92
  const views = $derived(rangeMonthViews(api, months));
89
93
  let positioner = $state<HTMLDivElement>();
90
94
  let surface = $state<HTMLDivElement>();
@@ -120,6 +124,7 @@
120
124
  <!-- Merged, so that the app's style joins any the machine writes on the root. -->
121
125
  <div
122
126
  {...mergeProps(api.getRootProps(), {
127
+ ...rootAttributes(props),
123
128
  class: classes("xds-date-picker xds-date-range-picker", className),
124
129
  style,
125
130
  })}
@@ -24,7 +24,7 @@
24
24
  </script>
25
25
 
26
26
  <script lang="ts">
27
- import { classes, leaveEscapeToFields } from "@xds/core";
27
+ import { classes, leaveEscapeToFields, rootAttributes } from "@xds/core";
28
28
  import * as dialog from "@zag-js/dialog";
29
29
  import { mergeProps, normalizeProps, useMachine } from "@zag-js/svelte";
30
30
  import Portal from "./Portal.svelte";
@@ -41,6 +41,7 @@
41
41
  style,
42
42
  children,
43
43
  actions,
44
+ ...rest
44
45
  }: DialogProps = $props();
45
46
 
46
47
  const id = $props.id();
@@ -49,6 +50,8 @@
49
50
  let content = $state<HTMLElement>();
50
51
  const service = useMachine(dialog.machine, () => ({
51
52
  id,
53
+ // The app's id names the dialog, and what Zag points at it points there.
54
+ ids: rest.id === undefined ? undefined : { content: rest.id },
52
55
  open,
53
56
  onOpenChange: (details: dialog.OpenChangeDetails) => {
54
57
  if (!details.open) onClose();
@@ -84,7 +87,11 @@
84
87
  ></div>
85
88
  <div {...api.getPositionerProps()} bind:this={positioner} class="xds-dialog__positioner">
86
89
  <section
87
- {...mergeProps(api.getContentProps(), { class: classes("xds-dialog", className), style })}
90
+ {...mergeProps(api.getContentProps(), {
91
+ ...rootAttributes(rest),
92
+ class: classes("xds-dialog", className),
93
+ style,
94
+ })}
88
95
  bind:this={content}
89
96
  hidden={false}
90
97
  >
@@ -9,9 +9,13 @@
9
9
  </script>
10
10
 
11
11
  <script lang="ts">
12
- import { classes, dividerClass, rootPart } from "@xds/core";
12
+ import { classes, dividerClass, rootAttributes, rootPart } from "@xds/core";
13
13
 
14
- let { class: className, style }: DividerProps = $props();
14
+ let { class: className, style, ...rest }: DividerProps = $props();
15
15
  </script>
16
16
 
17
- <hr class={classes(rootPart("Divider"), dividerClass, className)} {style} />
17
+ <hr
18
+ {...rootAttributes(rest)}
19
+ class={classes(rootPart("Divider"), dividerClass, className)}
20
+ {style}
21
+ />
@@ -16,13 +16,25 @@
16
16
  </script>
17
17
 
18
18
  <script lang="ts">
19
- import { classes, EMPTY_STATE_PARTS, rootPart } from "@xds/core";
19
+ import { classes, EMPTY_STATE_PARTS, rootAttributes, rootPart } from "@xds/core";
20
20
  import Icon from "./Icon.svelte";
21
21
 
22
- let { icon, title, description, action, class: className, style }: EmptyStateProps = $props();
22
+ let {
23
+ icon,
24
+ title,
25
+ description,
26
+ action,
27
+ class: className,
28
+ style,
29
+ ...rest
30
+ }: EmptyStateProps = $props();
23
31
  </script>
24
32
 
25
- <div class={classes(rootPart("EmptyState"), EMPTY_STATE_PARTS.root, className)} {style}>
33
+ <div
34
+ {...rootAttributes(rest)}
35
+ class={classes(rootPart("EmptyState"), EMPTY_STATE_PARTS.root, className)}
36
+ {style}
37
+ >
26
38
  <Icon name={icon} size="xl" class={EMPTY_STATE_PARTS.icon} />
27
39
  <p class={EMPTY_STATE_PARTS.title}>{title}</p>
28
40
  {#if description}
package/dist/Icon.svelte CHANGED
@@ -12,16 +12,25 @@
12
12
 
13
13
  <script lang="ts">
14
14
  import { icons } from "@xds/tokens";
15
- import { classes, iconClass, rootPart } from "@xds/core";
15
+ import { classes, iconClass, rootAttributes, rootPart } from "@xds/core";
16
16
  import { useDefaults } from "./defaults.svelte.js";
17
17
 
18
- let { name, size: ownSize, filled, label, class: className, style }: IconProps = $props();
18
+ let {
19
+ name,
20
+ size: ownSize,
21
+ filled,
22
+ label,
23
+ class: className,
24
+ style,
25
+ ...rest
26
+ }: IconProps = $props();
19
27
 
20
28
  const defaults = useDefaults("Icon");
21
29
  const size = $derived(ownSize ?? defaults().size);
22
30
  </script>
23
31
 
24
32
  <svg
33
+ {...rootAttributes(rest)}
25
34
  viewBox="0 0 24 24"
26
35
  fill={filled ? "currentColor" : "none"}
27
36
  stroke="currentColor"
@@ -3,19 +3,24 @@
3
3
  A button that holds only an icon, in Button's variants, sizes and states. It is a square as
4
4
  tall as a Button of its size, and its pressable area is never smaller than the minimum target,
5
5
  even when the square is. Like Button, it opens a Menu or a Tooltip it is the trigger of.
6
+
7
+ `focus()`, `blur()` and `element()` on the instance reach the native button.
6
8
  -->
7
9
  <script module lang="ts">
8
10
  import type { IconButtonBaseProps } from "@xds/core";
11
+ import type { FocusEventHandler } from "svelte/elements";
9
12
  import type { RootProps } from "./root.js";
10
13
 
11
14
  export type IconButtonProps = IconButtonBaseProps &
12
15
  RootProps & {
13
16
  onPress?: () => void;
17
+ onFocus?: FocusEventHandler<HTMLButtonElement>;
18
+ onBlur?: FocusEventHandler<HTMLButtonElement>;
14
19
  };
15
20
  </script>
16
21
 
17
22
  <script lang="ts">
18
- import { buttonClass, classes, ICON_BUTTON_BOX, isHeld } from "@xds/core";
23
+ import { buttonClass, classes, ICON_BUTTON_BOX, isHeld, rootAttributes } from "@xds/core";
19
24
  import type { HTMLButtonAttributes } from "svelte/elements";
20
25
  import { useDefaults } from "./defaults.svelte.js";
21
26
  import Icon from "./Icon.svelte";
@@ -31,8 +36,11 @@
31
36
  disabled,
32
37
  loading,
33
38
  onPress,
39
+ onFocus,
40
+ onBlur,
34
41
  class: className,
35
42
  style,
43
+ ...rest
36
44
  }: IconButtonProps = $props();
37
45
 
38
46
  const defaults = useDefaults("IconButton");
@@ -53,12 +61,32 @@
53
61
  onclick: () => {
54
62
  if (!loading) onPress?.();
55
63
  },
64
+ onfocus: onFocus,
65
+ onblur: onBlur,
56
66
  }),
57
67
  () => loading === true,
58
68
  );
69
+ let button = $state<HTMLButtonElement>();
70
+
71
+ /** Moves the focus to the native button. */
72
+ export function focus(options?: FocusOptions) {
73
+ button?.focus(options);
74
+ }
75
+
76
+ /** Takes the focus from the native button. */
77
+ export function blur() {
78
+ button?.blur();
79
+ }
80
+
81
+ /** The native button, once it is on the page. */
82
+ export function element(): HTMLButtonElement | undefined {
83
+ return button;
84
+ }
59
85
  </script>
60
86
 
61
- <button {...attributes()}>
87
+ <!-- The app's id gives way to the one an overlay gives its trigger, which the overlay's own
88
+ parts point at. -->
89
+ <button {...rootAttributes(rest)} {...attributes()} bind:this={button}>
62
90
  {#if loading}
63
91
  <span class={ICON_BUTTON_BOX[size]}><Spinner size="sm" /></span>
64
92
  {:else}
@@ -1,13 +1,22 @@
1
1
  import type { IconButtonBaseProps } from "@xds/core";
2
+ import type { FocusEventHandler } from "svelte/elements";
2
3
  import type { RootProps } from "./root.js";
3
4
  export type IconButtonProps = IconButtonBaseProps & RootProps & {
4
5
  onPress?: () => void;
6
+ onFocus?: FocusEventHandler<HTMLButtonElement>;
7
+ onBlur?: FocusEventHandler<HTMLButtonElement>;
5
8
  };
6
9
  /**
7
10
  * A button that holds only an icon, in Button's variants, sizes and states. It is a square as
8
11
  * tall as a Button of its size, and its pressable area is never smaller than the minimum target,
9
12
  * even when the square is. Like Button, it opens a Menu or a Tooltip it is the trigger of.
13
+ *
14
+ * `focus()`, `blur()` and `element()` on the instance reach the native button.
10
15
  */
11
- declare const IconButton: import("svelte").Component<IconButtonProps, {}, "">;
16
+ declare const IconButton: import("svelte").Component<IconButtonProps, {
17
+ focus: (options?: FocusOptions) => void;
18
+ blur: () => void;
19
+ element: () => HTMLButtonElement | undefined;
20
+ }, "">;
12
21
  type IconButton = ReturnType<typeof IconButton>;
13
22
  export default IconButton;
@@ -0,0 +1,29 @@
1
+ <!--
2
+ @component
3
+ The names the components inside it give their own parts, in the app's language: a banner's
4
+ dismiss control, a search field's clear control, a calendar's month buttons. A label passed to a
5
+ component wins, and a Labels inside another keeps the outer one's labels and replaces only those
6
+ it names.
7
+ -->
8
+ <script module lang="ts">
9
+ import type { ComponentLabels } from "@xds/core";
10
+ import type { Snippet } from "svelte";
11
+
12
+ export type { ComponentLabels } from "@xds/core";
13
+
14
+ export type LabelsProps = {
15
+ /** The labels, by key: `{ dismiss: "닫기" }`. It may change; the components follow it. */
16
+ value: Partial<ComponentLabels>;
17
+ children: Snippet;
18
+ };
19
+ </script>
20
+
21
+ <script lang="ts">
22
+ import { provideLabels } from "./labels.svelte.js";
23
+
24
+ let { value, children }: LabelsProps = $props();
25
+
26
+ provideLabels(() => value);
27
+ </script>
28
+
29
+ {@render children()}
@@ -0,0 +1,17 @@
1
+ import type { ComponentLabels } from "@xds/core";
2
+ import type { Snippet } from "svelte";
3
+ export type { ComponentLabels } from "@xds/core";
4
+ export type LabelsProps = {
5
+ /** The labels, by key: `{ dismiss: "닫기" }`. It may change; the components follow it. */
6
+ value: Partial<ComponentLabels>;
7
+ children: Snippet;
8
+ };
9
+ /**
10
+ * The names the components inside it give their own parts, in the app's language: a banner's
11
+ * dismiss control, a search field's clear control, a calendar's month buttons. A label passed to a
12
+ * component wins, and a Labels inside another keeps the outer one's labels and replaces only those
13
+ * it names.
14
+ */
15
+ declare const Labels: import("svelte").Component<LabelsProps, {}, "">;
16
+ type Labels = ReturnType<typeof Labels>;
17
+ export default Labels;