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