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