@xds/vue 1.0.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (188) hide show
  1. package/dist/Banner.vue_vue_type_script_setup_true_lang.js +4 -2
  2. package/dist/Breadcrumb.js +4 -0
  3. package/dist/Breadcrumb.vue.d.ts +6 -0
  4. package/dist/Breadcrumb.vue_vue_type_script_setup_true_lang.js +47 -0
  5. package/dist/Button.vue.d.ts +9 -1
  6. package/dist/Button.vue_vue_type_script_setup_true_lang.js +18 -5
  7. package/dist/Checkbox.vue.d.ts +13 -10
  8. package/dist/Checkbox.vue_vue_type_script_setup_true_lang.js +42 -22
  9. package/dist/Combobox.js +4 -0
  10. package/dist/Combobox.vue.d.ts +22 -0
  11. package/dist/Combobox.vue_vue_type_script_setup_true_lang.js +140 -0
  12. package/dist/DatePicker.vue_vue_type_script_setup_true_lang.js +4 -1
  13. package/dist/DateRangePicker.vue_vue_type_script_setup_true_lang.js +5 -2
  14. package/dist/Dialog.vue.d.ts +5 -2
  15. package/dist/Dialog.vue_vue_type_script_setup_true_lang.js +6 -5
  16. package/dist/IconButton.vue.d.ts +9 -1
  17. package/dist/IconButton.vue_vue_type_script_setup_true_lang.js +18 -5
  18. package/dist/Labels.vue.d.ts +17 -0
  19. package/dist/Labels.vue_vue_type_script_setup_true_lang.js +14 -0
  20. package/dist/Labels2.js +4 -0
  21. package/dist/Link.js +4 -0
  22. package/dist/Link.vue.d.ts +27 -0
  23. package/dist/Link.vue_vue_type_script_setup_true_lang.js +62 -0
  24. package/dist/Menu.vue.d.ts +4 -1
  25. package/dist/Menu.vue_vue_type_script_setup_true_lang.js +5 -4
  26. package/dist/Pagination.js +4 -0
  27. package/dist/Pagination.vue.d.ts +9 -0
  28. package/dist/Pagination.vue_vue_type_script_setup_true_lang.js +74 -0
  29. package/dist/Popover.js +4 -0
  30. package/dist/Popover.vue.d.ts +26 -0
  31. package/dist/Popover.vue_vue_type_script_setup_true_lang.js +81 -0
  32. package/dist/RadioGroup.vue_vue_type_script_setup_true_lang.js +13 -7
  33. package/dist/SearchField.vue.d.ts +11 -8
  34. package/dist/SearchField.vue_vue_type_script_setup_true_lang.js +40 -22
  35. package/dist/SegmentedControl.vue.d.ts +3 -7
  36. package/dist/SegmentedControl.vue_vue_type_script_setup_true_lang.js +13 -14
  37. package/dist/Select.vue.d.ts +3 -1
  38. package/dist/Select.vue_vue_type_script_setup_true_lang.js +47 -18
  39. package/dist/Slider.vue.d.ts +3 -8
  40. package/dist/Slider.vue_vue_type_script_setup_true_lang.js +11 -10
  41. package/dist/Switch.vue.d.ts +13 -10
  42. package/dist/Switch.vue_vue_type_script_setup_true_lang.js +33 -21
  43. package/dist/Table.js +4 -0
  44. package/dist/Table.vue.d.ts +10 -0
  45. package/dist/Table.vue_vue_type_script_setup_true_lang.js +61 -0
  46. package/dist/Tabs.vue.d.ts +3 -5
  47. package/dist/Tabs.vue_vue_type_script_setup_true_lang.js +10 -9
  48. package/dist/TextField.vue.d.ts +11 -8
  49. package/dist/TextField.vue_vue_type_script_setup_true_lang.js +26 -13
  50. package/dist/TimePicker.js +4 -0
  51. package/dist/TimePicker.vue.d.ts +10 -0
  52. package/dist/TimePicker.vue_vue_type_script_setup_true_lang.js +168 -0
  53. package/dist/Toast.vue_vue_type_script_setup_true_lang.js +5 -11
  54. package/dist/ToastQueue.js +4 -0
  55. package/dist/ToastQueue.vue.d.ts +9 -0
  56. package/dist/ToastQueue.vue_vue_type_script_setup_true_lang.js +42 -0
  57. package/dist/TooltipOverlay.vue.d.ts +1 -0
  58. package/dist/TooltipOverlay.vue_vue_type_script_setup_true_lang.js +6 -5
  59. package/dist/base.d.ts +13 -0
  60. package/dist/base.js +14 -0
  61. package/dist/controlled.d.ts +46 -0
  62. package/dist/controlled.js +64 -2
  63. package/dist/index.d.ts +14 -3
  64. package/dist/index.js +11 -1
  65. package/dist/labels.d.ts +9 -0
  66. package/dist/labels.js +17 -0
  67. package/dist/preview.d.ts +20 -3
  68. package/dist/preview.js +37 -7
  69. package/dist/trigger.d.ts +7 -0
  70. package/dist/trigger.js +13 -1
  71. package/eject/files/Accordion.vue +89 -0
  72. package/eject/files/AccordionPanel.vue +47 -0
  73. package/eject/files/Avatar.vue +41 -0
  74. package/eject/files/AvatarStack.vue +46 -0
  75. package/eject/files/Badge.vue +29 -0
  76. package/eject/files/Banner.vue +65 -0
  77. package/eject/files/Breadcrumb.vue +43 -0
  78. package/eject/files/Button.vue +93 -0
  79. package/eject/files/Card.vue +85 -0
  80. package/eject/files/Checkbox.vue +104 -0
  81. package/eject/files/Chip.vue +32 -0
  82. package/eject/files/ChipBar.vue +25 -0
  83. package/eject/files/Combobox.vue +175 -0
  84. package/eject/files/CountBadge.vue +45 -0
  85. package/eject/files/DatePicker.vue +223 -0
  86. package/eject/files/DateRangePicker.vue +317 -0
  87. package/eject/files/Dialog.vue +105 -0
  88. package/eject/files/Divider.vue +15 -0
  89. package/eject/files/EmptyState.vue +28 -0
  90. package/eject/files/Icon.vue +34 -0
  91. package/eject/files/IconButton.vue +71 -0
  92. package/eject/files/Link.vue +48 -0
  93. package/eject/files/ListRow.vue +33 -0
  94. package/eject/files/MediaCard.vue +109 -0
  95. package/eject/files/Menu.vue +181 -0
  96. package/eject/files/Pagination.vue +88 -0
  97. package/eject/files/PlaceRow.vue +54 -0
  98. package/eject/files/Popover.vue +119 -0
  99. package/eject/files/ProgressBar.vue +34 -0
  100. package/eject/files/RadioGroup.vue +126 -0
  101. package/eject/files/SearchField.vue +129 -0
  102. package/eject/files/SectionHeader.vue +37 -0
  103. package/eject/files/SegmentedControl.vue +81 -0
  104. package/eject/files/Select.vue +269 -0
  105. package/eject/files/Sidebar.vue +101 -0
  106. package/eject/files/SidebarRailButton.vue +31 -0
  107. package/eject/files/Skeleton.vue +27 -0
  108. package/eject/files/Slider.vue +126 -0
  109. package/eject/files/Spinner.vue +36 -0
  110. package/eject/files/Switch.vue +88 -0
  111. package/eject/files/Table.vue +77 -0
  112. package/eject/files/Tabs.vue +72 -0
  113. package/eject/files/Text.vue +22 -0
  114. package/eject/files/TextField.vue +190 -0
  115. package/eject/files/Thumbnail.vue +62 -0
  116. package/eject/files/TimePicker.vue +224 -0
  117. package/eject/files/Toast.vue +83 -0
  118. package/eject/files/ToastQueue.vue +54 -0
  119. package/eject/files/Tooltip.vue +28 -0
  120. package/eject/files/TooltipOverlay.vue +86 -0
  121. package/eject/files/accordion.css +89 -0
  122. package/eject/files/accordion.ts +67 -0
  123. package/eject/files/avatar-stack.ts +57 -0
  124. package/eject/files/avatar.ts +42 -0
  125. package/eject/files/badge.ts +30 -0
  126. package/eject/files/banner.ts +71 -0
  127. package/eject/files/base.css +38 -0
  128. package/eject/files/breadcrumb.css +51 -0
  129. package/eject/files/breadcrumb.ts +42 -0
  130. package/eject/files/button.css +241 -0
  131. package/eject/files/button.ts +106 -0
  132. package/eject/files/card.ts +58 -0
  133. package/eject/files/checkbox.ts +52 -0
  134. package/eject/files/chip-bar.ts +16 -0
  135. package/eject/files/chip.ts +35 -0
  136. package/eject/files/combobox.css +269 -0
  137. package/eject/files/combobox.ts +85 -0
  138. package/eject/files/count-badge.ts +32 -0
  139. package/eject/files/date-picker.css +375 -0
  140. package/eject/files/date-picker.ts +280 -0
  141. package/eject/files/date-range-picker.ts +338 -0
  142. package/eject/files/dialog.css +139 -0
  143. package/eject/files/dialog.ts +15 -0
  144. package/eject/files/divider.ts +5 -0
  145. package/eject/files/empty-state.ts +22 -0
  146. package/eject/files/icon.ts +36 -0
  147. package/eject/files/link.css +64 -0
  148. package/eject/files/link.ts +63 -0
  149. package/eject/files/list-row.ts +66 -0
  150. package/eject/files/media-card.ts +66 -0
  151. package/eject/files/menu.css +192 -0
  152. package/eject/files/menu.ts +84 -0
  153. package/eject/files/overlay.css +40 -0
  154. package/eject/files/pagination.css +106 -0
  155. package/eject/files/pagination.ts +68 -0
  156. package/eject/files/parts.ts +17 -0
  157. package/eject/files/popover.css +101 -0
  158. package/eject/files/popover.ts +37 -0
  159. package/eject/files/progress-bar.ts +26 -0
  160. package/eject/files/radio-group.css +184 -0
  161. package/eject/files/radio-group.ts +30 -0
  162. package/eject/files/section-header.ts +32 -0
  163. package/eject/files/segmented-control.ts +33 -0
  164. package/eject/files/select.css +347 -0
  165. package/eject/files/select.ts +77 -0
  166. package/eject/files/sidebar.ts +75 -0
  167. package/eject/files/skeleton.ts +51 -0
  168. package/eject/files/slider.css +160 -0
  169. package/eject/files/slider.ts +80 -0
  170. package/eject/files/spinner.ts +22 -0
  171. package/eject/files/switch.ts +45 -0
  172. package/eject/files/table.css +107 -0
  173. package/eject/files/table.ts +84 -0
  174. package/eject/files/tabs.css +120 -0
  175. package/eject/files/tabs.ts +37 -0
  176. package/eject/files/text-field.css +225 -0
  177. package/eject/files/text-field.ts +64 -0
  178. package/eject/files/text.ts +38 -0
  179. package/eject/files/thumbnail.ts +51 -0
  180. package/eject/files/time-picker.ts +113 -0
  181. package/eject/files/toast-queue.ts +64 -0
  182. package/eject/files/toast.ts +31 -0
  183. package/eject/files/tooltip.css +111 -0
  184. package/eject/files/tooltip.ts +21 -0
  185. package/eject/manifest.json +1122 -0
  186. package/package.json +11 -4
  187. package/styles.css +1135 -167
  188. package/tailwind.css +1295 -218
@@ -0,0 +1,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>
@@ -0,0 +1,126 @@
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 { formDefault, keepChecked, useControllable, useFormReset } from "@xds/vue/base";
7
+ import { computed, useId, useTemplateRef } from "vue";
8
+ // One choice among a few, applied later with the form it belongs to. For a choice that takes
9
+ // effect at once among two to four options, a SegmentedControl is the usual pick.
10
+ //
11
+ // The chosen option has a dot and a thicker ring, so the choice does not depend on color. The
12
+ // options are native radio buttons, hidden and drawn beside, in a group named by the legend:
13
+ // the arrow keys move between them, and the error is tied to the group and announced.
14
+ import type { RadioGroupBaseProps } from "./radio-group.ts";
15
+
16
+ export type { RadioOption } from "./radio-group.ts";
17
+
18
+ export type RadioGroupProps<Value extends string = string> = RadioGroupBaseProps<Value>;
19
+
20
+ // `v-model:value`, written out rather than with defineModel: a choice is never undefined, and
21
+ // defineModel would say that it can be. See useControllable too.
22
+ const {
23
+ value: given,
24
+ defaultValue,
25
+ label,
26
+ options,
27
+ disabled = false,
28
+ error,
29
+ name,
30
+ } = defineProps<RadioGroupProps<Value>>();
31
+ const emit = defineEmits<{ "update:value": [value: Value] }>();
32
+
33
+ const id = useId();
34
+ const labelId = `${id}-label`;
35
+ const errorId = `${id}-error`;
36
+ const invalid = computed(() => error !== undefined);
37
+ const group = useTemplateRef("group");
38
+ const { value, set, controlled, reset } = useControllable<Value | undefined>(
39
+ "value",
40
+ () => given,
41
+ () => defaultValue,
42
+ (next) => {
43
+ if (next !== undefined) emit("update:value", next);
44
+ },
45
+ );
46
+ useFormReset(() => group.value, controlled, reset);
47
+
48
+ // The description is inside the pressable row, so the row's text would name the radio
49
+ // together with it. The label alone names it; the description describes it.
50
+ const describedBy = (index: number, description: string | undefined) =>
51
+ [description ? `${id}-${index}-description` : undefined, invalid.value ? errorId : undefined]
52
+ .filter(Boolean)
53
+ .join(" ") || undefined;
54
+
55
+ function choose(option: Value) {
56
+ set(option);
57
+ // The browser moved the dot already; where the owner kept the old value, it goes back, on
58
+ // every radio of the group.
59
+ for (const input of group.value?.querySelectorAll("input") ?? []) {
60
+ keepChecked(input, () => input.value === value.value);
61
+ }
62
+ }
63
+ </script>
64
+
65
+ <template>
66
+ <div
67
+ ref="group"
68
+ role="radiogroup"
69
+ :aria-labelledby="labelId"
70
+ :aria-describedby="invalid ? errorId : undefined"
71
+ :aria-invalid="invalid ? 'true' : undefined"
72
+ :aria-disabled="disabled ? 'true' : undefined"
73
+ aria-orientation="vertical"
74
+ class="{{prefix}}-radio-group"
75
+ >
76
+ <span :id="labelId" class="{{prefix}}-radio-group__label">{{ label }}</span>
77
+ <div class="{{prefix}}-radio-group__options">
78
+ <label
79
+ v-for="(option, index) in options"
80
+ :key="option.value"
81
+ class="{{prefix}}-radio-group__option"
82
+ >
83
+ <!-- aria-invalid is on each radio as well as the group, so it is heard on the radio
84
+ that has focus. Radios group by name, which is what makes the arrow keys move
85
+ between them. -->
86
+ <input
87
+ type="radio"
88
+ class="{{prefix}}-radio-group__input sr-only"
89
+ :name="name ?? id"
90
+ :value="option.value"
91
+ :checked="option.value === value"
92
+ v-bind="formDefault({ defaultChecked: option.value === value })"
93
+ :disabled="disabled"
94
+ :aria-labelledby="`${id}-${index}`"
95
+ :aria-describedby="describedBy(index, option.description)"
96
+ :aria-invalid="invalid ? 'true' : undefined"
97
+ @change="choose(option.value)"
98
+ />
99
+ <span class="{{prefix}}-radio-group__row">
100
+ <span class="{{prefix}}-radio-group__circle-line">
101
+ <span class="{{prefix}}-radio-group__circle"
102
+ ><span class="{{prefix}}-radio-group__dot"
103
+ /></span>
104
+ </span>
105
+ <span class="{{prefix}}-radio-group__words">
106
+ <span :id="`${id}-${index}`" class="{{prefix}}-radio-group__text">{{
107
+ option.label
108
+ }}</span>
109
+ <span
110
+ v-if="option.description"
111
+ :id="`${id}-${index}-description`"
112
+ class="{{prefix}}-radio-group__description"
113
+ >
114
+ {{ option.description }}
115
+ </span>
116
+ </span>
117
+ </span>
118
+ </label>
119
+ </div>
120
+ <!-- The region is there before the error is, so that the error is announced when it
121
+ appears. Empty, it takes no room. -->
122
+ <div aria-live="polite">
123
+ <span v-if="invalid" :id="errorId" class="{{prefix}}-radio-group__error">{{ error }}</span>
124
+ </div>
125
+ </div>
126
+ </template>
@@ -0,0 +1,129 @@
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
+ keepValue,
10
+ useControllable,
11
+ useFormReset,
12
+ useLabels,
13
+ } from "@xds/vue/base";
14
+ import { computed, getCurrentInstance, useTemplateRef } from "vue";
15
+ import Icon from "./Icon.vue";
16
+ // A text field for a query: TextField's box as a pill, with a search icon in front and, while
17
+ // there is a value, a control that clears it. Escape clears too. A read-only field has neither.
18
+ //
19
+ // Use it to filter or search what is on the screen. For a value that is saved with a form,
20
+ // use a TextField, which has a visible label.
21
+ import { classes, rootPart } from "./parts.ts";
22
+ import type { SearchFieldBaseProps } from "./text-field.ts";
23
+
24
+ export type SearchFieldProps = SearchFieldBaseProps;
25
+
26
+ // `v-model:value`, written out rather than with defineModel: see useControllable.
27
+ const {
28
+ value: given,
29
+ defaultValue = "",
30
+ readOnly = false,
31
+ label,
32
+ placeholder,
33
+ disabled = false,
34
+ clearLabel,
35
+ } = defineProps<SearchFieldProps>();
36
+ const emit = defineEmits<{
37
+ "update:value": [value: string];
38
+ /** The query, on Enter or on the search key of a software keyboard. */
39
+ submit: [value: string];
40
+ // On the input, which the root holds.
41
+ focus: [event: FocusEvent];
42
+ blur: [event: FocusEvent];
43
+ }>();
44
+ const labels = useLabels();
45
+ const input = useTemplateRef<HTMLInputElement>("input");
46
+ const { value, set, controlled, reset } = useControllable(
47
+ "value",
48
+ () => given,
49
+ () => defaultValue,
50
+ (next) => emit("update:value", next),
51
+ );
52
+ useFormReset(() => input.value, controlled, reset);
53
+ defineExpose(focusable(() => input.value));
54
+ // Whether there is a query that Escape and the clear control can clear.
55
+ const clearable = computed(() => value.value !== "" && !disabled && !readOnly);
56
+ const instance = getCurrentInstance();
57
+
58
+ function edit(event: Event) {
59
+ const field = event.currentTarget as HTMLInputElement;
60
+ set(field.value);
61
+ if (!(event as InputEvent).isComposing) keepValue(field, () => value.value);
62
+ }
63
+ function settle(event: CompositionEvent) {
64
+ keepValue(event.currentTarget as HTMLInputElement, () => value.value);
65
+ }
66
+ function key(event: KeyboardEvent) {
67
+ // While a composition is open, Enter and Escape belong to the input method.
68
+ if (event.isComposing) return;
69
+ if (event.key === "Enter") {
70
+ if (instance?.vnode.props?.onSubmit) event.preventDefault();
71
+ emit("submit", value.value);
72
+ }
73
+ if (event.key === "Escape" && clearable.value) {
74
+ event.stopPropagation();
75
+ set("");
76
+ }
77
+ }
78
+ function clear() {
79
+ set("");
80
+ // The control is about to disappear, and focus would be lost with it.
81
+ input.value?.focus();
82
+ }
83
+ </script>
84
+
85
+ <template>
86
+ <div :class="classes('{{prefix}}-text-field', rootPart('SearchField'))">
87
+ <div
88
+ class="{{prefix}}-text-field__control {{prefix}}-text-field__control--pill {{prefix}}-text-field__group"
89
+ >
90
+ <span class="{{prefix}}-text-field__slot {{prefix}}-text-field__slot--leading"
91
+ ><Icon name="search" size="sm"
92
+ /></span>
93
+ <!-- Escape clears only while there is something to clear; an empty field lets Escape
94
+ through to whatever it sits in, such as a dialog. -->
95
+ <input
96
+ ref="input"
97
+ type="text"
98
+ role="searchbox"
99
+ class="{{prefix}}-text-field__input"
100
+ :aria-label="label"
101
+ enterkeyhint="search"
102
+ :placeholder="placeholder"
103
+ :value="value"
104
+ v-bind="formDefault({ defaultValue: value })"
105
+ :disabled="disabled"
106
+ :readonly="readOnly"
107
+ :data-uses-escape="clearable ? '' : undefined"
108
+ @input="edit"
109
+ @compositionend="settle"
110
+ @keydown="key"
111
+ @focus="emit('focus', $event)"
112
+ @blur="emit('blur', $event)"
113
+ />
114
+ <span
115
+ v-if="clearable"
116
+ class="{{prefix}}-text-field__slot {{prefix}}-text-field__slot--trailing"
117
+ >
118
+ <button
119
+ type="button"
120
+ :aria-label="clearLabel ?? labels.clear"
121
+ class="-me-1 flex size-xds-target-min cursor-pointer items-center justify-center rounded-xds-full hover:text-xds-field-text focus-visible:outline-(length:--xds-focus-width) focus-visible:outline-xds-border-focus focus-visible:outline-solid"
122
+ @click="clear"
123
+ >
124
+ <Icon name="circle-x" size="sm" />
125
+ </button>
126
+ </span>
127
+ </div>
128
+ </div>
129
+ </template>
@@ -0,0 +1,37 @@
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 Button from "./Button.vue";
7
+ import Icon from "./Icon.vue";
8
+ // The title row of a group of content. The title is a heading at `level`; the action is a quiet
9
+ // button with a chevron at its end edge, which points the other way in a right-to-left layout.
10
+ import { classes, rootPart } from "./parts.ts";
11
+ import { SECTION_HEADER_PARTS, type SectionHeaderBaseProps } from "./section-header.ts";
12
+
13
+ export type SectionHeaderProps = SectionHeaderBaseProps & {
14
+ /** A link-like action at the end, such as "See all". */
15
+ action?: { label: string; onPress: () => void };
16
+ };
17
+
18
+ const { title, description, icon, level = 2, action } = defineProps<SectionHeaderProps>();
19
+ </script>
20
+
21
+ <template>
22
+ <div :class="classes(rootPart('SectionHeader'), SECTION_HEADER_PARTS.root)">
23
+ <div :class="SECTION_HEADER_PARTS.lead">
24
+ <span v-if="icon" :class="SECTION_HEADER_PARTS.icon"><Icon :name="icon" size="md" /></span>
25
+ <div :class="SECTION_HEADER_PARTS.text">
26
+ <component :is="`h${level}`" :class="SECTION_HEADER_PARTS.title">{{ title }}</component>
27
+ <p v-if="description" :class="SECTION_HEADER_PARTS.description">{{ description }}</p>
28
+ </div>
29
+ </div>
30
+ <span v-if="action" :class="SECTION_HEADER_PARTS.action">
31
+ <Button variant="ghost" size="sm" @press="action.onPress()">
32
+ {{ action.label
33
+ }}<Icon name="chevron-right" size="sm" :class="SECTION_HEADER_PARTS.chevron" />
34
+ </Button>
35
+ </span>
36
+ </div>
37
+ </template>
@@ -0,0 +1,81 @@
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">
6
+ import { formDefault, keepChecked, useControllable } from "@xds/vue/base";
7
+ import { useId, useTemplateRef } from "vue";
8
+ // A choice between a few views or modes, all visible at once. The selected segment is outlined
9
+ // as well as filled, so the choice does not depend on telling two greys apart.
10
+ //
11
+ // It is a group of native radio buttons, so the arrow keys move between segments.
12
+ import { classes, rootPart } from "./parts.ts";
13
+ import {
14
+ type SegmentedControlBaseProps,
15
+ segmentedControlClass,
16
+ segmentedControlOptionClass,
17
+ segmentedControlSegmentClass,
18
+ } from "./segmented-control.ts";
19
+
20
+ // `aria-label` is declared as `ariaLabel`: Vue keeps a prop under its camelized name, and a
21
+ // template still writes `aria-label`.
22
+ export type SegmentedControlProps<Value extends string> = Omit<
23
+ SegmentedControlBaseProps<Value>,
24
+ "aria-label"
25
+ > & { ariaLabel: string };
26
+
27
+ // `v-model:value`, written out rather than with defineModel: see useControllable.
28
+ const {
29
+ value: given,
30
+ defaultValue,
31
+ options,
32
+ ariaLabel,
33
+ fullWidth = false,
34
+ } = defineProps<SegmentedControlProps<Value>>();
35
+ const emit = defineEmits<{ "update:value": [value: Value] }>();
36
+ const { value, set } = useControllable(
37
+ "value",
38
+ () => given,
39
+ // Without a default, the first segment: one segment is always chosen.
40
+ () => defaultValue ?? (options[0]?.value as Value),
41
+ (next) => emit("update:value", next),
42
+ );
43
+
44
+ const name = useId();
45
+ const group = useTemplateRef("group");
46
+
47
+ function choose(option: Value) {
48
+ set(option);
49
+ // The browser moved the dot already; where the owner kept the old value, it goes back, on
50
+ // every radio of the group.
51
+ for (const input of group.value?.querySelectorAll("input") ?? []) {
52
+ keepChecked(input, () => input.value === value.value);
53
+ }
54
+ }
55
+ </script>
56
+
57
+ <template>
58
+ <div
59
+ ref="group"
60
+ :aria-label="ariaLabel"
61
+ role="radiogroup"
62
+ :class="classes(rootPart('SegmentedControl'), segmentedControlClass(fullWidth))"
63
+ >
64
+ <label
65
+ v-for="option in options"
66
+ :key="option.value"
67
+ :class="segmentedControlOptionClass(fullWidth)"
68
+ >
69
+ <input
70
+ type="radio"
71
+ :name="name"
72
+ :value="option.value"
73
+ class="peer sr-only"
74
+ :checked="option.value === value"
75
+ v-bind="formDefault({ defaultChecked: option.value === value })"
76
+ @change="choose(option.value)"
77
+ />
78
+ <span :class="segmentedControlSegmentClass">{{ option.label }}</span>
79
+ </label>
80
+ </div>
81
+ </template>