@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,77 @@
|
|
|
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 Icon from "./Icon.vue";
|
|
7
|
+
import { rootPart } from "./parts.ts";
|
|
8
|
+
// Rows of data under a row of column headers, to read and compare across. The header of a
|
|
9
|
+
// sortable column is a button that asks for the rows sorted by it (`sortChange`), ascending first
|
|
10
|
+
// and then the other way, and the header they are sorted by says so with `aria-sort` and an
|
|
11
|
+
// arrow. The rows are shown in the order given. Where the columns do not fit, the table scrolls
|
|
12
|
+
// sideways.
|
|
13
|
+
import {
|
|
14
|
+
columnSort,
|
|
15
|
+
nextSort,
|
|
16
|
+
sortIcon,
|
|
17
|
+
TABLE_PARTS,
|
|
18
|
+
type TableBaseProps,
|
|
19
|
+
type TableSort,
|
|
20
|
+
} from "./table.ts";
|
|
21
|
+
|
|
22
|
+
export type { SortDirection, TableColumn, TableRow, TableSort } from "./table.ts";
|
|
23
|
+
|
|
24
|
+
export type TableProps = TableBaseProps;
|
|
25
|
+
|
|
26
|
+
const { label, columns, rows, sort, empty } = defineProps<TableProps>();
|
|
27
|
+
const emit = defineEmits<{
|
|
28
|
+
/** The sort a press on a sortable column's header asks for; the app sorts the rows. */
|
|
29
|
+
sortChange: [sort: TableSort];
|
|
30
|
+
}>();
|
|
31
|
+
const end = (align: string | undefined) => (align === "end" ? TABLE_PARTS.end : undefined);
|
|
32
|
+
</script>
|
|
33
|
+
|
|
34
|
+
<template>
|
|
35
|
+
<div :class="rootPart('Table')">
|
|
36
|
+
<table :class="TABLE_PARTS.table" :aria-label="label">
|
|
37
|
+
<thead>
|
|
38
|
+
<tr :class="TABLE_PARTS.row">
|
|
39
|
+
<th
|
|
40
|
+
v-for="column in columns"
|
|
41
|
+
:key="column.key"
|
|
42
|
+
scope="col"
|
|
43
|
+
:aria-sort="columnSort(sort, column.key)"
|
|
44
|
+
:class="[TABLE_PARTS.header, end(column.align)]"
|
|
45
|
+
>
|
|
46
|
+
<button
|
|
47
|
+
v-if="column.sortable"
|
|
48
|
+
type="button"
|
|
49
|
+
:class="TABLE_PARTS.sort"
|
|
50
|
+
@click="emit('sortChange', nextSort(sort, column.key))"
|
|
51
|
+
>
|
|
52
|
+
{{ column.label }}
|
|
53
|
+
<Icon :name="sortIcon(columnSort(sort, column.key))" size="xs" />
|
|
54
|
+
</button>
|
|
55
|
+
<template v-else>{{ column.label }}</template>
|
|
56
|
+
</th>
|
|
57
|
+
</tr>
|
|
58
|
+
</thead>
|
|
59
|
+
<tbody>
|
|
60
|
+
<tr v-if="rows.length === 0 && empty !== undefined" :class="TABLE_PARTS.row">
|
|
61
|
+
<td :class="TABLE_PARTS.empty" :colspan="columns.length">{{ empty }}</td>
|
|
62
|
+
</tr>
|
|
63
|
+
<template v-else>
|
|
64
|
+
<tr v-for="row in rows" :key="row.id" :class="TABLE_PARTS.row">
|
|
65
|
+
<td
|
|
66
|
+
v-for="(column, index) in columns"
|
|
67
|
+
:key="column.key"
|
|
68
|
+
:class="[TABLE_PARTS.cell, end(column.align)]"
|
|
69
|
+
>
|
|
70
|
+
{{ row.cells[index] }}
|
|
71
|
+
</td>
|
|
72
|
+
</tr>
|
|
73
|
+
</template>
|
|
74
|
+
</tbody>
|
|
75
|
+
</table>
|
|
76
|
+
</div>
|
|
77
|
+
</template>
|
|
@@ -0,0 +1,72 @@
|
|
|
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 { useControllable } from "@xds/vue/base";
|
|
7
|
+
import * as tabs from "@zag-js/tabs";
|
|
8
|
+
import { normalizeProps, useMachine } from "@zag-js/vue";
|
|
9
|
+
import { computed, useId } from "vue";
|
|
10
|
+
import Icon from "./Icon.vue";
|
|
11
|
+
// Switches between views inside one screen. For two to four short modes a SegmentedControl is
|
|
12
|
+
// lighter; tabs are for more items, longer labels, or a row that may have to scroll.
|
|
13
|
+
//
|
|
14
|
+
// The selected tab is underlined as well as darker, so the choice does not depend on color.
|
|
15
|
+
// This is only the row: the app shows the view that matches `value`. The arrow keys move
|
|
16
|
+
// between tabs.
|
|
17
|
+
import { type TabsBaseProps, tabStopIndex, tabsClass } from "./tabs.ts";
|
|
18
|
+
|
|
19
|
+
export type TabsProps<Value extends string> = TabsBaseProps<Value>;
|
|
20
|
+
|
|
21
|
+
// `v-model:value`, written out rather than with defineModel: see useControllable.
|
|
22
|
+
const {
|
|
23
|
+
value: given,
|
|
24
|
+
defaultValue,
|
|
25
|
+
items,
|
|
26
|
+
label,
|
|
27
|
+
fullWidth = false,
|
|
28
|
+
} = defineProps<TabsProps<Value>>();
|
|
29
|
+
const emit = defineEmits<{ "update:value": [value: Value] }>();
|
|
30
|
+
const { value, set } = useControllable(
|
|
31
|
+
"value",
|
|
32
|
+
() => given,
|
|
33
|
+
// Without a default, the first tab: one tab is always selected.
|
|
34
|
+
() => defaultValue ?? (items[0]?.value as Value),
|
|
35
|
+
(next) => emit("update:value", next),
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
const id = useId();
|
|
39
|
+
const service = useMachine(
|
|
40
|
+
tabs.machine,
|
|
41
|
+
computed(() => ({
|
|
42
|
+
id,
|
|
43
|
+
value: value.value,
|
|
44
|
+
onValueChange: (details: tabs.ValueChangeDetails) => set(details.value as Value),
|
|
45
|
+
})),
|
|
46
|
+
);
|
|
47
|
+
const api = computed(() => tabs.connect(service, normalizeProps));
|
|
48
|
+
const trigger = (item: Value) => {
|
|
49
|
+
const props = api.value.getTriggerProps({ value: item });
|
|
50
|
+
return { ...props, tabindex: tabStopIndex(api.value.focusedValue, item, props.tabindex) };
|
|
51
|
+
};
|
|
52
|
+
</script>
|
|
53
|
+
|
|
54
|
+
<template>
|
|
55
|
+
<div v-bind="api.getRootProps()" :class="tabsClass(fullWidth)">
|
|
56
|
+
<div v-bind="api.getListProps()" :aria-label="label" class="{{prefix}}-tabs__list">
|
|
57
|
+
<!-- Zag points the selected tab at its panel, which this row never renders: the app
|
|
58
|
+
shows the view. A reference to an element that does not exist is invalid. -->
|
|
59
|
+
<button
|
|
60
|
+
v-for="item in items"
|
|
61
|
+
:key="item.value"
|
|
62
|
+
v-bind="trigger(item.value)"
|
|
63
|
+
:aria-controls="undefined"
|
|
64
|
+
type="button"
|
|
65
|
+
class="{{prefix}}-tabs__tab"
|
|
66
|
+
>
|
|
67
|
+
<Icon v-if="item.icon" :name="item.icon" size="sm" />{{ item.label }}
|
|
68
|
+
</button>
|
|
69
|
+
<div v-bind="api.getIndicatorProps()" class="{{prefix}}-tabs__indicator" />
|
|
70
|
+
</div>
|
|
71
|
+
</div>
|
|
72
|
+
</template>
|
|
@@ -0,0 +1,22 @@
|
|
|
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 { classes, rootPart } from "./parts.ts";
|
|
8
|
+
import { type TextBaseProps, textClass } from "./text.ts";
|
|
9
|
+
|
|
10
|
+
export type TextProps = TextBaseProps & {
|
|
11
|
+
/** The element to render. Pick it for the document outline (`h1`, `h2`, `p`), not for looks. */
|
|
12
|
+
as?: keyof HTMLElementTagNameMap;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const { variant, tone, as = "p" } = defineProps<TextProps>();
|
|
16
|
+
defineSlots<{ default(): unknown }>();
|
|
17
|
+
const options = useDefaults("Text", () => ({ variant, tone }));
|
|
18
|
+
</script>
|
|
19
|
+
|
|
20
|
+
<template>
|
|
21
|
+
<component :is="as" :class="classes(rootPart('Text'), textClass(options))"><slot /></component>
|
|
22
|
+
</template>
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Ejected from `@xds/vue` 1.2.0 by `xds eject`. This copy is the app's own: change it
|
|
3
|
+
as you need. `xds eject --list` says which ejected files differ from what was copied.
|
|
4
|
+
-->
|
|
5
|
+
<script setup lang="ts">
|
|
6
|
+
import { focusable, keepValue, useControllable, useFormReset } from "@xds/vue/base";
|
|
7
|
+
import { computed, onMounted, useId, useTemplateRef, watch } from "vue";
|
|
8
|
+
// A labelled text field, of one line or several. The label, the description and the error
|
|
9
|
+
// message are tied to the input for assistive technology, and the error is announced when it
|
|
10
|
+
// appears.
|
|
11
|
+
//
|
|
12
|
+
// An invalid field blocks its form from being submitted, so `error` has to be cleared as soon as
|
|
13
|
+
// the person edits the value.
|
|
14
|
+
import type { TextFieldBaseProps } from "./text-field.ts";
|
|
15
|
+
|
|
16
|
+
// `autoComplete` is a string, as Vue's own `autocomplete` attribute is: the union of every
|
|
17
|
+
// autofill token that the shared type lists is too large for vue-tsc to destructure the props.
|
|
18
|
+
// The shared type takes any other string too, so what this gives up is the editor's list.
|
|
19
|
+
export type TextFieldProps = Omit<TextFieldBaseProps, "autoComplete"> & {
|
|
20
|
+
autoComplete?: string;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// `v-model:value`, written out rather than with defineModel: see useControllable.
|
|
24
|
+
const {
|
|
25
|
+
value: given,
|
|
26
|
+
defaultValue = "",
|
|
27
|
+
readOnly = false,
|
|
28
|
+
label,
|
|
29
|
+
description,
|
|
30
|
+
error,
|
|
31
|
+
placeholder,
|
|
32
|
+
multiline = false,
|
|
33
|
+
rows = 3,
|
|
34
|
+
maxLength,
|
|
35
|
+
name,
|
|
36
|
+
type = "text",
|
|
37
|
+
inputMode,
|
|
38
|
+
autoComplete: autocomplete,
|
|
39
|
+
autoFocus = false,
|
|
40
|
+
required = false,
|
|
41
|
+
disabled = false,
|
|
42
|
+
} = defineProps<TextFieldProps>();
|
|
43
|
+
const emit = defineEmits<{
|
|
44
|
+
"update:value": [value: string];
|
|
45
|
+
// On the input or the text area, which the root holds.
|
|
46
|
+
focus: [event: FocusEvent];
|
|
47
|
+
blur: [event: FocusEvent];
|
|
48
|
+
}>();
|
|
49
|
+
const slots = defineSlots<{
|
|
50
|
+
/**
|
|
51
|
+
* Inside the box, in front of the text: an icon, a unit. It takes the placeholder's color
|
|
52
|
+
* unless it sets its own.
|
|
53
|
+
*/
|
|
54
|
+
leading?(): unknown;
|
|
55
|
+
/** Inside the box, after the text: an icon, a unit, a small button. */
|
|
56
|
+
trailing?(): unknown;
|
|
57
|
+
}>();
|
|
58
|
+
|
|
59
|
+
const id = useId();
|
|
60
|
+
const descriptionId = `${id}-description`;
|
|
61
|
+
const errorId = `${id}-error`;
|
|
62
|
+
const invalid = computed(() => error !== undefined);
|
|
63
|
+
const input = useTemplateRef<HTMLInputElement | HTMLTextAreaElement>("input");
|
|
64
|
+
const { value, set, controlled, reset } = useControllable(
|
|
65
|
+
"value",
|
|
66
|
+
() => given,
|
|
67
|
+
() => defaultValue,
|
|
68
|
+
(next) => emit("update:value", next),
|
|
69
|
+
);
|
|
70
|
+
useFormReset(() => input.value, controlled, reset);
|
|
71
|
+
defineExpose(focusable(() => input.value));
|
|
72
|
+
// The input draws the box itself until something sits inside the box beside the text.
|
|
73
|
+
const grouped = computed(() => slots.leading !== undefined || slots.trailing !== undefined);
|
|
74
|
+
|
|
75
|
+
onMounted(() => {
|
|
76
|
+
// The value is set as a property, which leaves a text area's caret after the last line, and
|
|
77
|
+
// keyboard focus would then scroll to it. React renders the first value as the text area's
|
|
78
|
+
// own text, with the caret before the first line.
|
|
79
|
+
if (input.value instanceof HTMLTextAreaElement) input.value.setSelectionRange(0, 0);
|
|
80
|
+
if (autoFocus) input.value?.focus();
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
watch(
|
|
84
|
+
[() => error, () => multiline],
|
|
85
|
+
() => {
|
|
86
|
+
input.value?.setCustomValidity(error ?? "");
|
|
87
|
+
},
|
|
88
|
+
{ flush: "post", immediate: true },
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
// The attributes the input and the text area share.
|
|
92
|
+
const shared = computed(() => ({
|
|
93
|
+
id,
|
|
94
|
+
class: grouped.value
|
|
95
|
+
? "{{prefix}}-text-field__input"
|
|
96
|
+
: "{{prefix}}-text-field__input {{prefix}}-text-field__control",
|
|
97
|
+
value: value.value,
|
|
98
|
+
// A form's reset puts a field back to its default value: for an input its `value` attribute,
|
|
99
|
+
// which Vue writes, but for a text area its text, which Vue leaves empty. React keeps both
|
|
100
|
+
// equal to the value.
|
|
101
|
+
defaultValue: value.value,
|
|
102
|
+
placeholder,
|
|
103
|
+
name,
|
|
104
|
+
maxlength: maxLength,
|
|
105
|
+
inputmode: inputMode,
|
|
106
|
+
autocomplete,
|
|
107
|
+
required,
|
|
108
|
+
disabled,
|
|
109
|
+
readonly: readOnly,
|
|
110
|
+
"aria-invalid": invalid.value ? ("true" as const) : undefined,
|
|
111
|
+
"aria-errormessage": invalid.value ? errorId : undefined,
|
|
112
|
+
"aria-describedby": invalid.value ? errorId : description ? descriptionId : undefined,
|
|
113
|
+
onFocus: (event: FocusEvent) => emit("focus", event),
|
|
114
|
+
onBlur: (event: FocusEvent) => emit("blur", event),
|
|
115
|
+
}));
|
|
116
|
+
|
|
117
|
+
function edit(event: Event) {
|
|
118
|
+
const field = event.currentTarget as HTMLInputElement | HTMLTextAreaElement;
|
|
119
|
+
set(field.value);
|
|
120
|
+
// While a composition is open the text belongs to the input method; it ends with
|
|
121
|
+
// compositionend.
|
|
122
|
+
if (!(event as InputEvent).isComposing) keepValue(field, () => value.value);
|
|
123
|
+
}
|
|
124
|
+
function settle(event: CompositionEvent) {
|
|
125
|
+
keepValue(event.currentTarget as HTMLInputElement, () => value.value);
|
|
126
|
+
}
|
|
127
|
+
</script>
|
|
128
|
+
|
|
129
|
+
<template>
|
|
130
|
+
<div class="{{prefix}}-text-field">
|
|
131
|
+
<label :for="id" class="{{prefix}}-text-field__label">{{ label }}</label>
|
|
132
|
+
<div v-if="grouped" class="{{prefix}}-text-field__control {{prefix}}-text-field__group">
|
|
133
|
+
<span
|
|
134
|
+
v-if="slots.leading"
|
|
135
|
+
class="{{prefix}}-text-field__slot {{prefix}}-text-field__slot--leading"
|
|
136
|
+
>
|
|
137
|
+
<slot name="leading" />
|
|
138
|
+
</span>
|
|
139
|
+
<textarea
|
|
140
|
+
v-if="multiline"
|
|
141
|
+
ref="input"
|
|
142
|
+
:rows="rows"
|
|
143
|
+
v-bind="shared"
|
|
144
|
+
@input="edit"
|
|
145
|
+
@compositionend="settle"
|
|
146
|
+
/>
|
|
147
|
+
<input
|
|
148
|
+
v-else
|
|
149
|
+
ref="input"
|
|
150
|
+
:type="type"
|
|
151
|
+
v-bind="shared"
|
|
152
|
+
@input="edit"
|
|
153
|
+
@compositionend="settle"
|
|
154
|
+
/>
|
|
155
|
+
<span
|
|
156
|
+
v-if="slots.trailing"
|
|
157
|
+
class="{{prefix}}-text-field__slot {{prefix}}-text-field__slot--trailing"
|
|
158
|
+
>
|
|
159
|
+
<slot name="trailing" />
|
|
160
|
+
</span>
|
|
161
|
+
</div>
|
|
162
|
+
<textarea
|
|
163
|
+
v-else-if="multiline"
|
|
164
|
+
ref="input"
|
|
165
|
+
:rows="rows"
|
|
166
|
+
v-bind="shared"
|
|
167
|
+
@input="edit"
|
|
168
|
+
@compositionend="settle"
|
|
169
|
+
/>
|
|
170
|
+
<input v-else ref="input" :type="type" v-bind="shared" @input="edit" @compositionend="settle" />
|
|
171
|
+
<!-- One line under the box: the help or the error at the start edge, the count at the end.
|
|
172
|
+
The error is a live region, so it is announced when it appears. -->
|
|
173
|
+
<div class="{{prefix}}-text-field__footer">
|
|
174
|
+
<span
|
|
175
|
+
v-if="!invalid && description"
|
|
176
|
+
:id="descriptionId"
|
|
177
|
+
class="{{prefix}}-text-field__description"
|
|
178
|
+
>
|
|
179
|
+
{{ description }}
|
|
180
|
+
</span>
|
|
181
|
+
<span :id="errorId" class="{{prefix}}-text-field__error" aria-live="polite">{{ error }}</span>
|
|
182
|
+
<span
|
|
183
|
+
v-if="maxLength !== undefined"
|
|
184
|
+
class="ms-auto shrink-0 text-xds-footnote text-xds-text-secondary tabular-nums"
|
|
185
|
+
>
|
|
186
|
+
{{ value.length }}/{{ maxLength }}
|
|
187
|
+
</span>
|
|
188
|
+
</div>
|
|
189
|
+
</div>
|
|
190
|
+
</template>
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Ejected from `@xds/vue` 1.2.0 by `xds eject`. This copy is the app's own: change it
|
|
3
|
+
as you need. `xds eject --list` says which ejected files differ from what was copied.
|
|
4
|
+
-->
|
|
5
|
+
<script setup lang="ts">
|
|
6
|
+
import { pictureClass, useDefaults, usePicture } from "@xds/vue/base";
|
|
7
|
+
import { computed } from "vue";
|
|
8
|
+
import Badge from "./Badge.vue";
|
|
9
|
+
import Icon from "./Icon.vue";
|
|
10
|
+
// A picture in a fixed shape, for a video, an article or a product. It fills the width it is
|
|
11
|
+
// given and takes its height from `ratio`, and crops the picture to fill it.
|
|
12
|
+
import { classes, rootPart } from "./parts.ts";
|
|
13
|
+
import {
|
|
14
|
+
THUMBNAIL_PARTS,
|
|
15
|
+
type ThumbnailBaseProps,
|
|
16
|
+
thumbnailBadgeClass,
|
|
17
|
+
thumbnailClass,
|
|
18
|
+
thumbnailWatched,
|
|
19
|
+
} from "./thumbnail.ts";
|
|
20
|
+
|
|
21
|
+
export type { ThumbnailRatio } from "./thumbnail.ts";
|
|
22
|
+
|
|
23
|
+
export type ThumbnailProps = ThumbnailBaseProps;
|
|
24
|
+
|
|
25
|
+
const { src, alt, ratio, badge, progress } = defineProps<ThumbnailProps>();
|
|
26
|
+
const options = useDefaults("Thumbnail", () => ({ ratio }));
|
|
27
|
+
const picture = usePicture(() => src);
|
|
28
|
+
const watched = computed(() => thumbnailWatched(progress));
|
|
29
|
+
</script>
|
|
30
|
+
|
|
31
|
+
<template>
|
|
32
|
+
<span :class="classes(rootPart('Thumbnail'), thumbnailClass(options.ratio))">
|
|
33
|
+
<!-- The placeholder is the picture's stand-in for assistive technology too, so the
|
|
34
|
+
description is on the box that always shows, not on the picture that may not. -->
|
|
35
|
+
<span
|
|
36
|
+
:class="THUMBNAIL_PARTS.placeholder"
|
|
37
|
+
:role="alt ? 'img' : undefined"
|
|
38
|
+
:aria-label="alt || undefined"
|
|
39
|
+
:aria-hidden="alt ? undefined : 'true'"
|
|
40
|
+
>
|
|
41
|
+
<Icon v-if="picture.loaded.value !== true" name="image" size="lg" />
|
|
42
|
+
<img
|
|
43
|
+
v-if="picture.loaded.value !== false && src"
|
|
44
|
+
:ref="(el) => picture.sync(el, src)"
|
|
45
|
+
:src="src"
|
|
46
|
+
alt=""
|
|
47
|
+
aria-hidden="true"
|
|
48
|
+
:class="pictureClass(picture.loaded.value === true)"
|
|
49
|
+
@load="picture.onLoad(src)"
|
|
50
|
+
@error="picture.onError(src)"
|
|
51
|
+
/>
|
|
52
|
+
</span>
|
|
53
|
+
<span v-if="badge" :class="thumbnailBadgeClass(watched)">
|
|
54
|
+
<Badge tone="overlay">{{ badge }}</Badge>
|
|
55
|
+
</span>
|
|
56
|
+
<!-- Decoration: what was watched is for the eye, and a list that needs it said says it in
|
|
57
|
+
words. -->
|
|
58
|
+
<span v-if="watched > 0" aria-hidden="true" :class="THUMBNAIL_PARTS.track">
|
|
59
|
+
<span :class="THUMBNAIL_PARTS.fill" :style="{ width: `${watched * 100}%` }" />
|
|
60
|
+
</span>
|
|
61
|
+
</span>
|
|
62
|
+
</template>
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Ejected from `@xds/vue` 1.2.0 by `xds eject`. This copy is the app's own: change it
|
|
3
|
+
as you need. `xds eject --list` says which ejected files differ from what was copied.
|
|
4
|
+
-->
|
|
5
|
+
<script setup lang="ts">
|
|
6
|
+
// A field for choosing a time of day. Closed, it looks like a Select with a clock: the chosen
|
|
7
|
+
// time on the locale's own clock ("9:30 AM", "09:30"). Pressed, it opens the times from `min` to
|
|
8
|
+
// `max`, `step` minutes apart, under itself, with the chosen one in view; choosing one sets the
|
|
9
|
+
// value as `HH:MM` on a 24-hour clock and closes the list.
|
|
10
|
+
//
|
|
11
|
+
// The field is a button that says it opens a list box, as a Select's does: the arrow keys move,
|
|
12
|
+
// typing the hour jumps to it, and Enter chooses. Without `value` it keeps its own choice, from
|
|
13
|
+
// `defaultValue`.
|
|
14
|
+
import {
|
|
15
|
+
keepListKeys,
|
|
16
|
+
Portal,
|
|
17
|
+
readCssPx,
|
|
18
|
+
space,
|
|
19
|
+
underlayLayerStyle,
|
|
20
|
+
useControllable,
|
|
21
|
+
useFormReset,
|
|
22
|
+
useModalPopover,
|
|
23
|
+
usePresence,
|
|
24
|
+
} from "@xds/vue/base";
|
|
25
|
+
import * as select from "@zag-js/select";
|
|
26
|
+
import { normalizeProps, useMachine } from "@zag-js/vue";
|
|
27
|
+
import { computed, useId, useTemplateRef } from "vue";
|
|
28
|
+
import Icon from "./Icon.vue";
|
|
29
|
+
import type { SelectOption } from "./select.ts";
|
|
30
|
+
import {
|
|
31
|
+
type IsoTime,
|
|
32
|
+
type TimePickerBaseProps,
|
|
33
|
+
timeOptions,
|
|
34
|
+
timePickerIds,
|
|
35
|
+
timePickerLocale,
|
|
36
|
+
} from "./time-picker.ts";
|
|
37
|
+
|
|
38
|
+
export type { IsoTime } from "./time-picker.ts";
|
|
39
|
+
|
|
40
|
+
export type TimePickerProps = TimePickerBaseProps;
|
|
41
|
+
|
|
42
|
+
type KeyHandler = (event: KeyboardEvent) => void;
|
|
43
|
+
|
|
44
|
+
const {
|
|
45
|
+
value: given,
|
|
46
|
+
defaultValue,
|
|
47
|
+
label,
|
|
48
|
+
min,
|
|
49
|
+
max,
|
|
50
|
+
step,
|
|
51
|
+
placeholder,
|
|
52
|
+
description,
|
|
53
|
+
error,
|
|
54
|
+
name,
|
|
55
|
+
disabled = false,
|
|
56
|
+
locale,
|
|
57
|
+
} = defineProps<TimePickerProps>();
|
|
58
|
+
// `v-model:value`: the chosen time, as `HH:MM` on a 24-hour clock.
|
|
59
|
+
const emit = defineEmits<{ "update:value": [value: IsoTime] }>();
|
|
60
|
+
const { value, set, controlled, reset } = useControllable<IsoTime | undefined>(
|
|
61
|
+
"value",
|
|
62
|
+
() => given,
|
|
63
|
+
() => defaultValue,
|
|
64
|
+
(next) => {
|
|
65
|
+
if (next !== undefined) emit("update:value", next);
|
|
66
|
+
},
|
|
67
|
+
);
|
|
68
|
+
const root = useTemplateRef<HTMLDivElement>("root");
|
|
69
|
+
useFormReset(() => root.value, controlled, reset);
|
|
70
|
+
|
|
71
|
+
const id = useId();
|
|
72
|
+
const ids = timePickerIds(id);
|
|
73
|
+
const invalid = computed(() => error !== undefined);
|
|
74
|
+
const options = computed(() =>
|
|
75
|
+
timeOptions({ min, max, step, value: value.value }, timePickerLocale(locale)),
|
|
76
|
+
);
|
|
77
|
+
const collection = computed(() =>
|
|
78
|
+
select.collection<SelectOption<IsoTime>>({
|
|
79
|
+
items: options.value,
|
|
80
|
+
itemToValue: (option) => option.value,
|
|
81
|
+
itemToString: (option) => option.label,
|
|
82
|
+
}),
|
|
83
|
+
);
|
|
84
|
+
const service = useMachine(
|
|
85
|
+
select.machine,
|
|
86
|
+
computed(() => ({
|
|
87
|
+
id,
|
|
88
|
+
collection: collection.value,
|
|
89
|
+
value: value.value === undefined ? [] : [value.value],
|
|
90
|
+
onValueChange: (details: select.ValueChangeDetails<SelectOption<IsoTime>>) => {
|
|
91
|
+
const next = details.value[0];
|
|
92
|
+
if (next !== undefined) set(next);
|
|
93
|
+
},
|
|
94
|
+
disabled,
|
|
95
|
+
invalid: invalid.value,
|
|
96
|
+
positioning: {
|
|
97
|
+
placement: "bottom-start" as const,
|
|
98
|
+
gutter: readCssPx(null, "--xds-space-1", space[1]),
|
|
99
|
+
sameWidth: true,
|
|
100
|
+
overflowPadding: readCssPx(null, "--xds-space-3", space[3]),
|
|
101
|
+
},
|
|
102
|
+
})),
|
|
103
|
+
);
|
|
104
|
+
const api = computed(() => select.connect(service, normalizeProps));
|
|
105
|
+
// As in Select: a handler taken from the machine when the key comes reads whether a search by
|
|
106
|
+
// typing is still under way.
|
|
107
|
+
const current = () => select.connect(service, normalizeProps);
|
|
108
|
+
// A span: the field is a button, which a <label> cannot point at.
|
|
109
|
+
const labelProps = computed(() => {
|
|
110
|
+
const { for: _, ...rest } = api.value.getLabelProps();
|
|
111
|
+
return rest;
|
|
112
|
+
});
|
|
113
|
+
const triggerProps = computed(() => {
|
|
114
|
+
const {
|
|
115
|
+
role: _role,
|
|
116
|
+
"aria-invalid": _invalid,
|
|
117
|
+
"aria-required": _required,
|
|
118
|
+
onKeydown: _onKeydown,
|
|
119
|
+
...rest
|
|
120
|
+
} = api.value.getTriggerProps();
|
|
121
|
+
return {
|
|
122
|
+
...rest,
|
|
123
|
+
onKeydown: (event: KeyboardEvent) => {
|
|
124
|
+
if (!api.value.open && (event.key === "Home" || event.key === "End")) return;
|
|
125
|
+
(current().getTriggerProps().onKeydown as KeyHandler | undefined)?.(event);
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
});
|
|
129
|
+
const positioner = useTemplateRef<HTMLDivElement>("positioner");
|
|
130
|
+
const surface = useTemplateRef<HTMLDivElement>("surface");
|
|
131
|
+
useModalPopover(
|
|
132
|
+
() => api.value.open,
|
|
133
|
+
() => positioner.value,
|
|
134
|
+
);
|
|
135
|
+
const present = usePresence(
|
|
136
|
+
() => api.value.open,
|
|
137
|
+
() => [surface.value],
|
|
138
|
+
);
|
|
139
|
+
const content = computed(() => {
|
|
140
|
+
const { onKeydown: _onKeydown, ...rest } = api.value.getContentProps();
|
|
141
|
+
return {
|
|
142
|
+
...rest,
|
|
143
|
+
onKeydown: (event: KeyboardEvent) => {
|
|
144
|
+
keepListKeys(
|
|
145
|
+
event,
|
|
146
|
+
surface.value,
|
|
147
|
+
".{{prefix}}-time-picker__item:not([data-disabled])",
|
|
148
|
+
(next) => api.value.setHighlightedValue(next),
|
|
149
|
+
);
|
|
150
|
+
(current().getContentProps().onKeydown as KeyHandler | undefined)?.(event);
|
|
151
|
+
},
|
|
152
|
+
};
|
|
153
|
+
});
|
|
154
|
+
</script>
|
|
155
|
+
|
|
156
|
+
<template>
|
|
157
|
+
<div ref="root" v-bind="api.getRootProps()" class="{{prefix}}-time-picker">
|
|
158
|
+
<span v-bind="labelProps" class="{{prefix}}-time-picker__label">{{ label }}</span>
|
|
159
|
+
<button
|
|
160
|
+
v-bind="triggerProps"
|
|
161
|
+
:aria-labelledby="`${ids.value} ${labelProps.id}`"
|
|
162
|
+
:aria-describedby="invalid ? ids.error : description ? ids.description : undefined"
|
|
163
|
+
class="{{prefix}}-time-picker__trigger"
|
|
164
|
+
>
|
|
165
|
+
<span v-bind="api.getValueTextProps()" :id="ids.value" class="{{prefix}}-time-picker__value">
|
|
166
|
+
{{ api.valueAsString || placeholder }}
|
|
167
|
+
</span>
|
|
168
|
+
<Icon name="clock" size="sm" class="text-xds-field-placeholder" />
|
|
169
|
+
</button>
|
|
170
|
+
<div class="{{prefix}}-time-picker__footer">
|
|
171
|
+
<span
|
|
172
|
+
v-if="!invalid && description"
|
|
173
|
+
:id="ids.description"
|
|
174
|
+
class="{{prefix}}-time-picker__description"
|
|
175
|
+
>
|
|
176
|
+
{{ description }}
|
|
177
|
+
</span>
|
|
178
|
+
<span :id="ids.error" class="{{prefix}}-time-picker__error" aria-live="polite">{{
|
|
179
|
+
error
|
|
180
|
+
}}</span>
|
|
181
|
+
</div>
|
|
182
|
+
<!-- What a form submits: the time as HH:MM, where the field shows it on the locale's clock. -->
|
|
183
|
+
<input v-if="name !== undefined" type="hidden" :name="name" :value="value ?? ''" />
|
|
184
|
+
<Portal>
|
|
185
|
+
<div
|
|
186
|
+
v-if="api.open"
|
|
187
|
+
class="{{prefix}}-time-picker__underlay"
|
|
188
|
+
:style="underlayLayerStyle(api.getPositionerProps().style)"
|
|
189
|
+
@mousedown.prevent
|
|
190
|
+
/>
|
|
191
|
+
<div
|
|
192
|
+
ref="positioner"
|
|
193
|
+
v-bind="api.getPositionerProps()"
|
|
194
|
+
class="{{prefix}}-time-picker__positioner"
|
|
195
|
+
>
|
|
196
|
+
<div
|
|
197
|
+
v-bind="content"
|
|
198
|
+
ref="surface"
|
|
199
|
+
:hidden="!present"
|
|
200
|
+
class="{{prefix}}-time-picker__content"
|
|
201
|
+
>
|
|
202
|
+
<div v-bind="api.getListProps()" class="{{prefix}}-time-picker__list">
|
|
203
|
+
<div
|
|
204
|
+
v-for="option in collection.items"
|
|
205
|
+
:key="option.value"
|
|
206
|
+
v-bind="api.getItemProps({ item: option })"
|
|
207
|
+
class="{{prefix}}-time-picker__item"
|
|
208
|
+
>
|
|
209
|
+
<span class="{{prefix}}-time-picker__item-words">
|
|
210
|
+
<span
|
|
211
|
+
v-bind="api.getItemTextProps({ item: option })"
|
|
212
|
+
class="{{prefix}}-time-picker__item-label"
|
|
213
|
+
>
|
|
214
|
+
{{ option.label }}
|
|
215
|
+
</span>
|
|
216
|
+
</span>
|
|
217
|
+
<Icon v-if="api.getItemState({ item: option }).selected" name="check" size="sm" />
|
|
218
|
+
</div>
|
|
219
|
+
</div>
|
|
220
|
+
</div>
|
|
221
|
+
</div>
|
|
222
|
+
</Portal>
|
|
223
|
+
</div>
|
|
224
|
+
</template>
|