@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.
- package/dist/Banner.vue_vue_type_script_setup_true_lang.js +4 -2
- package/dist/Breadcrumb.js +4 -0
- package/dist/Breadcrumb.vue.d.ts +6 -0
- package/dist/Breadcrumb.vue_vue_type_script_setup_true_lang.js +47 -0
- package/dist/Button.vue.d.ts +9 -1
- package/dist/Button.vue_vue_type_script_setup_true_lang.js +18 -5
- package/dist/Checkbox.vue.d.ts +13 -10
- package/dist/Checkbox.vue_vue_type_script_setup_true_lang.js +42 -22
- package/dist/Combobox.js +4 -0
- package/dist/Combobox.vue.d.ts +22 -0
- package/dist/Combobox.vue_vue_type_script_setup_true_lang.js +140 -0
- package/dist/DatePicker.vue_vue_type_script_setup_true_lang.js +4 -1
- package/dist/DateRangePicker.vue_vue_type_script_setup_true_lang.js +5 -2
- package/dist/Dialog.vue.d.ts +5 -2
- package/dist/Dialog.vue_vue_type_script_setup_true_lang.js +6 -5
- package/dist/IconButton.vue.d.ts +9 -1
- package/dist/IconButton.vue_vue_type_script_setup_true_lang.js +18 -5
- package/dist/Labels.vue.d.ts +17 -0
- package/dist/Labels.vue_vue_type_script_setup_true_lang.js +14 -0
- package/dist/Labels2.js +4 -0
- package/dist/Link.js +4 -0
- package/dist/Link.vue.d.ts +27 -0
- package/dist/Link.vue_vue_type_script_setup_true_lang.js +62 -0
- package/dist/Menu.vue.d.ts +4 -1
- package/dist/Menu.vue_vue_type_script_setup_true_lang.js +5 -4
- package/dist/Pagination.js +4 -0
- package/dist/Pagination.vue.d.ts +9 -0
- package/dist/Pagination.vue_vue_type_script_setup_true_lang.js +74 -0
- package/dist/Popover.js +4 -0
- package/dist/Popover.vue.d.ts +26 -0
- package/dist/Popover.vue_vue_type_script_setup_true_lang.js +81 -0
- package/dist/RadioGroup.vue_vue_type_script_setup_true_lang.js +13 -7
- package/dist/SearchField.vue.d.ts +11 -8
- package/dist/SearchField.vue_vue_type_script_setup_true_lang.js +40 -22
- package/dist/SegmentedControl.vue.d.ts +3 -7
- package/dist/SegmentedControl.vue_vue_type_script_setup_true_lang.js +13 -14
- package/dist/Select.vue.d.ts +3 -1
- package/dist/Select.vue_vue_type_script_setup_true_lang.js +47 -18
- package/dist/Slider.vue.d.ts +3 -8
- package/dist/Slider.vue_vue_type_script_setup_true_lang.js +11 -10
- package/dist/Switch.vue.d.ts +13 -10
- package/dist/Switch.vue_vue_type_script_setup_true_lang.js +33 -21
- package/dist/Table.js +4 -0
- package/dist/Table.vue.d.ts +10 -0
- package/dist/Table.vue_vue_type_script_setup_true_lang.js +61 -0
- package/dist/Tabs.vue.d.ts +3 -5
- package/dist/Tabs.vue_vue_type_script_setup_true_lang.js +10 -9
- package/dist/TextField.vue.d.ts +11 -8
- package/dist/TextField.vue_vue_type_script_setup_true_lang.js +26 -13
- package/dist/TimePicker.js +4 -0
- package/dist/TimePicker.vue.d.ts +10 -0
- package/dist/TimePicker.vue_vue_type_script_setup_true_lang.js +168 -0
- package/dist/Toast.vue_vue_type_script_setup_true_lang.js +5 -11
- package/dist/ToastQueue.js +4 -0
- package/dist/ToastQueue.vue.d.ts +9 -0
- package/dist/ToastQueue.vue_vue_type_script_setup_true_lang.js +42 -0
- package/dist/TooltipOverlay.vue.d.ts +1 -0
- package/dist/TooltipOverlay.vue_vue_type_script_setup_true_lang.js +6 -5
- package/dist/base.d.ts +13 -0
- package/dist/base.js +14 -0
- package/dist/controlled.d.ts +46 -0
- package/dist/controlled.js +64 -2
- package/dist/index.d.ts +14 -3
- package/dist/index.js +11 -1
- package/dist/labels.d.ts +9 -0
- package/dist/labels.js +17 -0
- package/dist/preview.d.ts +20 -3
- package/dist/preview.js +37 -7
- package/dist/trigger.d.ts +7 -0
- package/dist/trigger.js +13 -1
- package/eject/files/Accordion.vue +89 -0
- package/eject/files/AccordionPanel.vue +47 -0
- package/eject/files/Avatar.vue +41 -0
- package/eject/files/AvatarStack.vue +46 -0
- package/eject/files/Badge.vue +29 -0
- package/eject/files/Banner.vue +65 -0
- package/eject/files/Breadcrumb.vue +43 -0
- package/eject/files/Button.vue +93 -0
- package/eject/files/Card.vue +85 -0
- package/eject/files/Checkbox.vue +104 -0
- package/eject/files/Chip.vue +32 -0
- package/eject/files/ChipBar.vue +25 -0
- package/eject/files/Combobox.vue +175 -0
- package/eject/files/CountBadge.vue +45 -0
- package/eject/files/DatePicker.vue +223 -0
- package/eject/files/DateRangePicker.vue +317 -0
- package/eject/files/Dialog.vue +105 -0
- package/eject/files/Divider.vue +15 -0
- package/eject/files/EmptyState.vue +28 -0
- package/eject/files/Icon.vue +34 -0
- package/eject/files/IconButton.vue +71 -0
- package/eject/files/Link.vue +48 -0
- package/eject/files/ListRow.vue +33 -0
- package/eject/files/MediaCard.vue +109 -0
- package/eject/files/Menu.vue +181 -0
- package/eject/files/Pagination.vue +88 -0
- package/eject/files/PlaceRow.vue +54 -0
- package/eject/files/Popover.vue +119 -0
- package/eject/files/ProgressBar.vue +34 -0
- package/eject/files/RadioGroup.vue +126 -0
- package/eject/files/SearchField.vue +129 -0
- package/eject/files/SectionHeader.vue +37 -0
- package/eject/files/SegmentedControl.vue +81 -0
- package/eject/files/Select.vue +269 -0
- package/eject/files/Sidebar.vue +101 -0
- package/eject/files/SidebarRailButton.vue +31 -0
- package/eject/files/Skeleton.vue +27 -0
- package/eject/files/Slider.vue +126 -0
- package/eject/files/Spinner.vue +36 -0
- package/eject/files/Switch.vue +88 -0
- package/eject/files/Table.vue +77 -0
- package/eject/files/Tabs.vue +72 -0
- package/eject/files/Text.vue +22 -0
- package/eject/files/TextField.vue +190 -0
- package/eject/files/Thumbnail.vue +62 -0
- package/eject/files/TimePicker.vue +224 -0
- package/eject/files/Toast.vue +83 -0
- package/eject/files/ToastQueue.vue +54 -0
- package/eject/files/Tooltip.vue +28 -0
- package/eject/files/TooltipOverlay.vue +86 -0
- package/eject/files/accordion.css +89 -0
- package/eject/files/accordion.ts +67 -0
- package/eject/files/avatar-stack.ts +57 -0
- package/eject/files/avatar.ts +42 -0
- package/eject/files/badge.ts +30 -0
- package/eject/files/banner.ts +71 -0
- package/eject/files/base.css +38 -0
- package/eject/files/breadcrumb.css +51 -0
- package/eject/files/breadcrumb.ts +42 -0
- package/eject/files/button.css +241 -0
- package/eject/files/button.ts +106 -0
- package/eject/files/card.ts +58 -0
- package/eject/files/checkbox.ts +52 -0
- package/eject/files/chip-bar.ts +16 -0
- package/eject/files/chip.ts +35 -0
- package/eject/files/combobox.css +269 -0
- package/eject/files/combobox.ts +85 -0
- package/eject/files/count-badge.ts +32 -0
- package/eject/files/date-picker.css +375 -0
- package/eject/files/date-picker.ts +280 -0
- package/eject/files/date-range-picker.ts +338 -0
- package/eject/files/dialog.css +139 -0
- package/eject/files/dialog.ts +15 -0
- package/eject/files/divider.ts +5 -0
- package/eject/files/empty-state.ts +22 -0
- package/eject/files/icon.ts +36 -0
- package/eject/files/link.css +64 -0
- package/eject/files/link.ts +63 -0
- package/eject/files/list-row.ts +66 -0
- package/eject/files/media-card.ts +66 -0
- package/eject/files/menu.css +192 -0
- package/eject/files/menu.ts +84 -0
- package/eject/files/overlay.css +40 -0
- package/eject/files/pagination.css +106 -0
- package/eject/files/pagination.ts +68 -0
- package/eject/files/parts.ts +17 -0
- package/eject/files/popover.css +101 -0
- package/eject/files/popover.ts +37 -0
- package/eject/files/progress-bar.ts +26 -0
- package/eject/files/radio-group.css +184 -0
- package/eject/files/radio-group.ts +30 -0
- package/eject/files/section-header.ts +32 -0
- package/eject/files/segmented-control.ts +33 -0
- package/eject/files/select.css +347 -0
- package/eject/files/select.ts +77 -0
- package/eject/files/sidebar.ts +75 -0
- package/eject/files/skeleton.ts +51 -0
- package/eject/files/slider.css +160 -0
- package/eject/files/slider.ts +80 -0
- package/eject/files/spinner.ts +22 -0
- package/eject/files/switch.ts +45 -0
- package/eject/files/table.css +107 -0
- package/eject/files/table.ts +84 -0
- package/eject/files/tabs.css +120 -0
- package/eject/files/tabs.ts +37 -0
- package/eject/files/text-field.css +225 -0
- package/eject/files/text-field.ts +64 -0
- package/eject/files/text.ts +38 -0
- package/eject/files/thumbnail.ts +51 -0
- package/eject/files/time-picker.ts +113 -0
- package/eject/files/toast-queue.ts +64 -0
- package/eject/files/toast.ts +31 -0
- package/eject/files/tooltip.css +111 -0
- package/eject/files/tooltip.ts +21 -0
- package/eject/manifest.json +1122 -0
- package/package.json +11 -4
- package/styles.css +1135 -167
- package/tailwind.css +1295 -218
|
@@ -0,0 +1,269 @@
|
|
|
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
|
+
// A field for choosing one option from a list too long to show at once. Closed, it looks like a
|
|
7
|
+
// TextField; pressed, it opens the list under itself with a Menu's surface, as wide as the
|
|
8
|
+
// field. Choosing an option sets the value and closes the list; a press outside or Escape
|
|
9
|
+
// closes it too.
|
|
10
|
+
//
|
|
11
|
+
// The field is a button that says it opens a list box and whether the list is open. In the list
|
|
12
|
+
// the arrow keys move, typing jumps to an option, and Enter chooses. The chosen option is
|
|
13
|
+
// selected for assistive technology and marked with a check.
|
|
14
|
+
//
|
|
15
|
+
// With `multiple`, any number of options can be chosen: choosing one adds it or takes it away,
|
|
16
|
+
// the list stays open, and `v-model:values` (`valuesChange`) gets them all. The list box says
|
|
17
|
+
// that several can be chosen.
|
|
18
|
+
import {
|
|
19
|
+
keepListKeys,
|
|
20
|
+
Portal,
|
|
21
|
+
readCssPx,
|
|
22
|
+
space,
|
|
23
|
+
underlayLayerStyle,
|
|
24
|
+
useControllable,
|
|
25
|
+
useModalPopover,
|
|
26
|
+
usePresence,
|
|
27
|
+
} from "@xds/vue/base";
|
|
28
|
+
import * as select from "@zag-js/select";
|
|
29
|
+
import { normalizeProps, useMachine } from "@zag-js/vue";
|
|
30
|
+
import { computed, useId, useTemplateRef } from "vue";
|
|
31
|
+
import Icon from "./Icon.vue";
|
|
32
|
+
import {
|
|
33
|
+
orderedValues,
|
|
34
|
+
type SelectBaseProps,
|
|
35
|
+
type SelectOption,
|
|
36
|
+
selectedLabels,
|
|
37
|
+
selectOptionIds,
|
|
38
|
+
} from "./select.ts";
|
|
39
|
+
|
|
40
|
+
export type { SelectOption } from "./select.ts";
|
|
41
|
+
|
|
42
|
+
export type SelectProps<Value extends string = string> = SelectBaseProps<Value>;
|
|
43
|
+
|
|
44
|
+
type KeyHandler = (event: KeyboardEvent) => void;
|
|
45
|
+
|
|
46
|
+
// `v-model:value`, written out rather than with defineModel: a choice is never undefined, and
|
|
47
|
+
// defineModel would say that it can be. See useControllable too.
|
|
48
|
+
const {
|
|
49
|
+
value: given,
|
|
50
|
+
defaultValue,
|
|
51
|
+
label,
|
|
52
|
+
options,
|
|
53
|
+
placeholder,
|
|
54
|
+
description,
|
|
55
|
+
error,
|
|
56
|
+
name,
|
|
57
|
+
disabled = false,
|
|
58
|
+
multiple = false,
|
|
59
|
+
values: givenValues,
|
|
60
|
+
defaultValues,
|
|
61
|
+
} = defineProps<SelectProps<Value>>();
|
|
62
|
+
const emit = defineEmits<{
|
|
63
|
+
"update:value": [value: Value];
|
|
64
|
+
/** The chosen options of a select with `multiple`, in the options' order. */
|
|
65
|
+
"update:values": [values: Value[]];
|
|
66
|
+
valuesChange: [values: Value[]];
|
|
67
|
+
}>();
|
|
68
|
+
const { value, set } = useControllable<Value | undefined>(
|
|
69
|
+
"value",
|
|
70
|
+
() => given,
|
|
71
|
+
() => defaultValue,
|
|
72
|
+
(next) => {
|
|
73
|
+
if (next !== undefined) emit("update:value", next);
|
|
74
|
+
},
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
const { value: values, set: setValues } = useControllable<readonly Value[]>(
|
|
78
|
+
"values",
|
|
79
|
+
() => givenValues,
|
|
80
|
+
() => defaultValues ?? [],
|
|
81
|
+
(next) => {
|
|
82
|
+
emit("update:values", [...next]);
|
|
83
|
+
emit("valuesChange", [...next]);
|
|
84
|
+
},
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
const id = useId();
|
|
88
|
+
const valueId = `${id}-value`;
|
|
89
|
+
const descriptionId = `${id}-description`;
|
|
90
|
+
const errorId = `${id}-error`;
|
|
91
|
+
const invalid = computed(() => error !== undefined);
|
|
92
|
+
const collection = computed(() =>
|
|
93
|
+
select.collection<SelectOption<Value>>({
|
|
94
|
+
items: [...options],
|
|
95
|
+
itemToValue: (option) => option.value,
|
|
96
|
+
itemToString: (option) => option.label,
|
|
97
|
+
}),
|
|
98
|
+
);
|
|
99
|
+
const service = useMachine(
|
|
100
|
+
select.machine,
|
|
101
|
+
computed(() => ({
|
|
102
|
+
id,
|
|
103
|
+
collection: collection.value,
|
|
104
|
+
value: multiple ? [...values.value] : value.value === undefined ? [] : [value.value],
|
|
105
|
+
onValueChange: (details: select.ValueChangeDetails<SelectOption<Value>>) => {
|
|
106
|
+
if (multiple) {
|
|
107
|
+
setValues(orderedValues(options, details.value as Value[]));
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const next = details.value[0];
|
|
111
|
+
if (next !== undefined) set(next as Value);
|
|
112
|
+
},
|
|
113
|
+
multiple,
|
|
114
|
+
// Several are chosen one after another, so the list stays until the person closes it.
|
|
115
|
+
closeOnSelect: !multiple,
|
|
116
|
+
disabled,
|
|
117
|
+
invalid: invalid.value,
|
|
118
|
+
name,
|
|
119
|
+
positioning: {
|
|
120
|
+
placement: "bottom-start" as const,
|
|
121
|
+
gutter: readCssPx(null, "--xds-space-1", space[1]),
|
|
122
|
+
sameWidth: true,
|
|
123
|
+
// The list keeps this far from the window's edges.
|
|
124
|
+
overflowPadding: readCssPx(null, "--xds-space-3", space[3]),
|
|
125
|
+
},
|
|
126
|
+
})),
|
|
127
|
+
);
|
|
128
|
+
const api = computed(() => select.connect(service, normalizeProps));
|
|
129
|
+
// Zag's key handlers read whether a search by typing is under way when the field renders, and
|
|
130
|
+
// a search ends on a timer, which renders nothing: long after a search, Space would still
|
|
131
|
+
// search for a space instead of opening the list or choosing. A handler taken from the machine
|
|
132
|
+
// when the key comes reads it then.
|
|
133
|
+
const current = () => select.connect(service, normalizeProps);
|
|
134
|
+
// A span: the field is a button, which a <label> cannot point at. A press on it still focuses
|
|
135
|
+
// the field.
|
|
136
|
+
const labelProps = computed(() => {
|
|
137
|
+
const { for: _, ...rest } = api.value.getLabelProps();
|
|
138
|
+
return rest;
|
|
139
|
+
});
|
|
140
|
+
// A button that opens a list box, rather than Zag's combobox: named by the chosen option and
|
|
141
|
+
// then the label, and described by the help or the error. The error is said there, so the
|
|
142
|
+
// button itself does not claim to be invalid or required.
|
|
143
|
+
const triggerProps = computed(() => {
|
|
144
|
+
const {
|
|
145
|
+
role: _role,
|
|
146
|
+
"aria-invalid": _invalid,
|
|
147
|
+
"aria-required": _required,
|
|
148
|
+
onKeydown: _onKeydown,
|
|
149
|
+
...rest
|
|
150
|
+
} = api.value.getTriggerProps();
|
|
151
|
+
return {
|
|
152
|
+
...rest,
|
|
153
|
+
// Home and End leave a closed field to the page; Zag would choose the first or the last
|
|
154
|
+
// option.
|
|
155
|
+
onKeydown: (event: KeyboardEvent) => {
|
|
156
|
+
if (!api.value.open && (event.key === "Home" || event.key === "End")) return;
|
|
157
|
+
(current().getTriggerProps().onKeydown as KeyHandler | undefined)?.(event);
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
});
|
|
161
|
+
const positioner = useTemplateRef<HTMLDivElement>("positioner");
|
|
162
|
+
const surface = useTemplateRef<HTMLDivElement>("surface");
|
|
163
|
+
useModalPopover(
|
|
164
|
+
() => api.value.open,
|
|
165
|
+
() => positioner.value,
|
|
166
|
+
);
|
|
167
|
+
const present = usePresence(
|
|
168
|
+
() => api.value.open,
|
|
169
|
+
() => [surface.value],
|
|
170
|
+
);
|
|
171
|
+
const content = computed(() => {
|
|
172
|
+
const { onKeydown: _onKeydown, ...rest } = api.value.getContentProps();
|
|
173
|
+
return {
|
|
174
|
+
...rest,
|
|
175
|
+
onKeydown: (event: KeyboardEvent) => {
|
|
176
|
+
keepListKeys(event, surface.value, ".{{prefix}}-select__item:not([data-disabled])", (next) =>
|
|
177
|
+
api.value.setHighlightedValue(next),
|
|
178
|
+
);
|
|
179
|
+
(current().getContentProps().onKeydown as KeyHandler | undefined)?.(event);
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
});
|
|
183
|
+
</script>
|
|
184
|
+
|
|
185
|
+
<template>
|
|
186
|
+
<div v-bind="api.getRootProps()" class="{{prefix}}-select">
|
|
187
|
+
<span v-bind="labelProps" class="{{prefix}}-select__label">{{ label }}</span>
|
|
188
|
+
<button
|
|
189
|
+
v-bind="triggerProps"
|
|
190
|
+
:aria-labelledby="`${valueId} ${labelProps.id}`"
|
|
191
|
+
:aria-describedby="invalid ? errorId : description ? descriptionId : undefined"
|
|
192
|
+
class="{{prefix}}-select__trigger"
|
|
193
|
+
>
|
|
194
|
+
<!-- The chosen option's label alone: the list's rows also hold a description and a
|
|
195
|
+
check, which do not belong in the field. -->
|
|
196
|
+
<span v-bind="api.getValueTextProps()" :id="valueId" class="{{prefix}}-select__value">
|
|
197
|
+
{{ (multiple ? selectedLabels(options, values) : api.valueAsString) || placeholder }}
|
|
198
|
+
</span>
|
|
199
|
+
<Icon name="chevrons-up-down" size="sm" class="text-xds-field-placeholder" />
|
|
200
|
+
</button>
|
|
201
|
+
<!-- One line under the box: the help, or the error in its place. The error stays mounted as
|
|
202
|
+
a live region so assistive technology announces it when it appears. -->
|
|
203
|
+
<div class="{{prefix}}-select__footer">
|
|
204
|
+
<span
|
|
205
|
+
v-if="!invalid && description"
|
|
206
|
+
:id="descriptionId"
|
|
207
|
+
class="{{prefix}}-select__description"
|
|
208
|
+
>
|
|
209
|
+
{{ description }}
|
|
210
|
+
</span>
|
|
211
|
+
<span :id="errorId" class="{{prefix}}-select__error" aria-live="polite">{{ error }}</span>
|
|
212
|
+
</div>
|
|
213
|
+
<!-- What a form submits; in a select of one, the first option stands for no choice. Zag's
|
|
214
|
+
props hide it from assistive technology, which uses the trigger. -->
|
|
215
|
+
<select v-bind="api.getHiddenSelectProps()">
|
|
216
|
+
<option v-if="!multiple" value="" />
|
|
217
|
+
<option v-for="option in options" :key="option.value" :value="option.value">
|
|
218
|
+
{{ option.label }}
|
|
219
|
+
</option>
|
|
220
|
+
</select>
|
|
221
|
+
<Portal>
|
|
222
|
+
<!-- Takes a press outside, which then only closes the list. The focus stays in the list
|
|
223
|
+
until the list hands it back to the field. -->
|
|
224
|
+
<div
|
|
225
|
+
v-if="api.open"
|
|
226
|
+
class="{{prefix}}-select__underlay"
|
|
227
|
+
:style="underlayLayerStyle(api.getPositionerProps().style)"
|
|
228
|
+
@mousedown.prevent
|
|
229
|
+
/>
|
|
230
|
+
<div ref="positioner" v-bind="api.getPositionerProps()" class="{{prefix}}-select__positioner">
|
|
231
|
+
<!-- Shown until its exit animation ends; Zag would hide it as it closes. -->
|
|
232
|
+
<div v-bind="content" ref="surface" :hidden="!present" class="{{prefix}}-select__content">
|
|
233
|
+
<div v-bind="api.getListProps()" class="{{prefix}}-select__list">
|
|
234
|
+
<!-- Named by its label alone, as the field shows it; the help line describes it. -->
|
|
235
|
+
<div
|
|
236
|
+
v-for="(option, index) in collection.items"
|
|
237
|
+
:key="option.value"
|
|
238
|
+
v-bind="api.getItemProps({ item: option })"
|
|
239
|
+
:aria-labelledby="selectOptionIds(id, index).label"
|
|
240
|
+
:aria-describedby="
|
|
241
|
+
option.description ? selectOptionIds(id, index).description : undefined
|
|
242
|
+
"
|
|
243
|
+
class="{{prefix}}-select__item"
|
|
244
|
+
>
|
|
245
|
+
<span class="{{prefix}}-select__item-words">
|
|
246
|
+
<span
|
|
247
|
+
v-bind="api.getItemTextProps({ item: option })"
|
|
248
|
+
:id="selectOptionIds(id, index).label"
|
|
249
|
+
class="{{prefix}}-select__item-label"
|
|
250
|
+
>
|
|
251
|
+
{{ option.label }}
|
|
252
|
+
</span>
|
|
253
|
+
<span
|
|
254
|
+
v-if="option.description"
|
|
255
|
+
:id="selectOptionIds(id, index).description"
|
|
256
|
+
class="{{prefix}}-select__item-description"
|
|
257
|
+
>
|
|
258
|
+
{{ option.description }}
|
|
259
|
+
</span>
|
|
260
|
+
</span>
|
|
261
|
+
<!-- Unnamed, unlike a Menu's: the option itself reports that it is selected. -->
|
|
262
|
+
<Icon v-if="api.getItemState({ item: option }).selected" name="check" size="sm" />
|
|
263
|
+
</div>
|
|
264
|
+
</div>
|
|
265
|
+
</div>
|
|
266
|
+
</div>
|
|
267
|
+
</Portal>
|
|
268
|
+
</div>
|
|
269
|
+
</template>
|
|
@@ -0,0 +1,101 @@
|
|
|
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 { tooltipEndSide } from "@xds/vue/base";
|
|
7
|
+
import { useId } from "vue";
|
|
8
|
+
import Icon from "./Icon.vue";
|
|
9
|
+
// The top-level places of an app used with a pointer: the counterpart of TabBar on touch. Each
|
|
10
|
+
// row is a compact list row; the current one is selected, its title heavier and its icon
|
|
11
|
+
// filled, so the place does not depend on the tint alone.
|
|
12
|
+
//
|
|
13
|
+
// It is navigation named by `label`, and the current row says it is the current page.
|
|
14
|
+
// Collapsed, the rows keep their names, and show them in a Tooltip under a pointer and on
|
|
15
|
+
// keyboard focus.
|
|
16
|
+
import { classes, rootPart } from "./parts.ts";
|
|
17
|
+
import PlaceRow from "./PlaceRow.vue";
|
|
18
|
+
import {
|
|
19
|
+
SIDEBAR_PARTS,
|
|
20
|
+
type SidebarBaseProps,
|
|
21
|
+
sidebarClass,
|
|
22
|
+
sidebarCount,
|
|
23
|
+
sidebarIconClass,
|
|
24
|
+
sidebarSectionClass,
|
|
25
|
+
sidebarTitleClass,
|
|
26
|
+
} from "./sidebar.ts";
|
|
27
|
+
import SidebarRailButton from "./SidebarRailButton.vue";
|
|
28
|
+
import TooltipOverlay from "./TooltipOverlay.vue";
|
|
29
|
+
|
|
30
|
+
export type { SidebarItem, SidebarSection } from "./sidebar.ts";
|
|
31
|
+
|
|
32
|
+
export type SidebarProps<Value extends string = string> = Omit<SidebarBaseProps<Value>, "value">;
|
|
33
|
+
|
|
34
|
+
const value = defineModel<Value>("value", { required: true });
|
|
35
|
+
const { sections, label, collapsed = false } = defineProps<SidebarProps<Value>>();
|
|
36
|
+
const slots = defineSlots<{
|
|
37
|
+
/** At the top, such as the app's name. It has to fit the rail itself while collapsed. */
|
|
38
|
+
header?(): unknown;
|
|
39
|
+
/** At the bottom, such as an account row. It has to fit the rail itself while collapsed. */
|
|
40
|
+
footer?(): unknown;
|
|
41
|
+
}>();
|
|
42
|
+
|
|
43
|
+
const id = useId();
|
|
44
|
+
// A section has nothing but its position to tell it apart: titles are optional.
|
|
45
|
+
const titleId = (index: number) => `${id}-${index}`;
|
|
46
|
+
</script>
|
|
47
|
+
|
|
48
|
+
<template>
|
|
49
|
+
<nav :aria-label="label" :class="classes(rootPart('Sidebar'), sidebarClass(collapsed))">
|
|
50
|
+
<div v-if="slots.header" :class="SIDEBAR_PARTS.edge"><slot name="header" /></div>
|
|
51
|
+
<!-- The places scroll when there are more than fit; the header and footer stay. -->
|
|
52
|
+
<div :class="SIDEBAR_PARTS.places">
|
|
53
|
+
<div
|
|
54
|
+
v-for="(section, index) in sections"
|
|
55
|
+
:key="index"
|
|
56
|
+
:class="sidebarSectionClass(index, collapsed)"
|
|
57
|
+
>
|
|
58
|
+
<p v-if="section.title" :id="titleId(index)" :class="sidebarTitleClass(collapsed)">
|
|
59
|
+
{{ section.title }}
|
|
60
|
+
</p>
|
|
61
|
+
<div v-if="collapsed && index > 0" aria-hidden="true" :class="SIDEBAR_PARTS.rule" />
|
|
62
|
+
<ul
|
|
63
|
+
:aria-labelledby="section.title ? titleId(index) : undefined"
|
|
64
|
+
:class="SIDEBAR_PARTS.list"
|
|
65
|
+
>
|
|
66
|
+
<li v-for="item in section.items" :key="item.value" :class="SIDEBAR_PARTS.item">
|
|
67
|
+
<TooltipOverlay v-if="collapsed" :label="item.label" :placement="tooltipEndSide()">
|
|
68
|
+
<SidebarRailButton
|
|
69
|
+
:label="item.label"
|
|
70
|
+
:icon="item.icon"
|
|
71
|
+
:selected="item.value === value"
|
|
72
|
+
@press="value = item.value"
|
|
73
|
+
/>
|
|
74
|
+
</TooltipOverlay>
|
|
75
|
+
<PlaceRow
|
|
76
|
+
v-else
|
|
77
|
+
compact
|
|
78
|
+
current="page"
|
|
79
|
+
:selected="item.value === value"
|
|
80
|
+
:title="item.label"
|
|
81
|
+
@press="value = item.value"
|
|
82
|
+
>
|
|
83
|
+
<template #leading>
|
|
84
|
+
<Icon
|
|
85
|
+
:name="item.icon"
|
|
86
|
+
size="md"
|
|
87
|
+
:filled="item.value === value"
|
|
88
|
+
:class="sidebarIconClass(item.value === value)"
|
|
89
|
+
/>
|
|
90
|
+
</template>
|
|
91
|
+
<template v-if="sidebarCount(item.count)" #trailing>
|
|
92
|
+
<span :class="SIDEBAR_PARTS.count">{{ sidebarCount(item.count) }}</span>
|
|
93
|
+
</template>
|
|
94
|
+
</PlaceRow>
|
|
95
|
+
</li>
|
|
96
|
+
</ul>
|
|
97
|
+
</div>
|
|
98
|
+
</div>
|
|
99
|
+
<div v-if="slots.footer" :class="SIDEBAR_PARTS.edge"><slot name="footer" /></div>
|
|
100
|
+
</nav>
|
|
101
|
+
</template>
|
|
@@ -0,0 +1,31 @@
|
|
|
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 row of a collapsed Sidebar: its icon alone. It is the trigger of the Tooltip that names it.
|
|
7
|
+
// Only for Sidebar: the index does not export it.
|
|
8
|
+
import { type IconName, useTrigger } from "@xds/vue/base";
|
|
9
|
+
import type { ButtonHTMLAttributes } from "vue";
|
|
10
|
+
import Icon from "./Icon.vue";
|
|
11
|
+
import { sidebarRailButtonClass } from "./sidebar.ts";
|
|
12
|
+
|
|
13
|
+
const { label, icon, selected } = defineProps<{
|
|
14
|
+
label: string;
|
|
15
|
+
icon: IconName;
|
|
16
|
+
selected: boolean;
|
|
17
|
+
}>();
|
|
18
|
+
const emit = defineEmits<{ press: [] }>();
|
|
19
|
+
|
|
20
|
+
const attributes = useTrigger((): ButtonHTMLAttributes => ({
|
|
21
|
+
type: "button",
|
|
22
|
+
class: sidebarRailButtonClass(selected),
|
|
23
|
+
"aria-label": label,
|
|
24
|
+
"aria-current": selected ? "page" : undefined,
|
|
25
|
+
onClick: () => emit("press"),
|
|
26
|
+
}));
|
|
27
|
+
</script>
|
|
28
|
+
|
|
29
|
+
<template>
|
|
30
|
+
<button v-bind="attributes"><Icon :name="icon" size="md" :filled="selected" /></button>
|
|
31
|
+
</template>
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
// Holds the place of content that is loading, in the shape the content will have. It pulses,
|
|
8
|
+
// and stands still for people who ask for less motion.
|
|
9
|
+
//
|
|
10
|
+
// It is hidden from assistive technology: the screen that shows skeletons says that it is
|
|
11
|
+
// loading, once, instead of every placeholder saying so.
|
|
12
|
+
import { classes, rootPart } from "./parts.ts";
|
|
13
|
+
import { type SkeletonBaseProps, skeletonClass, skeletonSize } from "./skeleton.ts";
|
|
14
|
+
|
|
15
|
+
export type SkeletonProps = SkeletonBaseProps;
|
|
16
|
+
|
|
17
|
+
const { shape, width, height } = defineProps<SkeletonProps>();
|
|
18
|
+
const options = useDefaults("Skeleton", () => ({ shape }));
|
|
19
|
+
</script>
|
|
20
|
+
|
|
21
|
+
<template>
|
|
22
|
+
<span
|
|
23
|
+
aria-hidden="true"
|
|
24
|
+
:class="classes(rootPart('Skeleton'), skeletonClass(options.shape))"
|
|
25
|
+
:style="skeletonSize({ shape: options.shape, width, height })"
|
|
26
|
+
/>
|
|
27
|
+
</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">
|
|
6
|
+
import { useControllable } from "@xds/vue/base";
|
|
7
|
+
import * as slider from "@zag-js/slider";
|
|
8
|
+
import { mergeProps, normalizeProps, useMachine } from "@zag-js/vue";
|
|
9
|
+
import { computed, useId, useTemplateRef } from "vue";
|
|
10
|
+
// Picks a number in a range by dragging the thumb, or by pressing the track where it should
|
|
11
|
+
// go. The values snap to `step`.
|
|
12
|
+
//
|
|
13
|
+
// It is a slider named by its label with its value, minimum and maximum, and each arrow key
|
|
14
|
+
// moves it one step.
|
|
15
|
+
import {
|
|
16
|
+
focusThumbOnPress,
|
|
17
|
+
type SliderBaseProps,
|
|
18
|
+
sliderArrowValue,
|
|
19
|
+
sliderPageSize,
|
|
20
|
+
sliderValueText,
|
|
21
|
+
} from "./slider.ts";
|
|
22
|
+
|
|
23
|
+
export type SliderProps = SliderBaseProps;
|
|
24
|
+
|
|
25
|
+
// `v-model:value`, written out rather than with defineModel: see useControllable.
|
|
26
|
+
const {
|
|
27
|
+
value: given,
|
|
28
|
+
defaultValue,
|
|
29
|
+
label,
|
|
30
|
+
min = 0,
|
|
31
|
+
max = 100,
|
|
32
|
+
step = 1,
|
|
33
|
+
disabled = false,
|
|
34
|
+
showValue = false,
|
|
35
|
+
name,
|
|
36
|
+
locale,
|
|
37
|
+
} = defineProps<SliderProps>();
|
|
38
|
+
const emit = defineEmits<{ "update:value": [value: number] }>();
|
|
39
|
+
const { value, set } = useControllable(
|
|
40
|
+
"value",
|
|
41
|
+
() => given,
|
|
42
|
+
() => defaultValue ?? min,
|
|
43
|
+
(next) => emit("update:value", next),
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const id = useId();
|
|
47
|
+
const pageSize = computed(() => sliderPageSize({ min, max, step }));
|
|
48
|
+
const service = useMachine(
|
|
49
|
+
slider.machine,
|
|
50
|
+
computed(() => ({
|
|
51
|
+
id,
|
|
52
|
+
name,
|
|
53
|
+
value: [value.value],
|
|
54
|
+
// One thumb, so one number.
|
|
55
|
+
onValueChange: (details: slider.ValueChangeDetails) => set(details.value[0] ?? min),
|
|
56
|
+
min,
|
|
57
|
+
max,
|
|
58
|
+
step,
|
|
59
|
+
largeStep: pageSize.value,
|
|
60
|
+
disabled,
|
|
61
|
+
// The thumb's center is on the value, at the ends too; the band is inset to make room.
|
|
62
|
+
thumbAlignment: "center" as const,
|
|
63
|
+
getAriaValueText: (details: { value: number }) => sliderValueText(details.value, locale),
|
|
64
|
+
})),
|
|
65
|
+
);
|
|
66
|
+
const api = computed(() => slider.connect(service, normalizeProps));
|
|
67
|
+
const thumbElement = useTemplateRef<HTMLDivElement>("thumb");
|
|
68
|
+
const thumb = computed(() =>
|
|
69
|
+
mergeProps(api.value.getThumbProps({ index: 0 }), {
|
|
70
|
+
// Up and Down move a horizontal slider too, as they move a native range input.
|
|
71
|
+
onKeydown: (event: KeyboardEvent) => {
|
|
72
|
+
if (disabled) return;
|
|
73
|
+
const next = sliderArrowValue(event, {
|
|
74
|
+
value: api.value.value[0] ?? min,
|
|
75
|
+
min,
|
|
76
|
+
max,
|
|
77
|
+
step,
|
|
78
|
+
pageSize: pageSize.value,
|
|
79
|
+
});
|
|
80
|
+
if (next !== undefined) {
|
|
81
|
+
event.preventDefault();
|
|
82
|
+
api.value.setThumbValue(0, next);
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
}),
|
|
86
|
+
);
|
|
87
|
+
const control = computed(() =>
|
|
88
|
+
mergeProps(api.value.getControlProps(), {
|
|
89
|
+
// No focus ring after a press. This handler runs before Zag's.
|
|
90
|
+
onPointerdown: (event: PointerEvent) => {
|
|
91
|
+
if (!disabled) focusThumbOnPress(event, thumbElement.value ?? undefined);
|
|
92
|
+
},
|
|
93
|
+
}),
|
|
94
|
+
);
|
|
95
|
+
</script>
|
|
96
|
+
|
|
97
|
+
<template>
|
|
98
|
+
<!-- A group named by the label, around the label, the value and the slider. Not a fieldset:
|
|
99
|
+
that is for a set of fields, and this is one slider and its label. -->
|
|
100
|
+
<div
|
|
101
|
+
v-bind="api.getRootProps()"
|
|
102
|
+
role="group"
|
|
103
|
+
:aria-labelledby="api.getLabelProps().id"
|
|
104
|
+
class="{{prefix}}-slider"
|
|
105
|
+
>
|
|
106
|
+
<!-- Zag's props give it `for`, the hidden input's id. -->
|
|
107
|
+
<label v-bind="api.getLabelProps()" class="{{prefix}}-slider__label">{{ label }}</label>
|
|
108
|
+
<!-- Read when asked for, not at every step: the slider itself announces its value. -->
|
|
109
|
+
<output
|
|
110
|
+
v-if="showValue"
|
|
111
|
+
v-bind="api.getValueTextProps()"
|
|
112
|
+
aria-live="off"
|
|
113
|
+
class="{{prefix}}-slider__output"
|
|
114
|
+
>
|
|
115
|
+
{{ sliderValueText(api.value[0] ?? value, locale) }}
|
|
116
|
+
</output>
|
|
117
|
+
<div v-bind="control" class="{{prefix}}-slider__control">
|
|
118
|
+
<div v-bind="api.getTrackProps()" class="{{prefix}}-slider__track">
|
|
119
|
+
<div v-bind="api.getRangeProps()" class="{{prefix}}-slider__range" />
|
|
120
|
+
</div>
|
|
121
|
+
<div v-bind="thumb" ref="thumb" class="{{prefix}}-slider__thumb">
|
|
122
|
+
<input v-bind="api.getHiddenInputProps({ index: 0 })" />
|
|
123
|
+
</div>
|
|
124
|
+
</div>
|
|
125
|
+
</div>
|
|
126
|
+
</template>
|
|
@@ -0,0 +1,36 @@
|
|
|
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
|
+
// Says that something is in progress and how long is unknown. Takes the color of the text
|
|
8
|
+
// around it. With `label` it is announced; without one it is decoration next to text that
|
|
9
|
+
// already says what is happening.
|
|
10
|
+
import { classes, rootPart } from "./parts.ts";
|
|
11
|
+
import { type SpinnerBaseProps, spinnerClass } from "./spinner.ts";
|
|
12
|
+
|
|
13
|
+
export type SpinnerProps = SpinnerBaseProps;
|
|
14
|
+
|
|
15
|
+
const { size, label } = defineProps<SpinnerProps>();
|
|
16
|
+
const options = useDefaults("Spinner", () => ({ size }));
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<template>
|
|
20
|
+
<span
|
|
21
|
+
:class="classes(rootPart('Spinner'), 'inline-flex shrink-0')"
|
|
22
|
+
:role="label ? 'status' : undefined"
|
|
23
|
+
:aria-label="label || undefined"
|
|
24
|
+
:aria-hidden="label ? undefined : 'true'"
|
|
25
|
+
>
|
|
26
|
+
<svg viewBox="0 0 24 24" fill="none" aria-hidden="true" :class="spinnerClass(options.size)">
|
|
27
|
+
<circle cx="12" cy="12" r="9" stroke="currentColor" stroke-width="3" opacity="0.25" />
|
|
28
|
+
<path
|
|
29
|
+
d="M21 12a9 9 0 0 0-9-9"
|
|
30
|
+
stroke="currentColor"
|
|
31
|
+
stroke-width="3"
|
|
32
|
+
stroke-linecap="round"
|
|
33
|
+
/>
|
|
34
|
+
</svg>
|
|
35
|
+
</span>
|
|
36
|
+
</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 {
|
|
7
|
+
focusable,
|
|
8
|
+
formDefault,
|
|
9
|
+
keepChecked,
|
|
10
|
+
useControllable,
|
|
11
|
+
useFormReset,
|
|
12
|
+
} from "@xds/vue/base";
|
|
13
|
+
import { useTemplateRef } from "vue";
|
|
14
|
+
// Turns a setting on or off, and takes effect at once. For a choice that is applied later,
|
|
15
|
+
// with a form, use a Checkbox.
|
|
16
|
+
//
|
|
17
|
+
// It is a native checkbox with the switch role, so the keyboard, forms and screen readers
|
|
18
|
+
// treat it as one. The input is hidden and the track is drawn beside it.
|
|
19
|
+
import { classes, rootPart } from "./parts.ts";
|
|
20
|
+
import {
|
|
21
|
+
type SwitchBaseProps,
|
|
22
|
+
switchClass,
|
|
23
|
+
switchLabelClass,
|
|
24
|
+
switchThumbClass,
|
|
25
|
+
switchTrackClass,
|
|
26
|
+
} from "./switch.ts";
|
|
27
|
+
|
|
28
|
+
// `aria-label` is declared as `ariaLabel`: Vue keeps a prop under its camelized name, and a
|
|
29
|
+
// template still writes `aria-label`.
|
|
30
|
+
export type SwitchProps = Omit<SwitchBaseProps, "aria-label"> & { ariaLabel?: string };
|
|
31
|
+
|
|
32
|
+
// `v-model:checked`, written out rather than with defineModel: see useControllable.
|
|
33
|
+
const {
|
|
34
|
+
checked: given,
|
|
35
|
+
defaultChecked = false,
|
|
36
|
+
label,
|
|
37
|
+
ariaLabel,
|
|
38
|
+
disabled = false,
|
|
39
|
+
} = defineProps<SwitchProps>();
|
|
40
|
+
const emit = defineEmits<{
|
|
41
|
+
"update:checked": [checked: boolean];
|
|
42
|
+
// On the native checkbox: the label, the root, never takes the focus.
|
|
43
|
+
focus: [event: FocusEvent];
|
|
44
|
+
blur: [event: FocusEvent];
|
|
45
|
+
}>();
|
|
46
|
+
|
|
47
|
+
const input = useTemplateRef<HTMLInputElement>("input");
|
|
48
|
+
const {
|
|
49
|
+
value: checked,
|
|
50
|
+
set,
|
|
51
|
+
controlled,
|
|
52
|
+
reset,
|
|
53
|
+
} = useControllable(
|
|
54
|
+
"checked",
|
|
55
|
+
() => given,
|
|
56
|
+
() => defaultChecked,
|
|
57
|
+
(next) => emit("update:checked", next),
|
|
58
|
+
);
|
|
59
|
+
useFormReset(() => input.value, controlled, reset);
|
|
60
|
+
defineExpose(focusable(() => input.value));
|
|
61
|
+
|
|
62
|
+
function change(event: Event) {
|
|
63
|
+
const element = event.currentTarget as HTMLInputElement;
|
|
64
|
+
set(element.checked);
|
|
65
|
+
keepChecked(element, () => checked.value);
|
|
66
|
+
}
|
|
67
|
+
</script>
|
|
68
|
+
|
|
69
|
+
<template>
|
|
70
|
+
<label :class="classes(rootPart('Switch'), switchClass)">
|
|
71
|
+
<input
|
|
72
|
+
ref="input"
|
|
73
|
+
type="checkbox"
|
|
74
|
+
role="switch"
|
|
75
|
+
:aria-checked="checked ? 'true' : 'false'"
|
|
76
|
+
:aria-label="ariaLabel"
|
|
77
|
+
class="peer sr-only"
|
|
78
|
+
:checked="checked"
|
|
79
|
+
v-bind="formDefault({ defaultChecked: checked })"
|
|
80
|
+
:disabled="disabled"
|
|
81
|
+
@change="change"
|
|
82
|
+
@focus="emit('focus', $event)"
|
|
83
|
+
@blur="emit('blur', $event)"
|
|
84
|
+
/>
|
|
85
|
+
<span :class="switchTrackClass"><span :class="switchThumbClass" /></span>
|
|
86
|
+
<span v-if="label" :class="switchLabelClass">{{ label }}</span>
|
|
87
|
+
</label>
|
|
88
|
+
</template>
|