@xds/vue 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 (151) hide show
  1. package/dist/Breadcrumb.js +4 -0
  2. package/dist/Breadcrumb.vue.d.ts +6 -0
  3. package/dist/Breadcrumb.vue_vue_type_script_setup_true_lang.js +47 -0
  4. package/dist/Checkbox.vue_vue_type_script_setup_true_lang.js +11 -3
  5. package/dist/Combobox.js +4 -0
  6. package/dist/Combobox.vue.d.ts +22 -0
  7. package/dist/Combobox.vue_vue_type_script_setup_true_lang.js +140 -0
  8. package/dist/Link.js +4 -0
  9. package/dist/Link.vue.d.ts +27 -0
  10. package/dist/Link.vue_vue_type_script_setup_true_lang.js +62 -0
  11. package/dist/Pagination.js +4 -0
  12. package/dist/Pagination.vue.d.ts +9 -0
  13. package/dist/Pagination.vue_vue_type_script_setup_true_lang.js +74 -0
  14. package/dist/Popover.js +4 -0
  15. package/dist/Popover.vue.d.ts +26 -0
  16. package/dist/Popover.vue_vue_type_script_setup_true_lang.js +81 -0
  17. package/dist/Select.vue.d.ts +3 -1
  18. package/dist/Select.vue_vue_type_script_setup_true_lang.js +41 -17
  19. package/dist/Table.js +4 -0
  20. package/dist/Table.vue.d.ts +10 -0
  21. package/dist/Table.vue_vue_type_script_setup_true_lang.js +61 -0
  22. package/dist/TimePicker.js +4 -0
  23. package/dist/TimePicker.vue.d.ts +10 -0
  24. package/dist/TimePicker.vue_vue_type_script_setup_true_lang.js +168 -0
  25. package/dist/ToastQueue.js +4 -0
  26. package/dist/ToastQueue.vue.d.ts +9 -0
  27. package/dist/ToastQueue.vue_vue_type_script_setup_true_lang.js +42 -0
  28. package/dist/base.d.ts +13 -0
  29. package/dist/base.js +14 -0
  30. package/dist/index.d.ts +13 -4
  31. package/dist/index.js +10 -1
  32. package/dist/preview.d.ts +20 -3
  33. package/dist/preview.js +29 -6
  34. package/eject/files/Accordion.vue +89 -0
  35. package/eject/files/AccordionPanel.vue +47 -0
  36. package/eject/files/Avatar.vue +41 -0
  37. package/eject/files/AvatarStack.vue +46 -0
  38. package/eject/files/Badge.vue +29 -0
  39. package/eject/files/Banner.vue +65 -0
  40. package/eject/files/Breadcrumb.vue +43 -0
  41. package/eject/files/Button.vue +93 -0
  42. package/eject/files/Card.vue +85 -0
  43. package/eject/files/Checkbox.vue +104 -0
  44. package/eject/files/Chip.vue +32 -0
  45. package/eject/files/ChipBar.vue +25 -0
  46. package/eject/files/Combobox.vue +175 -0
  47. package/eject/files/CountBadge.vue +45 -0
  48. package/eject/files/DatePicker.vue +223 -0
  49. package/eject/files/DateRangePicker.vue +317 -0
  50. package/eject/files/Dialog.vue +105 -0
  51. package/eject/files/Divider.vue +15 -0
  52. package/eject/files/EmptyState.vue +28 -0
  53. package/eject/files/Icon.vue +34 -0
  54. package/eject/files/IconButton.vue +71 -0
  55. package/eject/files/Link.vue +48 -0
  56. package/eject/files/ListRow.vue +33 -0
  57. package/eject/files/MediaCard.vue +109 -0
  58. package/eject/files/Menu.vue +181 -0
  59. package/eject/files/Pagination.vue +88 -0
  60. package/eject/files/PlaceRow.vue +54 -0
  61. package/eject/files/Popover.vue +119 -0
  62. package/eject/files/ProgressBar.vue +34 -0
  63. package/eject/files/RadioGroup.vue +126 -0
  64. package/eject/files/SearchField.vue +129 -0
  65. package/eject/files/SectionHeader.vue +37 -0
  66. package/eject/files/SegmentedControl.vue +81 -0
  67. package/eject/files/Select.vue +269 -0
  68. package/eject/files/Sidebar.vue +101 -0
  69. package/eject/files/SidebarRailButton.vue +31 -0
  70. package/eject/files/Skeleton.vue +27 -0
  71. package/eject/files/Slider.vue +126 -0
  72. package/eject/files/Spinner.vue +36 -0
  73. package/eject/files/Switch.vue +88 -0
  74. package/eject/files/Table.vue +77 -0
  75. package/eject/files/Tabs.vue +72 -0
  76. package/eject/files/Text.vue +22 -0
  77. package/eject/files/TextField.vue +190 -0
  78. package/eject/files/Thumbnail.vue +62 -0
  79. package/eject/files/TimePicker.vue +224 -0
  80. package/eject/files/Toast.vue +83 -0
  81. package/eject/files/ToastQueue.vue +54 -0
  82. package/eject/files/Tooltip.vue +28 -0
  83. package/eject/files/TooltipOverlay.vue +86 -0
  84. package/eject/files/accordion.css +89 -0
  85. package/eject/files/accordion.ts +67 -0
  86. package/eject/files/avatar-stack.ts +57 -0
  87. package/eject/files/avatar.ts +42 -0
  88. package/eject/files/badge.ts +30 -0
  89. package/eject/files/banner.ts +71 -0
  90. package/eject/files/base.css +38 -0
  91. package/eject/files/breadcrumb.css +51 -0
  92. package/eject/files/breadcrumb.ts +42 -0
  93. package/eject/files/button.css +241 -0
  94. package/eject/files/button.ts +106 -0
  95. package/eject/files/card.ts +58 -0
  96. package/eject/files/checkbox.ts +52 -0
  97. package/eject/files/chip-bar.ts +16 -0
  98. package/eject/files/chip.ts +35 -0
  99. package/eject/files/combobox.css +269 -0
  100. package/eject/files/combobox.ts +85 -0
  101. package/eject/files/count-badge.ts +32 -0
  102. package/eject/files/date-picker.css +375 -0
  103. package/eject/files/date-picker.ts +280 -0
  104. package/eject/files/date-range-picker.ts +338 -0
  105. package/eject/files/dialog.css +139 -0
  106. package/eject/files/dialog.ts +15 -0
  107. package/eject/files/divider.ts +5 -0
  108. package/eject/files/empty-state.ts +22 -0
  109. package/eject/files/icon.ts +36 -0
  110. package/eject/files/link.css +64 -0
  111. package/eject/files/link.ts +63 -0
  112. package/eject/files/list-row.ts +66 -0
  113. package/eject/files/media-card.ts +66 -0
  114. package/eject/files/menu.css +192 -0
  115. package/eject/files/menu.ts +84 -0
  116. package/eject/files/overlay.css +40 -0
  117. package/eject/files/pagination.css +106 -0
  118. package/eject/files/pagination.ts +68 -0
  119. package/eject/files/parts.ts +17 -0
  120. package/eject/files/popover.css +101 -0
  121. package/eject/files/popover.ts +37 -0
  122. package/eject/files/progress-bar.ts +26 -0
  123. package/eject/files/radio-group.css +184 -0
  124. package/eject/files/radio-group.ts +30 -0
  125. package/eject/files/section-header.ts +32 -0
  126. package/eject/files/segmented-control.ts +33 -0
  127. package/eject/files/select.css +347 -0
  128. package/eject/files/select.ts +77 -0
  129. package/eject/files/sidebar.ts +75 -0
  130. package/eject/files/skeleton.ts +51 -0
  131. package/eject/files/slider.css +160 -0
  132. package/eject/files/slider.ts +80 -0
  133. package/eject/files/spinner.ts +22 -0
  134. package/eject/files/switch.ts +45 -0
  135. package/eject/files/table.css +107 -0
  136. package/eject/files/table.ts +84 -0
  137. package/eject/files/tabs.css +120 -0
  138. package/eject/files/tabs.ts +37 -0
  139. package/eject/files/text-field.css +225 -0
  140. package/eject/files/text-field.ts +64 -0
  141. package/eject/files/text.ts +38 -0
  142. package/eject/files/thumbnail.ts +51 -0
  143. package/eject/files/time-picker.ts +113 -0
  144. package/eject/files/toast-queue.ts +64 -0
  145. package/eject/files/toast.ts +31 -0
  146. package/eject/files/tooltip.css +111 -0
  147. package/eject/files/tooltip.ts +21 -0
  148. package/eject/manifest.json +1122 -0
  149. package/package.json +11 -4
  150. package/styles.css +1066 -168
  151. package/tailwind.css +1295 -218
@@ -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>
@@ -0,0 +1,34 @@
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
+ // An icon from design/icons. It takes the color of the text around it. An arrow or a chevron
7
+ // mirrors itself in a right-to-left layout when given `rtl:-scale-x-100` in `class`, which
8
+ // falls through to the drawing.
9
+ import { icons, useDefaults } from "@xds/vue/base";
10
+ import { type IconBaseProps, iconClass } from "./icon.ts";
11
+ import { classes, rootPart } from "./parts.ts";
12
+
13
+ export type IconProps = IconBaseProps;
14
+
15
+ const { name, size, filled = false, label } = defineProps<IconProps>();
16
+ const options = useDefaults("Icon", () => ({ size }));
17
+ </script>
18
+
19
+ <template>
20
+ <svg
21
+ viewBox="0 0 24 24"
22
+ :fill="filled ? 'currentColor' : 'none'"
23
+ stroke="currentColor"
24
+ stroke-width="2"
25
+ stroke-linecap="round"
26
+ stroke-linejoin="round"
27
+ :class="classes(rootPart('Icon'), iconClass(options.size))"
28
+ :role="label ? 'img' : undefined"
29
+ :aria-label="label || undefined"
30
+ :aria-hidden="label ? undefined : 'true'"
31
+ >
32
+ <path v-for="(path, index) in icons[name]" :key="index" :d="path" />
33
+ </svg>
34
+ </template>
@@ -0,0 +1,71 @@
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 { focusable, useDefaults, useTrigger, withAttributes } from "@xds/vue/base";
7
+ import { type ButtonHTMLAttributes, useTemplateRef } from "vue";
8
+ // A button that holds only an icon, in Button's variants, sizes and states. It is a square as
9
+ // tall as a Button of its size, and its pressable area is never smaller than the minimum
10
+ // target, even when the square is. Like Button, it opens a Menu or a Tooltip it is the trigger
11
+ // of.
12
+ import { buttonClass, ICON_BUTTON_BOX, type IconButtonBaseProps, isHeld } from "./button.ts";
13
+ import Icon from "./Icon.vue";
14
+ import Spinner from "./Spinner.vue";
15
+
16
+ // The app's attributes are bound with the trigger's: see withAttributes.
17
+ defineOptions({ inheritAttrs: false });
18
+ export type IconButtonProps = IconButtonBaseProps;
19
+
20
+ const {
21
+ icon,
22
+ label,
23
+ variant,
24
+ size,
25
+ // Undefined unless given, so that only a toggle says whether it is pressed.
26
+ selected = undefined,
27
+ disabled = false,
28
+ loading = false,
29
+ } = defineProps<IconButtonProps>();
30
+ const emit = defineEmits<{
31
+ press: [];
32
+ focus: [event: FocusEvent];
33
+ blur: [event: FocusEvent];
34
+ }>();
35
+ const button = useTemplateRef<HTMLButtonElement>("button");
36
+ defineExpose(focusable(() => button.value));
37
+ const options = useDefaults("IconButton", () => ({ variant, size }), {
38
+ variant: "ghost",
39
+ size: "md",
40
+ });
41
+
42
+ const attributes = useTrigger(
43
+ (): ButtonHTMLAttributes & { "data-pending"?: "" } => ({
44
+ type: "button",
45
+ class: buttonClass({ ...options.value, iconButton: true }),
46
+ disabled,
47
+ "aria-disabled": loading ? "true" : undefined,
48
+ "data-pending": loading ? "" : undefined,
49
+ "aria-pressed": selected === undefined ? undefined : selected ? "true" : "false",
50
+ "aria-label": label,
51
+ onFocus: (event: FocusEvent) => emit("focus", event),
52
+ onBlur: (event: FocusEvent) => emit("blur", event),
53
+ onClick: () => {
54
+ if (!loading) emit("press");
55
+ },
56
+ }),
57
+ () => loading,
58
+ );
59
+ </script>
60
+
61
+ <template>
62
+ <button ref="button" v-bind="withAttributes(attributes, $attrs)">
63
+ <span v-if="loading" :class="ICON_BUTTON_BOX[options.size]"><Spinner size="sm" /></span>
64
+ <Icon
65
+ v-else
66
+ :name="icon"
67
+ :size="options.size"
68
+ :filled="isHeld({ variant: options.variant, selected, disabled })"
69
+ />
70
+ </button>
71
+ </template>
@@ -0,0 +1,48 @@
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 { focusable } from "@xds/vue/base";
7
+ import { computed, useTemplateRef } from "vue";
8
+ import Icon from "./Icon.vue";
9
+ // Text that takes the person somewhere, in the type of the text around it. It is underlined, so
10
+ // it does not depend on color. With `href` it is a native link; without one, a button that
11
+ // assistive technology hears as a link.
12
+ import { LINK_ICON, LINK_PARTS, type LinkBaseProps, linkElement } from "./link.ts";
13
+ import { rootPart } from "./parts.ts";
14
+
15
+ export type LinkProps = LinkBaseProps;
16
+
17
+ const { href, external = false, disabled = false } = defineProps<LinkProps>();
18
+ /** `press` comes before the browser follows `href`. A disabled link never sends it. */
19
+ const emit = defineEmits<{ press: []; focus: [event: FocusEvent]; blur: [event: FocusEvent] }>();
20
+ const root = useTemplateRef<HTMLElement>("root");
21
+ defineExpose(focusable(() => root.value));
22
+ defineSlots<{
23
+ /** The text, which names the link. */
24
+ default(): unknown;
25
+ }>();
26
+ const element = computed(() => linkElement({ href, external, disabled }));
27
+
28
+ function press() {
29
+ if (!disabled) emit("press");
30
+ }
31
+ </script>
32
+
33
+ <template>
34
+ <component
35
+ :is="element.tag"
36
+ ref="root"
37
+ v-bind="element.attributes"
38
+ :class="rootPart('Link')"
39
+ @click="press"
40
+ @focus="emit('focus', $event)"
41
+ @blur="emit('blur', $event)"
42
+ ><slot /><Icon
43
+ v-if="external"
44
+ :name="LINK_ICON.name"
45
+ :size="LINK_ICON.size"
46
+ :class="LINK_PARTS.icon"
47
+ /></component>
48
+ </template>
@@ -0,0 +1,33 @@
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
+ // One line of a list or a settings screen. Separate rows with a Divider.
7
+ import type { ListRowBaseProps } from "./list-row.ts";
8
+ import { rootPart } from "./parts.ts";
9
+ import PlaceRow from "./PlaceRow.vue";
10
+
11
+ export type ListRowProps = ListRowBaseProps & {
12
+ /**
13
+ * Makes the whole row a button. Do not put another control in `trailing` then. A prop rather
14
+ * than an event, since whether there is one decides what is drawn.
15
+ */
16
+ onPress?: () => void;
17
+ };
18
+
19
+ const props = defineProps<ListRowProps>();
20
+ defineSlots<{
21
+ /** In front of the title: an avatar or an icon. */
22
+ leading?(): unknown;
23
+ /** At the far end: a value, a badge or a switch. */
24
+ trailing?(): unknown;
25
+ }>();
26
+ </script>
27
+
28
+ <template>
29
+ <PlaceRow v-bind="props" current="true" :class="rootPart('ListRow')">
30
+ <template v-if="$slots.leading" #leading><slot name="leading" /></template>
31
+ <template v-if="$slots.trailing" #trailing><slot name="trailing" /></template>
32
+ </PlaceRow>
33
+ </template>