@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,104 @@
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 {
7
+ focusable,
8
+ formDefault,
9
+ keepChecked,
10
+ useControllable,
11
+ useFormReset,
12
+ } from "@xds/vue/base";
13
+ import { useTemplateRef, watchEffect } from "vue";
14
+ // A choice that is applied later, with the form it belongs to. A native checkbox: the input is
15
+ // hidden and the box is drawn beside it. Without `checked` it keeps its own state, from
16
+ // `defaultChecked`. With `indeterminate` it shows a dash and is reported as mixed.
17
+ import {
18
+ type CheckboxBaseProps,
19
+ checkboxBoxClass,
20
+ checkboxClass,
21
+ checkboxLabelClass,
22
+ checkboxMark,
23
+ checkboxMarkClass,
24
+ } from "./checkbox.ts";
25
+ import { classes, rootPart } from "./parts.ts";
26
+
27
+ // `aria-label` is declared as `ariaLabel`: Vue keeps a prop under its camelized name, and a
28
+ // template still writes `aria-label`.
29
+ export type CheckboxProps = Omit<CheckboxBaseProps, "aria-label"> & { ariaLabel?: string };
30
+
31
+ // `v-model:checked`, written out rather than with defineModel: see useControllable.
32
+ const {
33
+ checked: given,
34
+ defaultChecked = false,
35
+ indeterminate = false,
36
+ label,
37
+ ariaLabel,
38
+ name,
39
+ disabled = false,
40
+ } = defineProps<CheckboxProps>();
41
+ const emit = defineEmits<{
42
+ "update:checked": [checked: boolean];
43
+ // On the native checkbox: the label, the root, never takes the focus.
44
+ focus: [event: FocusEvent];
45
+ blur: [event: FocusEvent];
46
+ }>();
47
+
48
+ const input = useTemplateRef<HTMLInputElement>("input");
49
+ const {
50
+ value: checked,
51
+ set,
52
+ controlled,
53
+ reset,
54
+ } = useControllable(
55
+ "checked",
56
+ () => given,
57
+ () => defaultChecked,
58
+ (next) => emit("update:checked", next),
59
+ );
60
+ useFormReset(() => input.value, controlled, reset);
61
+ defineExpose(focusable(() => input.value));
62
+ // A property of the native input, with no attribute: it is what reports the box as mixed.
63
+ watchEffect(() => {
64
+ if (input.value) input.value.indeterminate = indeterminate;
65
+ });
66
+
67
+ function change(event: Event) {
68
+ const element = event.currentTarget as HTMLInputElement;
69
+ // A press clears it on the input; it stays until the app clears it.
70
+ element.indeterminate = indeterminate;
71
+ set(element.checked);
72
+ keepChecked(element, () => checked.value);
73
+ }
74
+ </script>
75
+
76
+ <template>
77
+ <label :class="classes(rootPart('Checkbox'), checkboxClass)">
78
+ <input
79
+ ref="input"
80
+ type="checkbox"
81
+ :aria-label="ariaLabel"
82
+ class="peer sr-only"
83
+ :checked="checked"
84
+ v-bind="formDefault({ defaultChecked: checked })"
85
+ :disabled="disabled"
86
+ :name="name || undefined"
87
+ @change="change"
88
+ @focus="emit('focus', $event)"
89
+ @blur="emit('blur', $event)"
90
+ />
91
+ <span :class="checkboxBoxClass">
92
+ <svg viewBox="0 0 16 16" fill="none" aria-hidden="true" :class="checkboxMarkClass">
93
+ <path
94
+ :d="checkboxMark(indeterminate)"
95
+ stroke="currentColor"
96
+ stroke-width="2"
97
+ stroke-linecap="round"
98
+ stroke-linejoin="round"
99
+ />
100
+ </svg>
101
+ </span>
102
+ <span v-if="label" :class="checkboxLabelClass">{{ label }}</span>
103
+ </label>
104
+ </template>
@@ -0,0 +1,32 @@
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 { computed } from "vue";
7
+ // A choice that filters what is shown. Unlike a Badge it is pressed. A selected chip is tinted,
8
+ // outlined and marked with a check, so the state does not depend on color.
9
+ //
10
+ // It is a toggle button: assistive technology hears whether it is pressed.
11
+ import { type ChipBaseProps, chipClass, chipIcon } from "./chip.ts";
12
+ import Icon from "./Icon.vue";
13
+ import { classes, rootPart } from "./parts.ts";
14
+
15
+ export type ChipProps = ChipBaseProps;
16
+
17
+ const { label, selected = false, disabled = false, iconStart } = defineProps<ChipProps>();
18
+ const emit = defineEmits<{ press: [] }>();
19
+ const icon = computed(() => chipIcon({ selected, iconStart }));
20
+ </script>
21
+
22
+ <template>
23
+ <button
24
+ type="button"
25
+ :aria-pressed="selected ? 'true' : 'false'"
26
+ :disabled="disabled"
27
+ :class="classes(rootPart('Chip'), chipClass(selected))"
28
+ @click="emit('press')"
29
+ >
30
+ <Icon v-if="icon" :name="icon" size="sm" />{{ label }}
31
+ </button>
32
+ </template>
@@ -0,0 +1,25 @@
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 row of chips. It scrolls sideways when the chips do not fit and never wraps, so the
7
+ // content under it stays where it is.
8
+ import { type ChipBarBaseProps, chipBarClass } from "./chip-bar.ts";
9
+ import { classes, rootPart } from "./parts.ts";
10
+
11
+ export type ChipBarProps = ChipBarBaseProps;
12
+
13
+ const { label } = defineProps<ChipBarProps>();
14
+ defineSlots<{
15
+ /** The chips. Which of them are selected is the app's business: the bar holds no state. */
16
+ default(): unknown;
17
+ }>();
18
+ </script>
19
+
20
+ <template>
21
+ <!-- A group, not a fieldset: a fieldset cannot be a scrolling flex row in every browser. -->
22
+ <div role="group" :aria-label="label" :class="classes(rootPart('ChipBar'), chipBarClass)">
23
+ <slot />
24
+ </div>
25
+ </template>
@@ -0,0 +1,175 @@
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" generic="Value extends string = string">
6
+ import {
7
+ Portal,
8
+ readCssPx,
9
+ type SelectOption,
10
+ selectOptionIds,
11
+ space,
12
+ useControllable,
13
+ useFormReset,
14
+ useLabels,
15
+ } from "@xds/vue/base";
16
+ import * as combobox from "@zag-js/combobox";
17
+ import { mergeProps, normalizeProps, useMachine } from "@zag-js/vue";
18
+ import { computed, shallowRef, useId, useTemplateRef } from "vue";
19
+ import { COMBOBOX_PARTS as PARTS, type ComboboxBaseProps, matchOptions } from "./combobox.ts";
20
+ import Icon from "./Icon.vue";
21
+
22
+ export type ComboboxProps<Value extends string = string> = ComboboxBaseProps<Value>;
23
+
24
+ // A field for choosing one option from a list by typing part of its name. As the person types,
25
+ // the options whose label holds what was typed open under it, those that start with it first,
26
+ // and the first is highlighted, so Enter chooses it. Choosing an option emits `update:value`,
27
+ // puts its label in the field and closes the list. Text that names no option goes back to the
28
+ // chosen option's label when the field is left. When nothing matches, the list says so.
29
+ const {
30
+ value: given,
31
+ defaultValue,
32
+ label,
33
+ options,
34
+ placeholder,
35
+ description,
36
+ error,
37
+ name,
38
+ disabled = false,
39
+ emptyLabel,
40
+ } = defineProps<ComboboxProps<Value>>();
41
+ const emit = defineEmits<{ "update:value": [value: Value] }>();
42
+ const labels = useLabels();
43
+ const { value, set, controlled, reset } = useControllable<Value | undefined>(
44
+ "value",
45
+ () => given,
46
+ () => defaultValue,
47
+ (next) => {
48
+ if (next !== undefined) emit("update:value", next);
49
+ },
50
+ );
51
+ const root = useTemplateRef<HTMLDivElement>("root");
52
+ useFormReset(() => root.value, controlled, reset);
53
+
54
+ const id = useId();
55
+ const descriptionId = `${id}-description`;
56
+ const errorId = `${id}-error`;
57
+ const invalid = computed(() => error !== undefined);
58
+ // What the person typed, which narrows the list. Choosing an option puts its label in the field
59
+ // without narrowing it, so the list opens on every option again.
60
+ const query = shallowRef("");
61
+ const shown = computed(() => matchOptions(options, query.value));
62
+ const collection = computed(() =>
63
+ combobox.collection<SelectOption<Value>>({
64
+ items: shown.value,
65
+ itemToValue: (option) => option.value,
66
+ itemToString: (option) => option.label,
67
+ }),
68
+ );
69
+ const service = useMachine(
70
+ combobox.machine,
71
+ computed(() => ({
72
+ id,
73
+ collection: collection.value,
74
+ value: value.value === undefined ? [] : [value.value],
75
+ onValueChange: (details: combobox.ValueChangeDetails<SelectOption<Value>>) => {
76
+ const next = details.value[0];
77
+ if (next !== undefined) set(next as Value);
78
+ },
79
+ onInputValueChange: (details: combobox.InputValueChangeDetails) => {
80
+ if (details.reason === "input-change") query.value = details.inputValue;
81
+ },
82
+ onOpenChange: (details: combobox.OpenChangeDetails) => {
83
+ if (!details.open) query.value = "";
84
+ },
85
+ // The first match is highlighted as the person types, so Enter chooses it.
86
+ inputBehavior: "autohighlight" as const,
87
+ selectionBehavior: "replace" as const,
88
+ openOnClick: true,
89
+ disabled,
90
+ invalid: invalid.value,
91
+ placeholder,
92
+ positioning: {
93
+ placement: "bottom-start" as const,
94
+ gutter: readCssPx(null, "--xds-space-1", space[1]),
95
+ sameWidth: true,
96
+ overflowPadding: readCssPx(null, "--xds-space-3", space[3]),
97
+ },
98
+ })),
99
+ );
100
+ const api = computed(() => combobox.connect(service, normalizeProps));
101
+ // Zag puts the chosen label back only when the list closes by a press outside; after Escape,
102
+ // text that names no option would stay in a field that has left it.
103
+ const input = computed(() =>
104
+ mergeProps(api.value.getInputProps(), {
105
+ onBlur: () => {
106
+ const chosen = options.find((option) => option.value === value.value)?.label ?? "";
107
+ const now = combobox.connect(service, normalizeProps);
108
+ if (now.inputValue !== chosen) now.setInputValue(chosen, "script");
109
+ },
110
+ }),
111
+ );
112
+ </script>
113
+
114
+ <template>
115
+ <div ref="root" v-bind="api.getRootProps()" class="{{prefix}}-combobox">
116
+ <label v-bind="api.getLabelProps()" :class="PARTS.label">{{ label }}</label>
117
+ <div v-bind="api.getControlProps()" :class="PARTS.control">
118
+ <input
119
+ v-bind="input"
120
+ :aria-describedby="invalid ? errorId : description ? descriptionId : undefined"
121
+ :class="PARTS.input"
122
+ />
123
+ <Icon name="chevrons-up-down" size="sm" :class="PARTS.icon" />
124
+ </div>
125
+ <div :class="PARTS.footer">
126
+ <span v-if="!invalid && description" :id="descriptionId" :class="PARTS.description">
127
+ {{ description }}
128
+ </span>
129
+ <span :id="errorId" :class="PARTS.error" aria-live="polite">{{ error }}</span>
130
+ </div>
131
+ <!-- What a form submits: the option's value, where the field holds its label. -->
132
+ <input v-if="name !== undefined" type="hidden" :name="name" :value="value ?? ''" />
133
+ <Portal>
134
+ <div v-bind="api.getPositionerProps()" :class="PARTS.positioner">
135
+ <!-- Zag hides it while closed. It goes at once, with no animation out: it comes and goes
136
+ as the person types. -->
137
+ <div v-bind="api.getContentProps()" :class="PARTS.content">
138
+ <div v-if="shown.length === 0" v-bind="api.getEmptyProps()" :class="PARTS.empty">
139
+ {{ emptyLabel ?? labels.noMatches }}
140
+ </div>
141
+ <div v-else v-bind="api.getListProps()" :class="PARTS.list">
142
+ <div
143
+ v-for="(option, index) in shown"
144
+ :key="option.value"
145
+ v-bind="api.getItemProps({ item: option })"
146
+ :aria-labelledby="selectOptionIds(id, index).label"
147
+ :aria-describedby="
148
+ option.description ? selectOptionIds(id, index).description : undefined
149
+ "
150
+ :class="PARTS.item"
151
+ >
152
+ <span :class="PARTS.itemWords">
153
+ <span
154
+ v-bind="api.getItemTextProps({ item: option })"
155
+ :id="selectOptionIds(id, index).label"
156
+ :class="PARTS.itemLabel"
157
+ >
158
+ {{ option.label }}
159
+ </span>
160
+ <span
161
+ v-if="option.description"
162
+ :id="selectOptionIds(id, index).description"
163
+ :class="PARTS.itemDescription"
164
+ >
165
+ {{ option.description }}
166
+ </span>
167
+ </span>
168
+ <Icon v-if="api.getItemState({ item: option }).selected" name="check" size="sm" />
169
+ </div>
170
+ </div>
171
+ </div>
172
+ </div>
173
+ </Portal>
174
+ </div>
175
+ </template>
@@ -0,0 +1,45 @@
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 {
7
+ type CountBadgeBaseProps,
8
+ countBadgeAnchorClass,
9
+ countBadgeClass,
10
+ countBadgeText,
11
+ } from "./count-badge.ts";
12
+ // A count of something waiting: unread messages, items in a cart. On its own it is laid out
13
+ // inline; around a child it sits on the child's top end corner.
14
+ import { classes, rootPart } from "./parts.ts";
15
+
16
+ export type CountBadgeProps = CountBadgeBaseProps;
17
+
18
+ const { count, max, label } = defineProps<CountBadgeProps>();
19
+ const slots = defineSlots<{
20
+ /** What the count belongs to: an icon, an avatar, a button. The badge sits on its corner. */
21
+ default?(): unknown;
22
+ }>();
23
+ </script>
24
+
25
+ <template>
26
+ <span v-if="slots.default" :class="classes(rootPart('CountBadge'), countBadgeAnchorClass)">
27
+ <slot />
28
+ <span
29
+ v-if="count > 0"
30
+ :role="label ? 'img' : undefined"
31
+ :aria-label="label || undefined"
32
+ :class="countBadgeClass(true)"
33
+ >
34
+ {{ countBadgeText(count, max) }}
35
+ </span>
36
+ </span>
37
+ <span
38
+ v-else-if="count > 0"
39
+ :role="label ? 'img' : undefined"
40
+ :aria-label="label || undefined"
41
+ :class="classes(rootPart('CountBadge'), countBadgeClass(false))"
42
+ >
43
+ {{ countBadgeText(count, max) }}
44
+ </span>
45
+ </template>
@@ -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>