@xds/vue 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. package/dist/Breadcrumb.js +4 -0
  2. package/dist/Breadcrumb.vue.d.ts +6 -0
  3. package/dist/Breadcrumb.vue_vue_type_script_setup_true_lang.js +47 -0
  4. package/dist/Checkbox.vue_vue_type_script_setup_true_lang.js +11 -3
  5. package/dist/Combobox.js +4 -0
  6. package/dist/Combobox.vue.d.ts +22 -0
  7. package/dist/Combobox.vue_vue_type_script_setup_true_lang.js +140 -0
  8. package/dist/Link.js +4 -0
  9. package/dist/Link.vue.d.ts +27 -0
  10. package/dist/Link.vue_vue_type_script_setup_true_lang.js +62 -0
  11. package/dist/Pagination.js +4 -0
  12. package/dist/Pagination.vue.d.ts +9 -0
  13. package/dist/Pagination.vue_vue_type_script_setup_true_lang.js +74 -0
  14. package/dist/Popover.js +4 -0
  15. package/dist/Popover.vue.d.ts +26 -0
  16. package/dist/Popover.vue_vue_type_script_setup_true_lang.js +81 -0
  17. package/dist/Select.vue.d.ts +3 -1
  18. package/dist/Select.vue_vue_type_script_setup_true_lang.js +41 -17
  19. package/dist/Table.js +4 -0
  20. package/dist/Table.vue.d.ts +10 -0
  21. package/dist/Table.vue_vue_type_script_setup_true_lang.js +61 -0
  22. package/dist/TimePicker.js +4 -0
  23. package/dist/TimePicker.vue.d.ts +10 -0
  24. package/dist/TimePicker.vue_vue_type_script_setup_true_lang.js +168 -0
  25. package/dist/ToastQueue.js +4 -0
  26. package/dist/ToastQueue.vue.d.ts +9 -0
  27. package/dist/ToastQueue.vue_vue_type_script_setup_true_lang.js +42 -0
  28. package/dist/base.d.ts +13 -0
  29. package/dist/base.js +14 -0
  30. package/dist/index.d.ts +13 -4
  31. package/dist/index.js +10 -1
  32. package/dist/preview.d.ts +20 -3
  33. package/dist/preview.js +29 -6
  34. package/eject/files/Accordion.vue +89 -0
  35. package/eject/files/AccordionPanel.vue +47 -0
  36. package/eject/files/Avatar.vue +41 -0
  37. package/eject/files/AvatarStack.vue +46 -0
  38. package/eject/files/Badge.vue +29 -0
  39. package/eject/files/Banner.vue +65 -0
  40. package/eject/files/Breadcrumb.vue +43 -0
  41. package/eject/files/Button.vue +93 -0
  42. package/eject/files/Card.vue +85 -0
  43. package/eject/files/Checkbox.vue +104 -0
  44. package/eject/files/Chip.vue +32 -0
  45. package/eject/files/ChipBar.vue +25 -0
  46. package/eject/files/Combobox.vue +175 -0
  47. package/eject/files/CountBadge.vue +45 -0
  48. package/eject/files/DatePicker.vue +223 -0
  49. package/eject/files/DateRangePicker.vue +317 -0
  50. package/eject/files/Dialog.vue +105 -0
  51. package/eject/files/Divider.vue +15 -0
  52. package/eject/files/EmptyState.vue +28 -0
  53. package/eject/files/Icon.vue +34 -0
  54. package/eject/files/IconButton.vue +71 -0
  55. package/eject/files/Link.vue +48 -0
  56. package/eject/files/ListRow.vue +33 -0
  57. package/eject/files/MediaCard.vue +109 -0
  58. package/eject/files/Menu.vue +181 -0
  59. package/eject/files/Pagination.vue +88 -0
  60. package/eject/files/PlaceRow.vue +54 -0
  61. package/eject/files/Popover.vue +119 -0
  62. package/eject/files/ProgressBar.vue +34 -0
  63. package/eject/files/RadioGroup.vue +126 -0
  64. package/eject/files/SearchField.vue +129 -0
  65. package/eject/files/SectionHeader.vue +37 -0
  66. package/eject/files/SegmentedControl.vue +81 -0
  67. package/eject/files/Select.vue +269 -0
  68. package/eject/files/Sidebar.vue +101 -0
  69. package/eject/files/SidebarRailButton.vue +31 -0
  70. package/eject/files/Skeleton.vue +27 -0
  71. package/eject/files/Slider.vue +126 -0
  72. package/eject/files/Spinner.vue +36 -0
  73. package/eject/files/Switch.vue +88 -0
  74. package/eject/files/Table.vue +77 -0
  75. package/eject/files/Tabs.vue +72 -0
  76. package/eject/files/Text.vue +22 -0
  77. package/eject/files/TextField.vue +190 -0
  78. package/eject/files/Thumbnail.vue +62 -0
  79. package/eject/files/TimePicker.vue +224 -0
  80. package/eject/files/Toast.vue +83 -0
  81. package/eject/files/ToastQueue.vue +54 -0
  82. package/eject/files/Tooltip.vue +28 -0
  83. package/eject/files/TooltipOverlay.vue +86 -0
  84. package/eject/files/accordion.css +89 -0
  85. package/eject/files/accordion.ts +67 -0
  86. package/eject/files/avatar-stack.ts +57 -0
  87. package/eject/files/avatar.ts +42 -0
  88. package/eject/files/badge.ts +30 -0
  89. package/eject/files/banner.ts +71 -0
  90. package/eject/files/base.css +38 -0
  91. package/eject/files/breadcrumb.css +51 -0
  92. package/eject/files/breadcrumb.ts +42 -0
  93. package/eject/files/button.css +241 -0
  94. package/eject/files/button.ts +106 -0
  95. package/eject/files/card.ts +58 -0
  96. package/eject/files/checkbox.ts +52 -0
  97. package/eject/files/chip-bar.ts +16 -0
  98. package/eject/files/chip.ts +35 -0
  99. package/eject/files/combobox.css +269 -0
  100. package/eject/files/combobox.ts +85 -0
  101. package/eject/files/count-badge.ts +32 -0
  102. package/eject/files/date-picker.css +375 -0
  103. package/eject/files/date-picker.ts +280 -0
  104. package/eject/files/date-range-picker.ts +338 -0
  105. package/eject/files/dialog.css +139 -0
  106. package/eject/files/dialog.ts +15 -0
  107. package/eject/files/divider.ts +5 -0
  108. package/eject/files/empty-state.ts +22 -0
  109. package/eject/files/icon.ts +36 -0
  110. package/eject/files/link.css +64 -0
  111. package/eject/files/link.ts +63 -0
  112. package/eject/files/list-row.ts +66 -0
  113. package/eject/files/media-card.ts +66 -0
  114. package/eject/files/menu.css +192 -0
  115. package/eject/files/menu.ts +84 -0
  116. package/eject/files/overlay.css +40 -0
  117. package/eject/files/pagination.css +106 -0
  118. package/eject/files/pagination.ts +68 -0
  119. package/eject/files/parts.ts +17 -0
  120. package/eject/files/popover.css +101 -0
  121. package/eject/files/popover.ts +37 -0
  122. package/eject/files/progress-bar.ts +26 -0
  123. package/eject/files/radio-group.css +184 -0
  124. package/eject/files/radio-group.ts +30 -0
  125. package/eject/files/section-header.ts +32 -0
  126. package/eject/files/segmented-control.ts +33 -0
  127. package/eject/files/select.css +347 -0
  128. package/eject/files/select.ts +77 -0
  129. package/eject/files/sidebar.ts +75 -0
  130. package/eject/files/skeleton.ts +51 -0
  131. package/eject/files/slider.css +160 -0
  132. package/eject/files/slider.ts +80 -0
  133. package/eject/files/spinner.ts +22 -0
  134. package/eject/files/switch.ts +45 -0
  135. package/eject/files/table.css +107 -0
  136. package/eject/files/table.ts +84 -0
  137. package/eject/files/tabs.css +120 -0
  138. package/eject/files/tabs.ts +37 -0
  139. package/eject/files/text-field.css +225 -0
  140. package/eject/files/text-field.ts +64 -0
  141. package/eject/files/text.ts +38 -0
  142. package/eject/files/thumbnail.ts +51 -0
  143. package/eject/files/time-picker.ts +113 -0
  144. package/eject/files/toast-queue.ts +64 -0
  145. package/eject/files/toast.ts +31 -0
  146. package/eject/files/tooltip.css +111 -0
  147. package/eject/files/tooltip.ts +21 -0
  148. package/eject/manifest.json +1122 -0
  149. package/package.json +11 -4
  150. package/styles.css +1066 -168
  151. package/tailwind.css +1295 -218
@@ -0,0 +1,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>
@@ -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>