@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,109 @@
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 { useDefaults } from "@xds/vue/base";
7
+ import { computed, useId } from "vue";
8
+ import {
9
+ MEDIA_CARD_PARTS,
10
+ type MediaCardBaseProps,
11
+ mediaCardContentClass,
12
+ mediaCardIds,
13
+ mediaCardThumbnailClass,
14
+ } from "./media-card.ts";
15
+ // A thumbnail with its title and details: a video in a feed, an article in a list.
16
+ //
17
+ // With `onPress` the whole card is one button with no surface at rest: under a pointer and
18
+ // while pressed it takes the card's fills, and it has a focus ring. The button is named by the
19
+ // title followed by the details. `action` is a separate control beside it, so pressing it does
20
+ // not press the card.
21
+ import { classes, rootPart } from "./parts.ts";
22
+ import Thumbnail from "./Thumbnail.vue";
23
+
24
+ export type MediaCardProps = MediaCardBaseProps & {
25
+ /**
26
+ * Makes the whole card one button. A prop rather than an event, since whether there is one
27
+ * decides what is drawn.
28
+ */
29
+ onPress?: () => void;
30
+ };
31
+
32
+ const {
33
+ title,
34
+ meta,
35
+ layout,
36
+ src,
37
+ alt = "",
38
+ // The card's own ratio, not one the app gives its other thumbnails.
39
+ ratio = "16:9",
40
+ badge,
41
+ progress,
42
+ onPress,
43
+ } = defineProps<MediaCardProps>();
44
+ const slots = defineSlots<{
45
+ /** Before the text in the vertical layout, such as an Avatar. */
46
+ leading?(): unknown;
47
+ /** At the end of the text: an IconButton or a Menu. It stays a control of its own. */
48
+ action?(): unknown;
49
+ }>();
50
+
51
+ const id = useId();
52
+ const ids = computed(() => mediaCardIds(id, meta));
53
+ const options = useDefaults("MediaCard", () => ({ layout }), { layout: "vertical" });
54
+ const horizontal = computed(() => options.value.layout === "horizontal");
55
+ const pressable = computed(() => onPress !== undefined);
56
+ // On a pressable card the button says all of this, so the parts are hidden from assistive
57
+ // technology and only the action is left beside it.
58
+ const hidden = computed(() => (pressable.value ? "true" : undefined));
59
+ // A group, not a fieldset, when it is not pressable: a fieldset groups form controls, and sizes
60
+ // itself to its content, which would undo the ellipses.
61
+ const root = computed(() =>
62
+ pressable.value
63
+ ? { class: classes(rootPart("MediaCard"), MEDIA_CARD_PARTS.pressable) }
64
+ : {
65
+ role: "group",
66
+ "aria-labelledby": ids.value.names,
67
+ class: classes(rootPart("MediaCard"), MEDIA_CARD_PARTS.group),
68
+ },
69
+ );
70
+ </script>
71
+
72
+ <template>
73
+ <div v-bind="root">
74
+ <button
75
+ v-if="pressable"
76
+ type="button"
77
+ :aria-labelledby="ids.names"
78
+ :class="MEDIA_CARD_PARTS.button"
79
+ @click="onPress?.()"
80
+ />
81
+ <div :class="mediaCardContentClass({ horizontal, pressable })">
82
+ <span :aria-hidden="hidden" :class="mediaCardThumbnailClass(horizontal)">
83
+ <Thumbnail :src="src" :alt="alt" :ratio="ratio" :badge="badge" :progress="progress" />
84
+ </span>
85
+ <div :class="MEDIA_CARD_PARTS.body">
86
+ <span
87
+ v-if="!horizontal && slots.leading"
88
+ :aria-hidden="hidden"
89
+ :class="MEDIA_CARD_PARTS.leading"
90
+ >
91
+ <slot name="leading" />
92
+ </span>
93
+ <span :aria-hidden="hidden" :class="MEDIA_CARD_PARTS.text">
94
+ <span :id="ids.title" :class="MEDIA_CARD_PARTS.title">{{ title }}</span>
95
+ <!-- Two details may read the same, so they are told apart by their position. -->
96
+ <span
97
+ v-for="(line, index) in meta"
98
+ :id="ids.details[index]"
99
+ :key="index"
100
+ :class="MEDIA_CARD_PARTS.meta"
101
+ >
102
+ {{ line }}
103
+ </span>
104
+ </span>
105
+ <div v-if="slots.action" :class="MEDIA_CARD_PARTS.action"><slot name="action" /></div>
106
+ </div>
107
+ </div>
108
+ </div>
109
+ </template>
@@ -0,0 +1,181 @@
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 list of actions that opens from a control. Choosing an item calls its `onSelect` and
7
+ // closes the menu; a press outside or Escape closes it too, and focus goes back to the
8
+ // trigger.
9
+ //
10
+ // The trigger reports that it opens a menu and whether the menu is open. The arrow keys move
11
+ // the highlight and Enter chooses.
12
+ import {
13
+ keepListKeys,
14
+ leaveEscapeToFields,
15
+ Portal,
16
+ readCssPx,
17
+ space,
18
+ type TriggerProps,
19
+ TriggerScope,
20
+ underlayLayerStyle,
21
+ useModalPopover,
22
+ usePresence,
23
+ } from "@xds/vue/base";
24
+ import * as menu from "@zag-js/menu";
25
+ import { mergeProps, normalizeProps, useMachine } from "@zag-js/vue";
26
+ import { computed, useId, useTemplateRef } from "vue";
27
+ import Icon from "./Icon.vue";
28
+ import {
29
+ firstMenuValue,
30
+ layoutRect,
31
+ type MenuBaseProps,
32
+ menuItemClass,
33
+ opensOnPress,
34
+ } from "./menu.ts";
35
+
36
+ export type { MenuItem } from "./menu.ts";
37
+
38
+ export type MenuProps = MenuBaseProps;
39
+
40
+ // What the app puts on the root (its class, style, id and `data-*` attributes) goes on the menu
41
+ // itself: the root is the trigger and a Teleport, with no element of the menu's own.
42
+ defineOptions({ inheritAttrs: false });
43
+ // The app's id is the surface's, which Zag names too: the machine is given it, so that what
44
+ // points at the surface points at that id.
45
+ const { label, items, align = "start", id: appId } = defineProps<MenuProps & { id?: string }>();
46
+ defineSlots<{
47
+ /** The control that opens the menu: a Button or an IconButton. */
48
+ trigger(): unknown;
49
+ }>();
50
+
51
+ const id = useId();
52
+ const service = useMachine(
53
+ menu.machine,
54
+ computed((): menu.Props => ({
55
+ id,
56
+ ids: { content: appId },
57
+ "aria-label": label,
58
+ positioning: {
59
+ placement: `bottom-${align}`,
60
+ gutter: readCssPx(null, "--xds-space-1", space[1]),
61
+ getAnchorRect: (anchor) => (anchor instanceof HTMLElement ? layoutRect(anchor) : null),
62
+ },
63
+ onSelect: (details) => {
64
+ // The values are positions, because two items may have the same label.
65
+ const item = items[Number(details.value)];
66
+ if (item && item !== "separator") item.onSelect();
67
+ },
68
+ onEscapeKeyDown: leaveEscapeToFields,
69
+ // The arrow keys go round from the last item to the first, as in a native menu.
70
+ loopFocus: true,
71
+ })),
72
+ );
73
+ const api = computed(() => menu.connect(service, normalizeProps));
74
+
75
+ // Whether the last press on the trigger opened the menu, which its click must then not do.
76
+ let pressOpened = false;
77
+ const trigger = computed(() => {
78
+ // Zag's handler for a press is left out: it keeps the press from focusing the trigger, so
79
+ // the focus would reach the menu, and come back to the trigger as the menu closes, only
80
+ // from a script, which the browser marks with the keyboard ring.
81
+ const { onPointerdown: _onPointerdown, ...rest } = api.value.getTriggerProps() as TriggerProps;
82
+ return mergeProps(rest, {
83
+ // Added to the control's own class; the trigger looks pressed while its menu is open.
84
+ class: "{{prefix}}-menu__trigger",
85
+ // A mouse opens the menu as its button goes down; touch and pen open it on the click, as
86
+ // Zag does.
87
+ onPointerdown: (event: PointerEvent) => {
88
+ pressOpened = opensOnPress(event) && !api.value.open;
89
+ if (pressOpened) api.value.setOpen(true);
90
+ },
91
+ onClick: (event: MouseEvent) => {
92
+ // A click with no pointer behind it comes from a screen reader or a script.
93
+ const pointer = event.detail !== 0;
94
+ // The press opened the menu already. This handler runs before Zag's, which skips a
95
+ // handled click. Not told by the click's pointer type: a browser may send the click as a
96
+ // plain mouse event.
97
+ if (pressOpened && pointer) {
98
+ pressOpened = false;
99
+ event.preventDefault();
100
+ return;
101
+ }
102
+ if (pointer) return;
103
+ // After the machine has opened the menu.
104
+ requestAnimationFrame(() => {
105
+ if (!api.value.open) return;
106
+ const first = firstMenuValue(items);
107
+ if (first !== undefined) api.value.setHighlightedValue(first);
108
+ });
109
+ },
110
+ }) as TriggerProps;
111
+ });
112
+
113
+ const positioner = useTemplateRef<HTMLDivElement>("positioner");
114
+ const surface = useTemplateRef<HTMLDivElement>("surface");
115
+ useModalPopover(
116
+ () => api.value.open,
117
+ () => positioner.value,
118
+ );
119
+ const present = usePresence(
120
+ () => api.value.open,
121
+ () => [surface.value],
122
+ );
123
+ const content = computed(() =>
124
+ mergeProps(api.value.getContentProps(), {
125
+ // This handler runs before Zag's.
126
+ onKeydown: (event: KeyboardEvent) =>
127
+ keepListKeys(event, surface.value, ".{{prefix}}-menu__item:not([data-disabled])", (value) =>
128
+ api.value.setHighlightedValue(value),
129
+ ),
130
+ }),
131
+ );
132
+ </script>
133
+
134
+ <template>
135
+ <TriggerScope :trigger="trigger"><slot name="trigger" /></TriggerScope>
136
+ <Portal>
137
+ <!-- Nothing inside opens an overlay from a control outside it. -->
138
+ <TriggerScope :trigger="null">
139
+ <!-- Takes a press outside, which then only closes the menu. The focus stays in the menu
140
+ until the menu hands it back to the trigger. -->
141
+ <div
142
+ v-if="api.open"
143
+ class="{{prefix}}-menu__underlay"
144
+ :style="underlayLayerStyle(api.getPositionerProps().style)"
145
+ @mousedown.prevent
146
+ />
147
+ <div ref="positioner" v-bind="api.getPositionerProps()" class="{{prefix}}-menu__positioner">
148
+ <!-- Shown until its exit animation ends; Zag would hide it as it closes. -->
149
+ <div
150
+ v-bind="mergeProps(content, $attrs)"
151
+ ref="surface"
152
+ :hidden="!present"
153
+ class="{{prefix}}-menu"
154
+ >
155
+ <template v-for="(item, index) in items" :key="index">
156
+ <div
157
+ v-if="item === 'separator'"
158
+ v-bind="api.getSeparatorProps()"
159
+ class="{{prefix}}-menu__separator"
160
+ />
161
+ <div
162
+ v-else
163
+ v-bind="api.getItemProps({ value: String(index), disabled: item.disabled })"
164
+ :class="menuItemClass(item.danger)"
165
+ >
166
+ <Icon
167
+ v-if="item.icon"
168
+ :name="item.icon"
169
+ size="sm"
170
+ class="{{prefix}}-menu__item-icon"
171
+ />
172
+ <span class="flex-1">{{ item.label }}</span>
173
+ <!-- Named, so a screen reader hears the state that the check shows. -->
174
+ <Icon v-if="item.selected" name="check" size="sm" label="Selected" />
175
+ </div>
176
+ </template>
177
+ </div>
178
+ </div>
179
+ </TriggerScope>
180
+ </Portal>
181
+ </template>
@@ -0,0 +1,88 @@
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 { useControllable, useLabels } from "@xds/vue/base";
7
+ import { computed } from "vue";
8
+ import Icon from "./Icon.vue";
9
+ // Moves through a list split into pages: a step back, the first and the last pages, the page
10
+ // shown with an ellipsis for those left out, and a step on. A navigation landmark; the page
11
+ // shown is marked as the current page. Without `value` it keeps its own, from `defaultValue`.
12
+ import {
13
+ clampPage,
14
+ PAGINATION_PARTS,
15
+ PAGINATION_STEPS,
16
+ type PaginationBaseProps,
17
+ paginationEntries,
18
+ } from "./pagination.ts";
19
+ import { rootPart } from "./parts.ts";
20
+
21
+ export type PaginationProps = PaginationBaseProps;
22
+
23
+ // `v-model:value`, written out rather than with defineModel: see useControllable.
24
+ const {
25
+ value: given,
26
+ defaultValue,
27
+ count,
28
+ label,
29
+ previousLabel,
30
+ nextLabel,
31
+ } = defineProps<PaginationProps>();
32
+ const emit = defineEmits<{ "update:value": [value: number] }>();
33
+ const { value, set } = useControllable(
34
+ "value",
35
+ () => given,
36
+ () => defaultValue ?? 1,
37
+ (next) => emit("update:value", next),
38
+ );
39
+ const labels = useLabels();
40
+ const page = computed(() => clampPage(value.value ?? 1, count));
41
+ const last = computed(() => Math.max(1, Math.floor(count)));
42
+ const entries = computed(() => paginationEntries(page.value, count));
43
+ const go = (next: number) => {
44
+ if (next !== page.value && next >= 1 && next <= last.value) set(next);
45
+ };
46
+ </script>
47
+
48
+ <template>
49
+ <nav :class="rootPart('Pagination')" :aria-label="label ?? labels.pagination">
50
+ <ul :class="PAGINATION_PARTS.list">
51
+ <li>
52
+ <button
53
+ type="button"
54
+ :class="PAGINATION_PARTS.step"
55
+ :aria-label="previousLabel ?? labels.previousPage"
56
+ :aria-disabled="page <= 1 ? true : undefined"
57
+ @click="go(page - 1)"
58
+ >
59
+ <Icon :name="PAGINATION_STEPS.previous" :size="PAGINATION_STEPS.size" />
60
+ </button>
61
+ </li>
62
+ <!-- A gap is known by where it is; a page by its number. -->
63
+ <li v-for="(entry, index) in entries" :key="entry === 'gap' ? `gap-${index}` : entry">
64
+ <span v-if="entry === 'gap'" :class="PAGINATION_PARTS.gap" aria-hidden="true">…</span>
65
+ <button
66
+ v-else
67
+ type="button"
68
+ :class="PAGINATION_PARTS.page"
69
+ :aria-current="entry === page ? 'page' : undefined"
70
+ @click="go(entry)"
71
+ >
72
+ {{ entry }}
73
+ </button>
74
+ </li>
75
+ <li>
76
+ <button
77
+ type="button"
78
+ :class="PAGINATION_PARTS.step"
79
+ :aria-label="nextLabel ?? labels.nextPage"
80
+ :aria-disabled="page >= last ? true : undefined"
81
+ @click="go(page + 1)"
82
+ >
83
+ <Icon :name="PAGINATION_STEPS.next" :size="PAGINATION_STEPS.size" />
84
+ </button>
85
+ </li>
86
+ </ul>
87
+ </nav>
88
+ </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
+ import { computed } from "vue";
7
+ import Icon from "./Icon.vue";
8
+ // A ListRow that says what kind of current item its selected state is. A Sidebar's rows are the
9
+ // places of an app, so its selected row is the current page. Only for this package's own
10
+ // components: the index does not export it.
11
+ import {
12
+ LIST_ROW_PARTS,
13
+ type ListRowBaseProps,
14
+ listRowClass,
15
+ listRowDescriptionClass,
16
+ listRowTitleClass,
17
+ } from "./list-row.ts";
18
+
19
+ const {
20
+ title,
21
+ description,
22
+ chevron = false,
23
+ selected = false,
24
+ compact = false,
25
+ disabled = false,
26
+ onPress,
27
+ current,
28
+ } = defineProps<ListRowBaseProps & { onPress?: () => void; current: "true" | "page" }>();
29
+ defineSlots<{ leading?(): unknown; trailing?(): unknown }>();
30
+
31
+ const pressable = computed(() => onPress !== undefined);
32
+ const row = computed(() =>
33
+ pressable.value
34
+ ? { type: "button", disabled, onClick: () => onPress?.() }
35
+ : ({} as Record<string, never>),
36
+ );
37
+ </script>
38
+
39
+ <template>
40
+ <component
41
+ :is="pressable ? 'button' : 'div'"
42
+ v-bind="row"
43
+ :aria-current="selected ? current : undefined"
44
+ :class="listRowClass({ compact, selected, pressable })"
45
+ >
46
+ <slot name="leading" />
47
+ <span :class="LIST_ROW_PARTS.text">
48
+ <span :class="listRowTitleClass({ compact, selected, disabled })">{{ title }}</span>
49
+ <span v-if="description" :class="listRowDescriptionClass(compact)">{{ description }}</span>
50
+ </span>
51
+ <slot name="trailing" />
52
+ <Icon v-if="chevron" name="chevron-right" size="sm" :class="LIST_ROW_PARTS.chevron" />
53
+ </component>
54
+ </template>
@@ -0,0 +1,119 @@
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 surface that opens beside the control that opens it, for details or a short task that do
7
+ // not need the whole screen: a press outside, Escape or its close button closes it, and the
8
+ // focus goes back to the trigger. It is a dialog named by its title, and not modal: the page
9
+ // stays as it is behind it. Without `open` it keeps its own, from `defaultOpen`.
10
+ import {
11
+ leaveEscapeToFields,
12
+ Portal,
13
+ readCssPx,
14
+ space,
15
+ type TriggerProps,
16
+ TriggerScope,
17
+ useControllable,
18
+ useLabels,
19
+ usePresence,
20
+ } from "@xds/vue/base";
21
+ import * as popover from "@zag-js/popover";
22
+ import { mergeProps, normalizeProps, useMachine } from "@zag-js/vue";
23
+ import { computed, useId, useTemplateRef } from "vue";
24
+ import IconButton from "./IconButton.vue";
25
+ import { POPOVER_PARTS, type PopoverBaseProps } from "./popover.ts";
26
+
27
+ export type PopoverProps = PopoverBaseProps;
28
+
29
+ // What the app puts on the root (its class, style, id and `data-*` attributes) goes on the
30
+ // surface: the root is the trigger and a Teleport, with no element of the popover's own.
31
+ defineOptions({ inheritAttrs: false });
32
+ // The app's id is the surface's, which Zag names too: the machine is given it, so that the
33
+ // trigger points at that id.
34
+ const {
35
+ title,
36
+ placement = "bottom",
37
+ closeLabel,
38
+ open: given,
39
+ defaultOpen = false,
40
+ id: appId,
41
+ } = defineProps<PopoverProps & { id?: string }>();
42
+ // `v-model:open`, written out rather than with defineModel: see useControllable. `openChange`
43
+ // is the same change for an app that listens with `@open-change`, as the other libraries'
44
+ // `onOpenChange`.
45
+ const emit = defineEmits<{ "update:open": [open: boolean]; openChange: [open: boolean] }>();
46
+ defineSlots<{
47
+ /** The control that opens it: a Button or an IconButton. */
48
+ trigger(): unknown;
49
+ /** What it holds: a few lines of text, a short form, actions. */
50
+ default?(): unknown;
51
+ }>();
52
+
53
+ const labels = useLabels();
54
+ const { value: open, set } = useControllable<boolean | undefined>(
55
+ "open",
56
+ () => given,
57
+ () => defaultOpen,
58
+ (next) => {
59
+ emit("update:open", next ?? false);
60
+ emit("openChange", next ?? false);
61
+ },
62
+ );
63
+ const content = useTemplateRef<HTMLElement>("content");
64
+ const id = useId();
65
+ const service = useMachine(
66
+ popover.machine,
67
+ computed(() => ({
68
+ id,
69
+ ids: { content: appId },
70
+ open: open.value ?? false,
71
+ onOpenChange: (details: popover.OpenChangeDetails) => set(details.open),
72
+ positioning: { placement, gutter: readCssPx(null, "--xds-space-1", space[1]) },
73
+ onEscapeKeyDown: leaveEscapeToFields,
74
+ // The surface itself rather than its first control: a screen reader then reads the title
75
+ // first, and the close button is the next stop.
76
+ initialFocusEl: () => content.value,
77
+ })),
78
+ );
79
+ const api = computed(() => popover.connect(service, normalizeProps));
80
+ // Added to the control's own class; the trigger looks pressed while it is open.
81
+ const trigger = computed(
82
+ () => mergeProps(api.value.getTriggerProps(), { class: POPOVER_PARTS.trigger }) as TriggerProps,
83
+ );
84
+ const present = usePresence(
85
+ () => api.value.open,
86
+ () => [content.value],
87
+ );
88
+ </script>
89
+
90
+ <template>
91
+ <TriggerScope :trigger="trigger"><slot name="trigger" /></TriggerScope>
92
+ <Portal v-if="present">
93
+ <!-- Nothing inside opens an overlay from a control outside it. -->
94
+ <TriggerScope :trigger="null">
95
+ <div v-bind="api.getPositionerProps()" :class="POPOVER_PARTS.positioner">
96
+ <!-- Shown until its exit animation ends; Zag would hide it as it closes. -->
97
+ <section
98
+ v-bind="mergeProps(api.getContentProps(), $attrs)"
99
+ ref="content"
100
+ :hidden="false"
101
+ class="{{prefix}}-popover"
102
+ >
103
+ <div :class="POPOVER_PARTS.header">
104
+ <h2 v-bind="api.getTitleProps()" :class="POPOVER_PARTS.title">{{ title }}</h2>
105
+ <IconButton
106
+ icon="x"
107
+ :label="closeLabel ?? labels.close"
108
+ variant="ghost"
109
+ size="sm"
110
+ :class="POPOVER_PARTS.close"
111
+ @press="api.setOpen(false)"
112
+ />
113
+ </div>
114
+ <div v-if="$slots.default" :class="POPOVER_PARTS.body"><slot /></div>
115
+ </section>
116
+ </div>
117
+ </TriggerScope>
118
+ </Portal>
119
+ </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
+ import { computed } from "vue";
7
+ // How far along something is, from 0 to 1. For work of unknown length use a Spinner.
8
+ // `label` says what is progressing; a screen reader reads it with the percentage.
9
+ import { classes, rootPart } from "./parts.ts";
10
+ import {
11
+ type ProgressBarBaseProps,
12
+ progressBarClass,
13
+ progressBarFillClass,
14
+ progressPercent,
15
+ } from "./progress-bar.ts";
16
+
17
+ export type ProgressBarProps = ProgressBarBaseProps;
18
+
19
+ const { value, label } = defineProps<ProgressBarProps>();
20
+ const percent = computed(() => progressPercent(value));
21
+ </script>
22
+
23
+ <template>
24
+ <div
25
+ role="progressbar"
26
+ :aria-label="label"
27
+ :aria-valuemin="0"
28
+ :aria-valuemax="100"
29
+ :aria-valuenow="percent"
30
+ :class="classes(rootPart('ProgressBar'), progressBarClass)"
31
+ >
32
+ <div :class="progressBarFillClass" :style="{ width: `${percent}%` }" />
33
+ </div>
34
+ </template>