@xds/svelte 1.1.0 → 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 (155) hide show
  1. package/dist/Breadcrumb.svelte +53 -0
  2. package/dist/Breadcrumb.svelte.d.ts +11 -0
  3. package/dist/Checkbox.svelte +11 -3
  4. package/dist/Checkbox.svelte.d.ts +2 -1
  5. package/dist/Combobox.svelte +194 -0
  6. package/dist/Combobox.svelte.d.ts +37 -0
  7. package/dist/DatePicker.svelte +5 -4
  8. package/dist/Link.svelte +86 -0
  9. package/dist/Link.svelte.d.ts +26 -0
  10. package/dist/Menu.svelte +8 -1
  11. package/dist/Pagination.svelte +108 -0
  12. package/dist/Pagination.svelte.d.ts +14 -0
  13. package/dist/Popover.svelte +91 -0
  14. package/dist/Popover.svelte.d.ts +21 -0
  15. package/dist/PopoverSurface.svelte +77 -0
  16. package/dist/PopoverSurface.svelte.d.ts +21 -0
  17. package/dist/Select.svelte +40 -8
  18. package/dist/Select.svelte.d.ts +6 -0
  19. package/dist/Table.svelte +92 -0
  20. package/dist/Table.svelte.d.ts +17 -0
  21. package/dist/TimePicker.svelte +222 -0
  22. package/dist/TimePicker.svelte.d.ts +20 -0
  23. package/dist/ToastQueue.svelte +57 -0
  24. package/dist/ToastQueue.svelte.d.ts +20 -0
  25. package/dist/base.d.ts +14 -0
  26. package/dist/base.js +27 -0
  27. package/dist/index.d.ts +11 -2
  28. package/dist/index.js +11 -0
  29. package/dist/modal-popover.svelte.js +5 -1
  30. package/dist/presence.svelte.js +5 -2
  31. package/dist/preview/Component.svelte +6 -3
  32. package/dist/preview/Preview.svelte +8 -2
  33. package/dist/preview/Preview.svelte.d.ts +2 -0
  34. package/dist/preview/components.d.ts +9 -2
  35. package/dist/preview/components.js +18 -2
  36. package/dist/preview/index.d.ts +1 -0
  37. package/eject/files/Accordion.svelte +100 -0
  38. package/eject/files/AccordionPanel.svelte +48 -0
  39. package/eject/files/Avatar.svelte +51 -0
  40. package/eject/files/AvatarStack.svelte +61 -0
  41. package/eject/files/Badge.svelte +52 -0
  42. package/eject/files/Banner.svelte +94 -0
  43. package/eject/files/Breadcrumb.svelte +52 -0
  44. package/eject/files/Button.svelte +126 -0
  45. package/eject/files/Card.svelte +112 -0
  46. package/eject/files/Checkbox.svelte +121 -0
  47. package/eject/files/Chip.svelte +51 -0
  48. package/eject/files/ChipBar.svelte +39 -0
  49. package/eject/files/Combobox.svelte +198 -0
  50. package/eject/files/CountBadge.svelte +51 -0
  51. package/eject/files/DatePicker.svelte +213 -0
  52. package/eject/files/DateRangePicker.svelte +294 -0
  53. package/eject/files/Dialog.svelte +119 -0
  54. package/eject/files/Divider.svelte +27 -0
  55. package/eject/files/EmptyState.svelte +52 -0
  56. package/eject/files/Icon.svelte +51 -0
  57. package/eject/files/IconButton.svelte +99 -0
  58. package/eject/files/Link.svelte +85 -0
  59. package/eject/files/ListRow.svelte +33 -0
  60. package/eject/files/MediaCard.svelte +117 -0
  61. package/eject/files/Menu.svelte +183 -0
  62. package/eject/files/Pagination.svelte +109 -0
  63. package/eject/files/PlaceRow.svelte +75 -0
  64. package/eject/files/Popover.svelte +100 -0
  65. package/eject/files/PopoverSurface.svelte +85 -0
  66. package/eject/files/ProgressBar.svelte +38 -0
  67. package/eject/files/RadioGroup.svelte +133 -0
  68. package/eject/files/SearchField.svelte +154 -0
  69. package/eject/files/SectionHeader.svelte +67 -0
  70. package/eject/files/SegmentedControl.svelte +85 -0
  71. package/eject/files/Select.svelte +276 -0
  72. package/eject/files/Sidebar.svelte +130 -0
  73. package/eject/files/SidebarRailButton.svelte +32 -0
  74. package/eject/files/Skeleton.svelte +55 -0
  75. package/eject/files/Slider.svelte +136 -0
  76. package/eject/files/Spinner.svelte +41 -0
  77. package/eject/files/Switch.svelte +105 -0
  78. package/eject/files/Table.svelte +90 -0
  79. package/eject/files/Tabs.svelte +85 -0
  80. package/eject/files/Text.svelte +43 -0
  81. package/eject/files/TextField.svelte +222 -0
  82. package/eject/files/Thumbnail.svelte +88 -0
  83. package/eject/files/TimePicker.svelte +237 -0
  84. package/eject/files/Toast.svelte +98 -0
  85. package/eject/files/ToastQueue.svelte +61 -0
  86. package/eject/files/Tooltip.svelte +51 -0
  87. package/eject/files/TooltipOverlay.svelte +88 -0
  88. package/eject/files/accordion.css +89 -0
  89. package/eject/files/accordion.ts +67 -0
  90. package/eject/files/avatar-stack.ts +57 -0
  91. package/eject/files/avatar.ts +42 -0
  92. package/eject/files/badge.ts +30 -0
  93. package/eject/files/banner.ts +71 -0
  94. package/eject/files/base.css +38 -0
  95. package/eject/files/breadcrumb.css +51 -0
  96. package/eject/files/breadcrumb.ts +42 -0
  97. package/eject/files/button.css +241 -0
  98. package/eject/files/button.ts +106 -0
  99. package/eject/files/card.ts +58 -0
  100. package/eject/files/checkbox.ts +52 -0
  101. package/eject/files/chip-bar.ts +16 -0
  102. package/eject/files/chip.ts +35 -0
  103. package/eject/files/combobox.css +269 -0
  104. package/eject/files/combobox.ts +85 -0
  105. package/eject/files/count-badge.ts +32 -0
  106. package/eject/files/date-picker.css +375 -0
  107. package/eject/files/date-picker.ts +280 -0
  108. package/eject/files/date-range-picker.ts +338 -0
  109. package/eject/files/dialog.css +139 -0
  110. package/eject/files/dialog.ts +15 -0
  111. package/eject/files/divider.ts +5 -0
  112. package/eject/files/empty-state.ts +22 -0
  113. package/eject/files/icon.ts +36 -0
  114. package/eject/files/link.css +64 -0
  115. package/eject/files/link.ts +63 -0
  116. package/eject/files/list-row.ts +66 -0
  117. package/eject/files/media-card.ts +66 -0
  118. package/eject/files/menu.css +192 -0
  119. package/eject/files/menu.ts +84 -0
  120. package/eject/files/overlay.css +40 -0
  121. package/eject/files/pagination.css +106 -0
  122. package/eject/files/pagination.ts +68 -0
  123. package/eject/files/parts.ts +17 -0
  124. package/eject/files/popover.css +101 -0
  125. package/eject/files/popover.ts +37 -0
  126. package/eject/files/progress-bar.ts +26 -0
  127. package/eject/files/radio-group.css +184 -0
  128. package/eject/files/radio-group.ts +30 -0
  129. package/eject/files/section-header.ts +32 -0
  130. package/eject/files/segmented-control.ts +33 -0
  131. package/eject/files/select.css +347 -0
  132. package/eject/files/select.ts +77 -0
  133. package/eject/files/sidebar.ts +75 -0
  134. package/eject/files/skeleton.ts +51 -0
  135. package/eject/files/slider.css +160 -0
  136. package/eject/files/slider.ts +80 -0
  137. package/eject/files/spinner.ts +22 -0
  138. package/eject/files/switch.ts +45 -0
  139. package/eject/files/table.css +107 -0
  140. package/eject/files/table.ts +84 -0
  141. package/eject/files/tabs.css +120 -0
  142. package/eject/files/tabs.ts +37 -0
  143. package/eject/files/text-field.css +225 -0
  144. package/eject/files/text-field.ts +64 -0
  145. package/eject/files/text.ts +38 -0
  146. package/eject/files/thumbnail.ts +51 -0
  147. package/eject/files/time-picker.ts +113 -0
  148. package/eject/files/toast-queue.ts +64 -0
  149. package/eject/files/toast.ts +31 -0
  150. package/eject/files/tooltip.css +111 -0
  151. package/eject/files/tooltip.ts +21 -0
  152. package/eject/manifest.json +1053 -0
  153. package/package.json +12 -4
  154. package/styles.css +1064 -169
  155. package/tailwind.css +1295 -218
@@ -0,0 +1,213 @@
1
+ <!--
2
+ Ejected from `@xds/svelte` 1.2.0 by `xds eject`. This copy is the app's own: change it
3
+ as you need. `xds eject --list` says which ejected files differ from what was copied.
4
+ -->
5
+ <!--
6
+ @component
7
+ A field for choosing one day. Closed, it looks like a Select: the chosen day in the locale's
8
+ medium form, or the placeholder. Pressed, it opens a calendar of one month under itself, on the
9
+ chosen day, or on today while none is. A press on a day, or Enter on the focused one, calls
10
+ `onChange` with the day as `YYYY-MM-DD` and closes the calendar; Escape or a press outside
11
+ closes it without a choice.
12
+
13
+ The field is a button that says it opens a dialog and whether it is open. In the calendar the
14
+ arrow keys move a day or a week, Page Up and Page Down a month (a year with Shift), and Home and
15
+ End to the first and the last day of the month, never past `min` or `max`. Tab goes round the
16
+ month buttons and the focused day. The chosen day is selected for assistive technology, and
17
+ today is the current date.
18
+ -->
19
+ <script module lang="ts">
20
+ import type { RootProps } from "@xds/svelte/base";
21
+ import type { DatePickerBaseProps, IsoDate } from "./date-picker.ts";
22
+
23
+ export type { IsoDate } from "./date-picker.ts";
24
+
25
+ export type DatePickerProps = DatePickerBaseProps &
26
+ RootProps & {
27
+ onChange: (value: IsoDate) => void;
28
+ };
29
+ </script>
30
+
31
+ <script lang="ts">
32
+ import {
33
+ createPresence,
34
+ modalPopover,
35
+ Portal,
36
+ readCssPx,
37
+ rootAttributes,
38
+ space,
39
+ underlayLayerStyle,
40
+ useLabels,
41
+ } from "@xds/svelte/base";
42
+ import * as datePicker from "@zag-js/date-picker";
43
+ import { mergeProps, normalizeProps, useMachine } from "@zag-js/svelte";
44
+ import { untrack } from "svelte";
45
+ import {
46
+ DATE_PICKER_NAV_CLASS,
47
+ datePickerContentAttrs,
48
+ datePickerIds,
49
+ datePickerLocale,
50
+ datePickerMachineProps,
51
+ datePickerTriggerAttrs,
52
+ focusOpeningDay,
53
+ formatDay,
54
+ keepCalendarFocus,
55
+ keepDayFocused,
56
+ } from "./date-picker.ts";
57
+ import Icon from "./Icon.svelte";
58
+ import { classes } from "./parts.ts";
59
+
60
+ // The rest stays reactive: the machine's props read it each time it changes.
61
+ let { onChange, class: className, style, ...props }: DatePickerProps = $props();
62
+
63
+ const id = $props.id();
64
+ const ids = datePickerIds(id);
65
+ const locale = $derived(datePickerLocale(props.locale));
66
+ const labels = useLabels();
67
+ const service = useMachine(datePicker.machine, () =>
68
+ datePickerMachineProps(props, {
69
+ id,
70
+ locale,
71
+ onChange,
72
+ gutter: readCssPx(null, "--xds-space-1", space[1]),
73
+ labels: labels(),
74
+ }),
75
+ );
76
+ const api = $derived(datePicker.connect(service, normalizeProps));
77
+ const trigger = $derived(api.getTriggerProps());
78
+ const invalid = $derived(props.error !== undefined);
79
+ let positioner = $state<HTMLDivElement>();
80
+ let surface = $state<HTMLDivElement>();
81
+ modalPopover(
82
+ () => api.open,
83
+ () => positioner,
84
+ );
85
+ const present = createPresence(
86
+ () => api.open,
87
+ () => [surface],
88
+ );
89
+ // Derived, so that the effect below runs only when the calendar opens or closes or the focused
90
+ // day or the month changes, not on every change of the machine.
91
+ const open = $derived(api.open);
92
+ const focused = $derived(api.focusedValue.toString());
93
+ const month = $derived(api.visibleRange.start.toString());
94
+ $effect(() => {
95
+ const isOpen = open;
96
+ void focused;
97
+ void month;
98
+ untrack(() => keepDayFocused(isOpen, surface));
99
+ });
100
+ </script>
101
+
102
+ <!-- Merged, so that the app's style joins any the machine writes on the root. -->
103
+ <div
104
+ {...mergeProps(api.getRootProps(), {
105
+ ...rootAttributes(props),
106
+ class: classes("{{prefix}}-date-picker", className),
107
+ style,
108
+ })}
109
+ >
110
+ <!-- A span: the field is a button, which a <label> cannot point at. -->
111
+ <span id={ids.label} class="{{prefix}}-date-picker__label">{props.label}</span>
112
+ <!-- What Zag places the calendar against. -->
113
+ <div {...api.getControlProps()} class="{{prefix}}-date-picker__control">
114
+ <button
115
+ {...trigger}
116
+ {...datePickerTriggerAttrs(props, ids)}
117
+ type="button"
118
+ onclick={(event) => {
119
+ focusOpeningDay(api, props);
120
+ trigger.onclick?.(event);
121
+ }}
122
+ class="{{prefix}}-date-picker__trigger"
123
+ >
124
+ <span id={ids.value} class="{{prefix}}-date-picker__value"
125
+ >{props.value === undefined ? props.placeholder : formatDay(props.value, locale)}</span
126
+ >
127
+ <Icon name="calendar" size="sm" class="text-xds-field-placeholder" />
128
+ </button>
129
+ </div>
130
+ <!-- One line under the box: the help, or the error in its place. The error stays mounted as
131
+ a live region so assistive technology announces it when it appears. -->
132
+ <div class="{{prefix}}-date-picker__footer">
133
+ {#if !invalid && props.description}
134
+ <span id={ids.description} class="{{prefix}}-date-picker__description"
135
+ >{props.description}</span
136
+ >
137
+ {/if}
138
+ <span id={ids.error} class="{{prefix}}-date-picker__error" aria-live="polite"
139
+ >{props.error}</span
140
+ >
141
+ </div>
142
+ <!-- What a form submits. Zag gives the name to its text input, which is not drawn. -->
143
+ {#if props.name !== undefined}
144
+ <input type="hidden" name={props.name} value={props.value ?? ""} />
145
+ {/if}
146
+ <Portal>
147
+ {#if api.open}
148
+ <!-- Takes a press outside, which then only closes the calendar. The focus stays in the
149
+ calendar until it hands it back to the field. -->
150
+ <!-- svelte-ignore a11y_no_static_element_interactions -->
151
+ <div
152
+ class="{{prefix}}-date-picker__underlay"
153
+ style:--layer-index={underlayLayerStyle(api.getPositionerProps().style)?.["--layer-index"]}
154
+ onmousedown={(event) => event.preventDefault()}
155
+ ></div>
156
+ {/if}
157
+ <div
158
+ {...api.getPositionerProps()}
159
+ bind:this={positioner}
160
+ class="{{prefix}}-date-picker__positioner"
161
+ >
162
+ <!-- Shown until its exit animation ends; Zag would hide it as it closes. -->
163
+ <div
164
+ {...api.getContentProps()}
165
+ {...datePickerContentAttrs(ids)}
166
+ bind:this={surface}
167
+ hidden={!present()}
168
+ onkeydown={(event) => keepCalendarFocus(event, surface)}
169
+ class="{{prefix}}-date-picker__content"
170
+ >
171
+ <div class="{{prefix}}-date-picker__header">
172
+ <button {...api.getPreviousTriggerProps()} type="button" class={DATE_PICKER_NAV_CLASS}>
173
+ <Icon name="chevron-left" size="sm" />
174
+ </button>
175
+ <span {...api.getRangeTextProps()} class="{{prefix}}-date-picker__heading"
176
+ >{api.visibleRangeText.start}</span
177
+ >
178
+ <button {...api.getNextTriggerProps()} type="button" class={DATE_PICKER_NAV_CLASS}>
179
+ <Icon name="chevron-right" size="sm" />
180
+ </button>
181
+ </div>
182
+ <table {...api.getTableProps({ view: "day" })} class="{{prefix}}-date-picker__grid">
183
+ <thead {...api.getTableHeadProps({ view: "day" })}>
184
+ <tr {...api.getTableRowProps({ view: "day" })}>
185
+ {#each api.weekDays as weekDay (weekDay.long)}
186
+ <th scope="col" class="{{prefix}}-date-picker__weekday">{weekDay.narrow}</th>
187
+ {/each}
188
+ </tr>
189
+ </thead>
190
+ <tbody {...api.getTableBodyProps({ view: "day" })}>
191
+ <!-- Keyed by the day, not by the object: Zag hands out new dates on every change, and
192
+ a cell made anew would drop the focus it holds when a move is held at `min` or
193
+ `max`. -->
194
+ {#each api.weeks as week (week[0]?.toString())}
195
+ <tr {...api.getTableRowProps({ view: "day" })}>
196
+ {#each week as value (value.toString())}
197
+ <td {...api.getDayTableCellProps({ value })} class="{{prefix}}-date-picker__cell">
198
+ <div
199
+ {...api.getDayTableCellTriggerProps({ value })}
200
+ class="{{prefix}}-date-picker__day"
201
+ >
202
+ {value.day}
203
+ </div>
204
+ </td>
205
+ {/each}
206
+ </tr>
207
+ {/each}
208
+ </tbody>
209
+ </table>
210
+ </div>
211
+ </div>
212
+ </Portal>
213
+ </div>
@@ -0,0 +1,294 @@
1
+ <!--
2
+ Ejected from `@xds/svelte` 1.2.0 by `xds eject`. This copy is the app's own: change it
3
+ as you need. `xds eject --list` says which ejected files differ from what was copied.
4
+ -->
5
+ <!--
6
+ @component
7
+ A field for choosing a range of days, a start and an end, as for a stay. Closed, it looks like a
8
+ DatePicker and shows both days in the locale's medium form ("Mar 10 – 14, 2026"), or the
9
+ placeholder. Pressed, it opens a calendar under itself, two months side by side where the window
10
+ has room and one where it does not, on the start's month, or on today's while nothing is chosen.
11
+
12
+ The first day pressed starts the range, and the band previews it to the day under the pointer or
13
+ the keyboard's focus. The second ends it, if the days between are at least `minLength` and at
14
+ most `maxLength`, which leave the other days unavailable meanwhile: `onChange` gets the range and
15
+ the calendar closes. A day before the start starts again from there. Escape or a press outside
16
+ closes the calendar without a change.
17
+
18
+ The keys are DatePicker's, and Page Up and Page Down move a month whether one or two are shown.
19
+ Each month is a grid named by its month; every day of the range is selected, and the two ends
20
+ are named by `startLabel` and `endLabel` before the day.
21
+ -->
22
+ <script module lang="ts">
23
+ import type { RootProps } from "@xds/svelte/base";
24
+ import type { DateRange, DateRangePickerBaseProps } from "./date-range-picker.ts";
25
+
26
+ export type { DateRange } from "./date-range-picker.ts";
27
+
28
+ export type DateRangePickerProps = DateRangePickerBaseProps &
29
+ RootProps & {
30
+ onChange: (value: DateRange) => void;
31
+ };
32
+ </script>
33
+
34
+ <script lang="ts">
35
+ import {
36
+ createPresence,
37
+ modalPopover,
38
+ Portal,
39
+ readCssPx,
40
+ rootAttributes,
41
+ space,
42
+ underlayLayerStyle,
43
+ useLabels,
44
+ } from "@xds/svelte/base";
45
+ import * as datePicker from "@zag-js/date-picker";
46
+ import { mergeProps, normalizeProps, useMachine } from "@zag-js/svelte";
47
+ import { untrack } from "svelte";
48
+ import {
49
+ DATE_PICKER_NAV_CLASS,
50
+ datePickerContentAttrs,
51
+ datePickerIds,
52
+ datePickerLocale,
53
+ datePickerTriggerAttrs,
54
+ focusOpeningDay,
55
+ keepCalendarFocus,
56
+ keepDayFocused,
57
+ } from "./date-picker.ts";
58
+ import {
59
+ dateRangeMachineProps,
60
+ endRangeChoiceOnClose,
61
+ formatRange,
62
+ keepRangePreview,
63
+ type RangeDraft,
64
+ rangeDayClick,
65
+ rangeGridKeyDown,
66
+ rangeMonths,
67
+ rangeMonthViews,
68
+ rangeSummary,
69
+ shownRange,
70
+ } from "./date-range-picker.ts";
71
+ import Icon from "./Icon.svelte";
72
+ import { classes } from "./parts.ts";
73
+
74
+ // The rest stays reactive: the machine's props read it each time it changes.
75
+ let { onChange, class: className, style, ...props }: DateRangePickerProps = $props();
76
+
77
+ const id = $props.id();
78
+ const ids = datePickerIds(id);
79
+ const locale = $derived(datePickerLocale(props.locale));
80
+ const labels = useLabels();
81
+ // A start alone while the end is chosen; null while the calendar shows the chosen range.
82
+ let draft = $state.raw<RangeDraft | null>(null);
83
+ let months = $state(1);
84
+ const shown = $derived(shownRange(props.value, draft));
85
+ const service = useMachine(datePicker.machine, () =>
86
+ dateRangeMachineProps(props, shown, {
87
+ id,
88
+ locale,
89
+ months,
90
+ onDraft: (next) => (draft = next),
91
+ onChange,
92
+ gutter: readCssPx(null, "--xds-space-1", space[1]),
93
+ labels: labels(),
94
+ }),
95
+ );
96
+ const api = $derived(datePicker.connect(service, normalizeProps));
97
+ const trigger = $derived(api.getTriggerProps());
98
+ const invalid = $derived(props.error !== undefined);
99
+ const summary = $derived(rangeSummary(shown, props, locale, labels()));
100
+ const views = $derived(rangeMonthViews(api, months));
101
+ let positioner = $state<HTMLDivElement>();
102
+ let surface = $state<HTMLDivElement>();
103
+ modalPopover(
104
+ () => api.open,
105
+ () => positioner,
106
+ );
107
+ const present = createPresence(
108
+ () => api.open,
109
+ () => [surface],
110
+ );
111
+ // Strings, so that the effects below run only when the focused day or the month changes, not
112
+ // on every change of the machine.
113
+ const focused = $derived(api.focusedValue.toString());
114
+ const month = $derived(api.visibleRange.start.toString());
115
+ const open = $derived(api.open);
116
+ $effect(() => {
117
+ const isOpen = open;
118
+ void focused;
119
+ void month;
120
+ untrack(() => keepDayFocused(isOpen, surface));
121
+ });
122
+ $effect(() => {
123
+ const isOpen = open;
124
+ untrack(() => endRangeChoiceOnClose(service, isOpen));
125
+ });
126
+ $effect(() => {
127
+ void focused;
128
+ untrack(() => keepRangePreview(service, shown, open));
129
+ });
130
+ </script>
131
+
132
+ <!-- Merged, so that the app's style joins any the machine writes on the root. -->
133
+ <div
134
+ {...mergeProps(api.getRootProps(), {
135
+ ...rootAttributes(props),
136
+ class: classes("{{prefix}}-date-picker {{prefix}}-date-range-picker", className),
137
+ style,
138
+ })}
139
+ >
140
+ <!-- A span: the field is a button, which a <label> cannot point at. -->
141
+ <span id={ids.label} class="{{prefix}}-date-picker__label">{props.label}</span>
142
+ <!-- What Zag places the calendar against. -->
143
+ <div {...api.getControlProps()} class="{{prefix}}-date-picker__control">
144
+ <button
145
+ {...trigger}
146
+ {...datePickerTriggerAttrs(props, ids)}
147
+ type="button"
148
+ onclick={(event) => {
149
+ if (!api.open) months = rangeMonths();
150
+ focusOpeningDay(api, { ...props, value: props.value?.start });
151
+ trigger.onclick?.(event);
152
+ }}
153
+ class="{{prefix}}-date-picker__trigger"
154
+ >
155
+ <span id={ids.value} class="{{prefix}}-date-picker__value"
156
+ >{props.value === undefined ? props.placeholder : formatRange(props.value, locale)}</span
157
+ >
158
+ <Icon name="calendar" size="sm" class="text-xds-field-placeholder" />
159
+ </button>
160
+ </div>
161
+ <!-- One line under the box: the help, or the error in its place. The error stays mounted as
162
+ a live region so assistive technology announces it when it appears. -->
163
+ <div class="{{prefix}}-date-picker__footer">
164
+ {#if !invalid && props.description}
165
+ <span id={ids.description} class="{{prefix}}-date-picker__description"
166
+ >{props.description}</span
167
+ >
168
+ {/if}
169
+ <span id={ids.error} class="{{prefix}}-date-picker__error" aria-live="polite"
170
+ >{props.error}</span
171
+ >
172
+ </div>
173
+ <!-- What a form submits. Zag gives the names to its text inputs, which are not drawn. -->
174
+ {#if props.startName !== undefined}
175
+ <input type="hidden" name={props.startName} value={props.value?.start ?? ""} />
176
+ {/if}
177
+ {#if props.endName !== undefined}
178
+ <input type="hidden" name={props.endName} value={props.value?.end ?? ""} />
179
+ {/if}
180
+ <Portal>
181
+ {#if api.open}
182
+ <!-- Takes a press outside, which then only closes the calendar. The focus stays in the
183
+ calendar until it hands it back to the field. -->
184
+ <!-- svelte-ignore a11y_no_static_element_interactions -->
185
+ <div
186
+ class="{{prefix}}-date-picker__underlay"
187
+ style:--layer-index={underlayLayerStyle(api.getPositionerProps().style)?.["--layer-index"]}
188
+ onmousedown={(event) => event.preventDefault()}
189
+ ></div>
190
+ {/if}
191
+ <div
192
+ {...api.getPositionerProps()}
193
+ bind:this={positioner}
194
+ class="{{prefix}}-date-picker__positioner"
195
+ >
196
+ <!-- Shown until its exit animation ends; Zag would hide it as it closes. -->
197
+ <div
198
+ {...api.getContentProps()}
199
+ {...datePickerContentAttrs(ids)}
200
+ bind:this={surface}
201
+ hidden={!present()}
202
+ onkeydown={(event) => keepCalendarFocus(event, surface)}
203
+ class="{{prefix}}-date-picker__content {{prefix}}-date-range-picker__content"
204
+ >
205
+ <div class="{{prefix}}-date-range-picker__summary" aria-live="polite">
206
+ <span>{summary.start}</span>
207
+ <span>{summary.end}</span>
208
+ </div>
209
+ <div class="{{prefix}}-date-range-picker__months">
210
+ {#each views as view (view.index)}
211
+ {@const table = api.getTableProps({ view: "day", id: view.table.id })}
212
+ <div class="{{prefix}}-date-range-picker__month">
213
+ <div class="{{prefix}}-date-picker__header">
214
+ {#if view.index === 0}
215
+ <button
216
+ {...api.getPreviousTriggerProps()}
217
+ type="button"
218
+ class={DATE_PICKER_NAV_CLASS}
219
+ >
220
+ <Icon name="chevron-left" size="sm" />
221
+ </button>
222
+ {:else}
223
+ <span class="{{prefix}}-date-range-picker__nav-space"></span>
224
+ {/if}
225
+ <span {...api.getRangeTextProps()} class="{{prefix}}-date-picker__heading"
226
+ >{view.name}</span
227
+ >
228
+ {#if view.index === months - 1}
229
+ <button
230
+ {...api.getNextTriggerProps()}
231
+ type="button"
232
+ class={DATE_PICKER_NAV_CLASS}
233
+ >
234
+ <Icon name="chevron-right" size="sm" />
235
+ </button>
236
+ {:else}
237
+ <span class="{{prefix}}-date-range-picker__nav-space"></span>
238
+ {/if}
239
+ </div>
240
+ <table
241
+ {...table}
242
+ {...view.table}
243
+ onkeydown={(event) => rangeGridKeyDown(event, api, shown, props, table.onkeydown)}
244
+ class="{{prefix}}-date-picker__grid"
245
+ >
246
+ <thead {...api.getTableHeadProps({ view: "day" })}>
247
+ <tr {...api.getTableRowProps({ view: "day" })}>
248
+ {#each api.weekDays as weekDay (weekDay.long)}
249
+ <th scope="col" class="{{prefix}}-date-picker__weekday">{weekDay.narrow}</th>
250
+ {/each}
251
+ </tr>
252
+ </thead>
253
+ <tbody {...api.getTableBodyProps({ view: "day" })}>
254
+ <!-- Keyed by the day, as in DatePicker: a cell made anew would drop the focus it
255
+ holds when a move is held at `min` or `max`. -->
256
+ {#each view.weeks as week (week[0]?.toString())}
257
+ <tr {...api.getTableRowProps({ view: "day" })}>
258
+ {#each week as value (value.toString())}
259
+ {@const cell = { value, visibleRange: view.visibleRange }}
260
+ {@const day = api.getDayTableCellTriggerProps(cell)}
261
+ <td
262
+ {...api.getDayTableCellProps(cell)}
263
+ class="{{prefix}}-date-picker__cell"
264
+ >
265
+ <!-- svelte-ignore a11y_click_events_have_key_events, a11y_no_static_element_interactions -->
266
+ <div
267
+ {...day}
268
+ onclick={(event) =>
269
+ rangeDayClick(
270
+ event,
271
+ api,
272
+ shown,
273
+ props,
274
+ value,
275
+ view.visibleRange,
276
+ day.onclick,
277
+ )}
278
+ class="{{prefix}}-date-picker__day"
279
+ >
280
+ {value.day}
281
+ </div>
282
+ </td>
283
+ {/each}
284
+ </tr>
285
+ {/each}
286
+ </tbody>
287
+ </table>
288
+ </div>
289
+ {/each}
290
+ </div>
291
+ </div>
292
+ </div>
293
+ </Portal>
294
+ </div>
@@ -0,0 +1,119 @@
1
+ <!--
2
+ Ejected from `@xds/svelte` 1.2.0 by `xds eject`. This copy is the app's own: change it
3
+ as you need. `xds eject --list` says which ejected files differ from what was copied.
4
+ -->
5
+ <!--
6
+ @component
7
+ A window that interrupts the screen for a confirmation or a short task. Everything behind it is
8
+ dimmed and cannot be reached until it closes.
9
+
10
+ It is a modal dialog named by its title and described by its description. Focus moves into it,
11
+ stays inside it, and returns to where it was when it closes.
12
+ -->
13
+ <script module lang="ts">
14
+ import type { RootProps } from "@xds/svelte/base";
15
+ import type { Snippet } from "svelte";
16
+ import type { DialogBaseProps } from "./dialog.ts";
17
+
18
+ /** Its root is the dialog itself, while it is open, not the scrim around it. */
19
+ export type DialogProps = DialogBaseProps &
20
+ RootProps & {
21
+ /** Called on Escape and on a press outside the dialog. Set `open` to false in it. */
22
+ onClose: () => void;
23
+ /** The body, between the description and the actions. It scrolls when it is too tall. */
24
+ children?: Snippet;
25
+ /** Buttons, in a row at the end edge. Put the main action last. */
26
+ actions?: Snippet;
27
+ };
28
+ </script>
29
+
30
+ <script lang="ts">
31
+ import {
32
+ createPresence,
33
+ leaveEscapeToFields,
34
+ Portal,
35
+ resetTrigger,
36
+ rootAttributes,
37
+ } from "@xds/svelte/base";
38
+ import * as dialog from "@zag-js/dialog";
39
+ import { mergeProps, normalizeProps, useMachine } from "@zag-js/svelte";
40
+ import { classes } from "./parts.ts";
41
+
42
+ let {
43
+ open,
44
+ title,
45
+ description,
46
+ dismissible,
47
+ onClose,
48
+ class: className,
49
+ style,
50
+ children,
51
+ actions,
52
+ ...rest
53
+ }: DialogProps = $props();
54
+
55
+ const id = $props.id();
56
+ let backdrop = $state<HTMLDivElement>();
57
+ let positioner = $state<HTMLDivElement>();
58
+ let content = $state<HTMLElement>();
59
+ const service = useMachine(dialog.machine, () => ({
60
+ id,
61
+ // The app's id names the dialog, and what Zag points at it points there.
62
+ ids: rest.id === undefined ? undefined : { content: rest.id },
63
+ open,
64
+ onOpenChange: (details: dialog.OpenChangeDetails) => {
65
+ if (!details.open) onClose();
66
+ },
67
+ closeOnEscape: dismissible ?? true,
68
+ closeOnInteractOutside: dismissible ?? true,
69
+ onEscapeKeyDown: leaveEscapeToFields,
70
+ // The dialog itself rather than its first field or button: a screen reader then reads the
71
+ // title and the description first.
72
+ initialFocusEl: () => content ?? null,
73
+ }));
74
+ const api = $derived(dialog.connect(service, normalizeProps));
75
+ const present = createPresence(
76
+ () => api.open,
77
+ () => [backdrop, positioner],
78
+ );
79
+ // Nothing inside opens an overlay from a control outside it.
80
+ resetTrigger();
81
+ </script>
82
+
83
+ {#if present()}
84
+ <Portal>
85
+ <!-- A press on the scrim keeps the focus in the dialog: a dialog that cannot be dismissed stays
86
+ open, and the focus would go to the page. The backdrop and the dialog stay shown until
87
+ their exit animation ends; Zag would hide them as the dialog closes. -->
88
+ <!-- svelte-ignore a11y_no_static_element_interactions -->
89
+ <div
90
+ {...api.getBackdropProps()}
91
+ bind:this={backdrop}
92
+ hidden={false}
93
+ onmousedown={(event) => event.preventDefault()}
94
+ class="{{prefix}}-dialog__backdrop"
95
+ ></div>
96
+ <div {...api.getPositionerProps()} bind:this={positioner} class="{{prefix}}-dialog__positioner">
97
+ <section
98
+ {...mergeProps(api.getContentProps(), {
99
+ ...rootAttributes(rest),
100
+ class: classes("{{prefix}}-dialog", className),
101
+ style,
102
+ })}
103
+ bind:this={content}
104
+ hidden={false}
105
+ >
106
+ <h2 {...api.getTitleProps()} class="{{prefix}}-dialog__title">{title}</h2>
107
+ {#if description}
108
+ <p {...api.getDescriptionProps()} class="{{prefix}}-dialog__description">{description}</p>
109
+ {/if}
110
+ {#if children}
111
+ <div class="{{prefix}}-dialog__body">{@render children()}</div>
112
+ {/if}
113
+ {#if actions}
114
+ <div class="{{prefix}}-dialog__actions">{@render actions()}</div>
115
+ {/if}
116
+ </section>
117
+ </div>
118
+ </Portal>
119
+ {/if}
@@ -0,0 +1,27 @@
1
+ <!--
2
+ Ejected from `@xds/svelte` 1.2.0 by `xds eject`. This copy is the app's own: change it
3
+ as you need. `xds eject --list` says which ejected files differ from what was copied.
4
+ -->
5
+ <!--
6
+ @component
7
+ A line between groups of content. Decorative lines use the low-contrast border color.
8
+ -->
9
+ <script module lang="ts">
10
+ import type { RootProps } from "@xds/svelte/base";
11
+
12
+ export type DividerProps = RootProps;
13
+ </script>
14
+
15
+ <script lang="ts">
16
+ import { rootAttributes } from "@xds/svelte/base";
17
+ import { dividerClass } from "./divider.ts";
18
+ import { classes, rootPart } from "./parts.ts";
19
+
20
+ let { class: className, style, ...rest }: DividerProps = $props();
21
+ </script>
22
+
23
+ <hr
24
+ {...rootAttributes(rest)}
25
+ class={classes(rootPart("Divider"), dividerClass, className)}
26
+ {style}
27
+ />