@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,190 @@
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, keepValue, useControllable, useFormReset } from "@xds/vue/base";
7
+ import { computed, onMounted, useId, useTemplateRef, watch } from "vue";
8
+ // A labelled text field, of one line or several. The label, the description and the error
9
+ // message are tied to the input for assistive technology, and the error is announced when it
10
+ // appears.
11
+ //
12
+ // An invalid field blocks its form from being submitted, so `error` has to be cleared as soon as
13
+ // the person edits the value.
14
+ import type { TextFieldBaseProps } from "./text-field.ts";
15
+
16
+ // `autoComplete` is a string, as Vue's own `autocomplete` attribute is: the union of every
17
+ // autofill token that the shared type lists is too large for vue-tsc to destructure the props.
18
+ // The shared type takes any other string too, so what this gives up is the editor's list.
19
+ export type TextFieldProps = Omit<TextFieldBaseProps, "autoComplete"> & {
20
+ autoComplete?: string;
21
+ };
22
+
23
+ // `v-model:value`, written out rather than with defineModel: see useControllable.
24
+ const {
25
+ value: given,
26
+ defaultValue = "",
27
+ readOnly = false,
28
+ label,
29
+ description,
30
+ error,
31
+ placeholder,
32
+ multiline = false,
33
+ rows = 3,
34
+ maxLength,
35
+ name,
36
+ type = "text",
37
+ inputMode,
38
+ autoComplete: autocomplete,
39
+ autoFocus = false,
40
+ required = false,
41
+ disabled = false,
42
+ } = defineProps<TextFieldProps>();
43
+ const emit = defineEmits<{
44
+ "update:value": [value: string];
45
+ // On the input or the text area, which the root holds.
46
+ focus: [event: FocusEvent];
47
+ blur: [event: FocusEvent];
48
+ }>();
49
+ const slots = defineSlots<{
50
+ /**
51
+ * Inside the box, in front of the text: an icon, a unit. It takes the placeholder's color
52
+ * unless it sets its own.
53
+ */
54
+ leading?(): unknown;
55
+ /** Inside the box, after the text: an icon, a unit, a small button. */
56
+ trailing?(): unknown;
57
+ }>();
58
+
59
+ const id = useId();
60
+ const descriptionId = `${id}-description`;
61
+ const errorId = `${id}-error`;
62
+ const invalid = computed(() => error !== undefined);
63
+ const input = useTemplateRef<HTMLInputElement | HTMLTextAreaElement>("input");
64
+ const { value, set, controlled, reset } = useControllable(
65
+ "value",
66
+ () => given,
67
+ () => defaultValue,
68
+ (next) => emit("update:value", next),
69
+ );
70
+ useFormReset(() => input.value, controlled, reset);
71
+ defineExpose(focusable(() => input.value));
72
+ // The input draws the box itself until something sits inside the box beside the text.
73
+ const grouped = computed(() => slots.leading !== undefined || slots.trailing !== undefined);
74
+
75
+ onMounted(() => {
76
+ // The value is set as a property, which leaves a text area's caret after the last line, and
77
+ // keyboard focus would then scroll to it. React renders the first value as the text area's
78
+ // own text, with the caret before the first line.
79
+ if (input.value instanceof HTMLTextAreaElement) input.value.setSelectionRange(0, 0);
80
+ if (autoFocus) input.value?.focus();
81
+ });
82
+
83
+ watch(
84
+ [() => error, () => multiline],
85
+ () => {
86
+ input.value?.setCustomValidity(error ?? "");
87
+ },
88
+ { flush: "post", immediate: true },
89
+ );
90
+
91
+ // The attributes the input and the text area share.
92
+ const shared = computed(() => ({
93
+ id,
94
+ class: grouped.value
95
+ ? "{{prefix}}-text-field__input"
96
+ : "{{prefix}}-text-field__input {{prefix}}-text-field__control",
97
+ value: value.value,
98
+ // A form's reset puts a field back to its default value: for an input its `value` attribute,
99
+ // which Vue writes, but for a text area its text, which Vue leaves empty. React keeps both
100
+ // equal to the value.
101
+ defaultValue: value.value,
102
+ placeholder,
103
+ name,
104
+ maxlength: maxLength,
105
+ inputmode: inputMode,
106
+ autocomplete,
107
+ required,
108
+ disabled,
109
+ readonly: readOnly,
110
+ "aria-invalid": invalid.value ? ("true" as const) : undefined,
111
+ "aria-errormessage": invalid.value ? errorId : undefined,
112
+ "aria-describedby": invalid.value ? errorId : description ? descriptionId : undefined,
113
+ onFocus: (event: FocusEvent) => emit("focus", event),
114
+ onBlur: (event: FocusEvent) => emit("blur", event),
115
+ }));
116
+
117
+ function edit(event: Event) {
118
+ const field = event.currentTarget as HTMLInputElement | HTMLTextAreaElement;
119
+ set(field.value);
120
+ // While a composition is open the text belongs to the input method; it ends with
121
+ // compositionend.
122
+ if (!(event as InputEvent).isComposing) keepValue(field, () => value.value);
123
+ }
124
+ function settle(event: CompositionEvent) {
125
+ keepValue(event.currentTarget as HTMLInputElement, () => value.value);
126
+ }
127
+ </script>
128
+
129
+ <template>
130
+ <div class="{{prefix}}-text-field">
131
+ <label :for="id" class="{{prefix}}-text-field__label">{{ label }}</label>
132
+ <div v-if="grouped" class="{{prefix}}-text-field__control {{prefix}}-text-field__group">
133
+ <span
134
+ v-if="slots.leading"
135
+ class="{{prefix}}-text-field__slot {{prefix}}-text-field__slot--leading"
136
+ >
137
+ <slot name="leading" />
138
+ </span>
139
+ <textarea
140
+ v-if="multiline"
141
+ ref="input"
142
+ :rows="rows"
143
+ v-bind="shared"
144
+ @input="edit"
145
+ @compositionend="settle"
146
+ />
147
+ <input
148
+ v-else
149
+ ref="input"
150
+ :type="type"
151
+ v-bind="shared"
152
+ @input="edit"
153
+ @compositionend="settle"
154
+ />
155
+ <span
156
+ v-if="slots.trailing"
157
+ class="{{prefix}}-text-field__slot {{prefix}}-text-field__slot--trailing"
158
+ >
159
+ <slot name="trailing" />
160
+ </span>
161
+ </div>
162
+ <textarea
163
+ v-else-if="multiline"
164
+ ref="input"
165
+ :rows="rows"
166
+ v-bind="shared"
167
+ @input="edit"
168
+ @compositionend="settle"
169
+ />
170
+ <input v-else ref="input" :type="type" v-bind="shared" @input="edit" @compositionend="settle" />
171
+ <!-- One line under the box: the help or the error at the start edge, the count at the end.
172
+ The error is a live region, so it is announced when it appears. -->
173
+ <div class="{{prefix}}-text-field__footer">
174
+ <span
175
+ v-if="!invalid && description"
176
+ :id="descriptionId"
177
+ class="{{prefix}}-text-field__description"
178
+ >
179
+ {{ description }}
180
+ </span>
181
+ <span :id="errorId" class="{{prefix}}-text-field__error" aria-live="polite">{{ error }}</span>
182
+ <span
183
+ v-if="maxLength !== undefined"
184
+ class="ms-auto shrink-0 text-xds-footnote text-xds-text-secondary tabular-nums"
185
+ >
186
+ {{ value.length }}/{{ maxLength }}
187
+ </span>
188
+ </div>
189
+ </div>
190
+ </template>
@@ -0,0 +1,62 @@
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 { pictureClass, useDefaults, usePicture } from "@xds/vue/base";
7
+ import { computed } from "vue";
8
+ import Badge from "./Badge.vue";
9
+ import Icon from "./Icon.vue";
10
+ // A picture in a fixed shape, for a video, an article or a product. It fills the width it is
11
+ // given and takes its height from `ratio`, and crops the picture to fill it.
12
+ import { classes, rootPart } from "./parts.ts";
13
+ import {
14
+ THUMBNAIL_PARTS,
15
+ type ThumbnailBaseProps,
16
+ thumbnailBadgeClass,
17
+ thumbnailClass,
18
+ thumbnailWatched,
19
+ } from "./thumbnail.ts";
20
+
21
+ export type { ThumbnailRatio } from "./thumbnail.ts";
22
+
23
+ export type ThumbnailProps = ThumbnailBaseProps;
24
+
25
+ const { src, alt, ratio, badge, progress } = defineProps<ThumbnailProps>();
26
+ const options = useDefaults("Thumbnail", () => ({ ratio }));
27
+ const picture = usePicture(() => src);
28
+ const watched = computed(() => thumbnailWatched(progress));
29
+ </script>
30
+
31
+ <template>
32
+ <span :class="classes(rootPart('Thumbnail'), thumbnailClass(options.ratio))">
33
+ <!-- The placeholder is the picture's stand-in for assistive technology too, so the
34
+ description is on the box that always shows, not on the picture that may not. -->
35
+ <span
36
+ :class="THUMBNAIL_PARTS.placeholder"
37
+ :role="alt ? 'img' : undefined"
38
+ :aria-label="alt || undefined"
39
+ :aria-hidden="alt ? undefined : 'true'"
40
+ >
41
+ <Icon v-if="picture.loaded.value !== true" name="image" size="lg" />
42
+ <img
43
+ v-if="picture.loaded.value !== false && src"
44
+ :ref="(el) => picture.sync(el, src)"
45
+ :src="src"
46
+ alt=""
47
+ aria-hidden="true"
48
+ :class="pictureClass(picture.loaded.value === true)"
49
+ @load="picture.onLoad(src)"
50
+ @error="picture.onError(src)"
51
+ />
52
+ </span>
53
+ <span v-if="badge" :class="thumbnailBadgeClass(watched)">
54
+ <Badge tone="overlay">{{ badge }}</Badge>
55
+ </span>
56
+ <!-- Decoration: what was watched is for the eye, and a list that needs it said says it in
57
+ words. -->
58
+ <span v-if="watched > 0" aria-hidden="true" :class="THUMBNAIL_PARTS.track">
59
+ <span :class="THUMBNAIL_PARTS.fill" :style="{ width: `${watched * 100}%` }" />
60
+ </span>
61
+ </span>
62
+ </template>
@@ -0,0 +1,224 @@
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 time of day. Closed, it looks like a Select with a clock: the chosen
7
+ // time on the locale's own clock ("9:30 AM", "09:30"). Pressed, it opens the times from `min` to
8
+ // `max`, `step` minutes apart, under itself, with the chosen one in view; choosing one sets the
9
+ // value as `HH:MM` on a 24-hour clock and closes the list.
10
+ //
11
+ // The field is a button that says it opens a list box, as a Select's does: the arrow keys move,
12
+ // typing the hour jumps to it, and Enter chooses. Without `value` it keeps its own choice, from
13
+ // `defaultValue`.
14
+ import {
15
+ keepListKeys,
16
+ Portal,
17
+ readCssPx,
18
+ space,
19
+ underlayLayerStyle,
20
+ useControllable,
21
+ useFormReset,
22
+ useModalPopover,
23
+ usePresence,
24
+ } from "@xds/vue/base";
25
+ import * as select from "@zag-js/select";
26
+ import { normalizeProps, useMachine } from "@zag-js/vue";
27
+ import { computed, useId, useTemplateRef } from "vue";
28
+ import Icon from "./Icon.vue";
29
+ import type { SelectOption } from "./select.ts";
30
+ import {
31
+ type IsoTime,
32
+ type TimePickerBaseProps,
33
+ timeOptions,
34
+ timePickerIds,
35
+ timePickerLocale,
36
+ } from "./time-picker.ts";
37
+
38
+ export type { IsoTime } from "./time-picker.ts";
39
+
40
+ export type TimePickerProps = TimePickerBaseProps;
41
+
42
+ type KeyHandler = (event: KeyboardEvent) => void;
43
+
44
+ const {
45
+ value: given,
46
+ defaultValue,
47
+ label,
48
+ min,
49
+ max,
50
+ step,
51
+ placeholder,
52
+ description,
53
+ error,
54
+ name,
55
+ disabled = false,
56
+ locale,
57
+ } = defineProps<TimePickerProps>();
58
+ // `v-model:value`: the chosen time, as `HH:MM` on a 24-hour clock.
59
+ const emit = defineEmits<{ "update:value": [value: IsoTime] }>();
60
+ const { value, set, controlled, reset } = useControllable<IsoTime | undefined>(
61
+ "value",
62
+ () => given,
63
+ () => defaultValue,
64
+ (next) => {
65
+ if (next !== undefined) emit("update:value", next);
66
+ },
67
+ );
68
+ const root = useTemplateRef<HTMLDivElement>("root");
69
+ useFormReset(() => root.value, controlled, reset);
70
+
71
+ const id = useId();
72
+ const ids = timePickerIds(id);
73
+ const invalid = computed(() => error !== undefined);
74
+ const options = computed(() =>
75
+ timeOptions({ min, max, step, value: value.value }, timePickerLocale(locale)),
76
+ );
77
+ const collection = computed(() =>
78
+ select.collection<SelectOption<IsoTime>>({
79
+ items: options.value,
80
+ itemToValue: (option) => option.value,
81
+ itemToString: (option) => option.label,
82
+ }),
83
+ );
84
+ const service = useMachine(
85
+ select.machine,
86
+ computed(() => ({
87
+ id,
88
+ collection: collection.value,
89
+ value: value.value === undefined ? [] : [value.value],
90
+ onValueChange: (details: select.ValueChangeDetails<SelectOption<IsoTime>>) => {
91
+ const next = details.value[0];
92
+ if (next !== undefined) set(next);
93
+ },
94
+ disabled,
95
+ invalid: invalid.value,
96
+ positioning: {
97
+ placement: "bottom-start" as const,
98
+ gutter: readCssPx(null, "--xds-space-1", space[1]),
99
+ sameWidth: true,
100
+ overflowPadding: readCssPx(null, "--xds-space-3", space[3]),
101
+ },
102
+ })),
103
+ );
104
+ const api = computed(() => select.connect(service, normalizeProps));
105
+ // As in Select: a handler taken from the machine when the key comes reads whether a search by
106
+ // typing is still under way.
107
+ const current = () => select.connect(service, normalizeProps);
108
+ // A span: the field is a button, which a <label> cannot point at.
109
+ const labelProps = computed(() => {
110
+ const { for: _, ...rest } = api.value.getLabelProps();
111
+ return rest;
112
+ });
113
+ const triggerProps = computed(() => {
114
+ const {
115
+ role: _role,
116
+ "aria-invalid": _invalid,
117
+ "aria-required": _required,
118
+ onKeydown: _onKeydown,
119
+ ...rest
120
+ } = api.value.getTriggerProps();
121
+ return {
122
+ ...rest,
123
+ onKeydown: (event: KeyboardEvent) => {
124
+ if (!api.value.open && (event.key === "Home" || event.key === "End")) return;
125
+ (current().getTriggerProps().onKeydown as KeyHandler | undefined)?.(event);
126
+ },
127
+ };
128
+ });
129
+ const positioner = useTemplateRef<HTMLDivElement>("positioner");
130
+ const surface = useTemplateRef<HTMLDivElement>("surface");
131
+ useModalPopover(
132
+ () => api.value.open,
133
+ () => positioner.value,
134
+ );
135
+ const present = usePresence(
136
+ () => api.value.open,
137
+ () => [surface.value],
138
+ );
139
+ const content = computed(() => {
140
+ const { onKeydown: _onKeydown, ...rest } = api.value.getContentProps();
141
+ return {
142
+ ...rest,
143
+ onKeydown: (event: KeyboardEvent) => {
144
+ keepListKeys(
145
+ event,
146
+ surface.value,
147
+ ".{{prefix}}-time-picker__item:not([data-disabled])",
148
+ (next) => api.value.setHighlightedValue(next),
149
+ );
150
+ (current().getContentProps().onKeydown as KeyHandler | undefined)?.(event);
151
+ },
152
+ };
153
+ });
154
+ </script>
155
+
156
+ <template>
157
+ <div ref="root" v-bind="api.getRootProps()" class="{{prefix}}-time-picker">
158
+ <span v-bind="labelProps" class="{{prefix}}-time-picker__label">{{ label }}</span>
159
+ <button
160
+ v-bind="triggerProps"
161
+ :aria-labelledby="`${ids.value} ${labelProps.id}`"
162
+ :aria-describedby="invalid ? ids.error : description ? ids.description : undefined"
163
+ class="{{prefix}}-time-picker__trigger"
164
+ >
165
+ <span v-bind="api.getValueTextProps()" :id="ids.value" class="{{prefix}}-time-picker__value">
166
+ {{ api.valueAsString || placeholder }}
167
+ </span>
168
+ <Icon name="clock" size="sm" class="text-xds-field-placeholder" />
169
+ </button>
170
+ <div class="{{prefix}}-time-picker__footer">
171
+ <span
172
+ v-if="!invalid && description"
173
+ :id="ids.description"
174
+ class="{{prefix}}-time-picker__description"
175
+ >
176
+ {{ description }}
177
+ </span>
178
+ <span :id="ids.error" class="{{prefix}}-time-picker__error" aria-live="polite">{{
179
+ error
180
+ }}</span>
181
+ </div>
182
+ <!-- What a form submits: the time as HH:MM, where the field shows it on the locale's clock. -->
183
+ <input v-if="name !== undefined" type="hidden" :name="name" :value="value ?? ''" />
184
+ <Portal>
185
+ <div
186
+ v-if="api.open"
187
+ class="{{prefix}}-time-picker__underlay"
188
+ :style="underlayLayerStyle(api.getPositionerProps().style)"
189
+ @mousedown.prevent
190
+ />
191
+ <div
192
+ ref="positioner"
193
+ v-bind="api.getPositionerProps()"
194
+ class="{{prefix}}-time-picker__positioner"
195
+ >
196
+ <div
197
+ v-bind="content"
198
+ ref="surface"
199
+ :hidden="!present"
200
+ class="{{prefix}}-time-picker__content"
201
+ >
202
+ <div v-bind="api.getListProps()" class="{{prefix}}-time-picker__list">
203
+ <div
204
+ v-for="option in collection.items"
205
+ :key="option.value"
206
+ v-bind="api.getItemProps({ item: option })"
207
+ class="{{prefix}}-time-picker__item"
208
+ >
209
+ <span class="{{prefix}}-time-picker__item-words">
210
+ <span
211
+ v-bind="api.getItemTextProps({ item: option })"
212
+ class="{{prefix}}-time-picker__item-label"
213
+ >
214
+ {{ option.label }}
215
+ </span>
216
+ </span>
217
+ <Icon v-if="api.getItemState({ item: option }).selected" name="check" size="sm" />
218
+ </div>
219
+ </div>
220
+ </div>
221
+ </div>
222
+ </Portal>
223
+ </div>
224
+ </template>
@@ -0,0 +1,83 @@
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 short message about what just happened, which leaves on its own. It sits at the bottom
7
+ // center of the window, above everything else, and is announced politely without taking
8
+ // focus. The time does not run while the pointer is over it or focus is inside it.
9
+ //
10
+ // Do not put the only way to do something in a toast: it is gone in a few seconds.
11
+ import { motion, readCssMs } from "@xds/vue/base";
12
+ import { onBeforeUnmount, onMounted, ref, useTemplateRef, watchEffect } from "vue";
13
+ import { rootPart } from "./parts.ts";
14
+ import { TOAST_PARTS, type ToastBaseProps } from "./toast.ts";
15
+
16
+ export type ToastProps = ToastBaseProps;
17
+
18
+ // What the app puts on the root (its class, style, id and `data-*` attributes) goes on the toast
19
+ // itself, not on the region across the bottom of the window that it rises in.
20
+ defineOptions({ inheritAttrs: false });
21
+ const { open, message, action, duration } = defineProps<ToastProps>();
22
+ const emit = defineEmits<{
23
+ /** When the time is up and after the action. Set `open` to false in it. */
24
+ close: [];
25
+ }>();
26
+
27
+ const region = useTemplateRef<HTMLDivElement>("region");
28
+ // Vue's types for the DOM do not list `popover` yet.
29
+ const popover: Record<string, string> = { popover: "manual" };
30
+ // The toast the pointer is over and the one focus is in. A toast that closed under the pointer
31
+ // gets no event to say that the pointer left, so only one still in the page counts.
32
+ const hovered = ref<Element>();
33
+ const focused = ref<Element>();
34
+ const inPage = (toast: Element | undefined) => toast?.isConnected === true;
35
+
36
+ // The region is in the top layer for as long as the component is mounted, empty or not: a
37
+ // screen reader only announces what is added to a region it already knows.
38
+ onMounted(() => region.value?.showPopover?.());
39
+ onBeforeUnmount(() => {
40
+ const element = region.value;
41
+ if (element?.isConnected && element.matches(":popover-open")) element.hidePopover();
42
+ });
43
+
44
+ watchEffect((onCleanup) => {
45
+ // Touch `message` so a replacement toast restarts the timer.
46
+ void message;
47
+ const ms =
48
+ duration ?? readCssMs(region.value, "--xds-motion-duration-toast", motion.duration.toast);
49
+ if (!open || inPage(hovered.value) || inPage(focused.value) || ms <= 0) return;
50
+ const timer = setTimeout(() => emit("close"), ms);
51
+ onCleanup(() => clearTimeout(timer));
52
+ });
53
+
54
+ function press(run: () => void) {
55
+ run();
56
+ emit("close");
57
+ }
58
+ </script>
59
+
60
+ <template>
61
+ <div ref="region" v-bind="popover" role="status" :class="TOAST_PARTS.region">
62
+ <!-- Hover and focus only pause the timer; the action inside is a real button. -->
63
+ <div
64
+ v-if="open"
65
+ v-bind="$attrs"
66
+ :class="[rootPart('Toast'), TOAST_PARTS.toast]"
67
+ @pointerenter="hovered = $event.currentTarget as Element"
68
+ @pointerleave="hovered = undefined"
69
+ @focusin="focused = $event.currentTarget as Element"
70
+ @focusout="focused = undefined"
71
+ >
72
+ <span :class="TOAST_PARTS.message">{{ message }}</span>
73
+ <button
74
+ v-if="action"
75
+ type="button"
76
+ :class="TOAST_PARTS.action"
77
+ @click="press(action.onPress)"
78
+ >
79
+ {{ action.label }}
80
+ </button>
81
+ </div>
82
+ </div>
83
+ </template>
@@ -0,0 +1,54 @@
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
+ // Shows the app's toasts one at a time, in their order: the first of `toasts`, which stays for
7
+ // its own `duration` or until its action is taken, and then the next, `motion.duration.normal`
8
+ // after the one before has gone, so that each is read and announced as a message of its own.
9
+ // Add a toast with `queueToast`, which keeps at most three waiting, and take one out on
10
+ // `close`. Put one where a single Toast would go.
11
+ import { motion, readCssMs } from "@xds/vue/base";
12
+ import { computed, ref, watch } from "vue";
13
+ import { type QueuedToast, type ToastQueueBaseProps, toastQueueStep } from "./toast-queue.ts";
14
+ import Toast from "./Toast.vue";
15
+
16
+ export type ToastQueueProps = ToastQueueBaseProps;
17
+
18
+ const props = defineProps<ToastQueueProps>();
19
+ const emit = defineEmits<{
20
+ /** With a toast's id, when its time is up or its action was taken. Take it out of `toasts`. */
21
+ close: [id: QueuedToast["id"]];
22
+ }>();
23
+
24
+ const visible = ref<QueuedToast["id"]>();
25
+ const step = computed(() => toastQueueStep(props.toasts, visible.value));
26
+ const shown = computed(() => (step.value === "keep" ? props.toasts[0] : undefined));
27
+
28
+ // A watcher, not `watchEffect`: closing sets `visible`, which changes the step again, and only a
29
+ // watcher's callback runs again for a change it made itself.
30
+ watch(
31
+ [step, () => props.toasts[0]],
32
+ ([current, first], _, onCleanup) => {
33
+ if (current === "close") {
34
+ visible.value = undefined;
35
+ return;
36
+ }
37
+ if (current !== "wait" || first === undefined) return;
38
+ const gap = readCssMs(null, "--xds-motion-duration-normal", motion.duration.normal);
39
+ const timer = setTimeout(() => (visible.value = first.id), gap);
40
+ onCleanup(() => clearTimeout(timer));
41
+ },
42
+ { immediate: true },
43
+ );
44
+ </script>
45
+
46
+ <template>
47
+ <Toast
48
+ :open="shown !== undefined"
49
+ :message="shown?.message ?? ''"
50
+ :action="shown?.action"
51
+ :duration="shown?.duration"
52
+ @close="shown !== undefined && emit('close', shown.id)"
53
+ />
54
+ </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
+ // Names a control when the pointer rests on it or the keyboard focuses it. It appears after a
7
+ // short wait under a pointer and at once on keyboard focus, and goes when the pointer leaves,
8
+ // focus leaves, or Escape is pressed.
9
+ //
10
+ // It describes the control and is not its name: an IconButton still needs its `label`. It
11
+ // never holds anything pressable, and touch input has no hover, so nothing may depend on it.
12
+ import type { TooltipBaseProps } from "./tooltip.ts";
13
+ import TooltipOverlay from "./TooltipOverlay.vue";
14
+
15
+ export type TooltipProps = TooltipBaseProps;
16
+
17
+ const { label, shortcut, placement = "top" } = defineProps<TooltipProps>();
18
+ defineSlots<{
19
+ /** The control it describes: a Button or an IconButton. */
20
+ default(): unknown;
21
+ }>();
22
+ </script>
23
+
24
+ <template>
25
+ <TooltipOverlay :label="label" :shortcut="shortcut" :placement="placement"
26
+ ><slot
27
+ /></TooltipOverlay>
28
+ </template>