@aleph-alpha/ui-library 5.2.0 → 5.3.1
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/system/components/UiTooltip/UiTooltip.vue.d.ts +1 -0
- package/dist/system/components/UiTooltip/types.d.ts +8 -0
- package/dist/system/components/core/tooltip/TooltipContent.vue.d.ts +2 -0
- package/dist/system/index.d.ts +1 -0
- package/dist/system/lib/useAnchorFloat.d.ts +143 -0
- package/dist/system/lib.js +18787 -18280
- package/dist/system/patterns/UiFloatActions/UiFloatActionItems.vue.d.ts +35 -0
- package/dist/system/patterns/UiFloatActions/UiFloatActions.vue.d.ts +45 -0
- package/dist/system/patterns/UiFloatActions/floatActionItemContext.d.ts +16 -0
- package/dist/system/patterns/UiFloatActions/index.d.ts +3 -0
- package/dist/system/patterns/UiFloatActions/types.d.ts +127 -0
- package/dist/system/patterns/index.d.ts +1 -0
- package/docs/public-docs/quick-start.md +43 -0
- package/package.json +1 -1
- package/src/components/UiAccordion/UiAccordion.stories.ts +2 -2
- package/src/components/UiAutocomplete/UiAutocomplete.stories.ts +2 -2
- package/src/components/UiAutocomplete/UiAutocomplete.vue +3 -3
- package/src/components/UiBadge/UiBadge.stories.ts +9 -9
- package/src/components/UiDropdownMenu/UiDropdownMenu.stories.ts +4 -4
- package/src/components/UiField/UiField.stories.ts +6 -6
- package/src/components/UiInput/UiInput.vue +1 -1
- package/src/components/UiKbd/UiKbd.stories.ts +3 -3
- package/src/components/UiKbd/UiKbd.vue +1 -1
- package/src/components/UiNavigationMenu/UiNavigationMenu.stories.ts +28 -28
- package/src/components/UiPopover/UiPopover.stories.ts +20 -20
- package/src/components/UiRadioGroup/UiRadioGroup.stories.ts +24 -24
- package/src/components/UiResizable/UiResizable.stories.ts +14 -14
- package/src/components/UiSelect/UiSelect.stories.ts +1 -1
- package/src/components/UiSheet/UiSheet.stories.ts +14 -14
- package/src/components/UiSlider/UiSlider.stories.ts +8 -8
- package/src/components/UiSpinner/UiSpinner.stories.ts +8 -8
- package/src/components/UiSwitch/UiSwitch.stories.ts +4 -4
- package/src/components/UiTabs/UiTabs.stories.ts +46 -46
- package/src/components/UiToggleGroup/UiToggleGroup.stories.ts +14 -14
- package/src/components/UiTooltip/UiTooltip.vue +2 -0
- package/src/components/UiTooltip/types.ts +9 -0
- package/src/components/core/accordion/AccordionContent.vue +1 -1
- package/src/components/core/accordion/AccordionTrigger.vue +1 -1
- package/src/components/core/alert/AlertDescription.vue +1 -1
- package/src/components/core/alert/index.ts +1 -1
- package/src/components/core/calendar/Calendar.vue +4 -4
- package/src/components/core/calendar/CalendarCell.vue +1 -1
- package/src/components/core/drawer/DrawerDescription.vue +1 -1
- package/src/components/core/dropdown-menu/DropdownMenuCheckboxItem.vue +1 -1
- package/src/components/core/dropdown-menu/DropdownMenuItem.vue +1 -1
- package/src/components/core/dropdown-menu/DropdownMenuLabel.vue +1 -3
- package/src/components/core/dropdown-menu/DropdownMenuRadioItem.vue +1 -1
- package/src/components/core/dropdown-menu/DropdownMenuShortcut.vue +4 -1
- package/src/components/core/dropdown-menu/DropdownMenuSubTrigger.vue +1 -1
- package/src/components/core/field/FieldDescription.vue +1 -1
- package/src/components/core/field/FieldLegend.vue +2 -2
- package/src/components/core/field/FieldSeparator.vue +1 -1
- package/src/components/core/input/Input.vue +1 -1
- package/src/components/core/item/index.ts +1 -1
- package/src/components/core/label/Label.vue +1 -1
- package/src/components/core/listbox/ListboxFilter.vue +1 -1
- package/src/components/core/listbox/ListboxGroupLabel.vue +1 -1
- package/src/components/core/listbox/ListboxItem.vue +1 -1
- package/src/components/core/native-select/NativeSelect.vue +1 -1
- package/src/components/core/navigation-menu/NavigationMenuLink.vue +1 -1
- package/src/components/core/navigation-menu/index.ts +1 -1
- package/src/components/core/range-calendar/RangeCalendarCell.vue +1 -1
- package/src/components/core/select/SelectItem.vue +1 -1
- package/src/components/core/select/SelectLabel.vue +3 -1
- package/src/components/core/select/SelectTrigger.vue +1 -1
- package/src/components/core/sidebar/SidebarGroupContent.vue +1 -1
- package/src/components/core/sidebar/SidebarGroupLabel.vue +1 -1
- package/src/components/core/sidebar/SidebarMenuBadge.vue +1 -1
- package/src/components/core/sidebar/SidebarMenuSubButton.vue +2 -2
- package/src/components/core/sidebar/index.ts +4 -4
- package/src/components/core/slider/Slider.vue +3 -3
- package/src/components/core/stepper/StepperDescription.vue +1 -1
- package/src/components/core/table/Table.vue +1 -1
- package/src/components/core/table/TableEmpty.vue +1 -1
- package/src/components/core/tabs/TabsTrigger.vue +1 -1
- package/src/components/core/tags-input/TagsInput.vue +1 -1
- package/src/components/core/tags-input/TagsInputItem.vue +1 -1
- package/src/components/core/textarea/Textarea.vue +1 -1
- package/src/components/core/toggle/index.ts +1 -1
- package/src/components/core/toggle-group/index.ts +1 -1
- package/src/components/core/tooltip/TooltipContent.vue +10 -4
- package/src/index.ts +1 -0
- package/src/lib/useAnchorFloat.test.ts +166 -0
- package/src/lib/useAnchorFloat.ts +437 -0
- package/src/lib/useDrag.stories.ts +12 -12
- package/src/patterns/UiDatePicker/UiDatePicker.stories.ts +8 -8
- package/src/patterns/UiFloatActions/UiFloatActionItems.vue +327 -0
- package/src/patterns/UiFloatActions/UiFloatActions.stories.ts +900 -0
- package/src/patterns/UiFloatActions/UiFloatActions.vue +224 -0
- package/src/patterns/UiFloatActions/__tests__/UiFloatActionItems.test.ts +104 -0
- package/src/patterns/UiFloatActions/__tests__/UiFloatActions.a11y.test.ts +152 -0
- package/src/patterns/UiFloatActions/__tests__/UiFloatActions.test.ts +86 -0
- package/src/patterns/UiFloatActions/floatActionItemContext.ts +20 -0
- package/src/patterns/UiFloatActions/index.ts +3 -0
- package/src/patterns/UiFloatActions/types.ts +155 -0
- package/src/patterns/UiSidebar/UiSidebarGroupLabel.stories.ts +2 -2
- package/src/patterns/UiSidebar/UiSidebarMenuButton.stories.ts +3 -3
- package/src/patterns/index.ts +1 -0
|
@@ -130,7 +130,7 @@ function onDragStart(event: DragEvent, itemId: string) {
|
|
|
130
130
|
|
|
131
131
|
<template>
|
|
132
132
|
<div class="max-w-md space-y-3">
|
|
133
|
-
<p class="text-muted-foreground
|
|
133
|
+
<p class="text-muted-foreground body-14-regular">
|
|
134
134
|
Drag an item over another item. The helper keeps the native drag data,
|
|
135
135
|
creates an empty bordered ghost, and reorders on drop.
|
|
136
136
|
</p>
|
|
@@ -140,7 +140,7 @@ function onDragStart(event: DragEvent, itemId: string) {
|
|
|
140
140
|
:key="item.id"
|
|
141
141
|
draggable="true"
|
|
142
142
|
:class="[
|
|
143
|
-
'rounded-md border border-border-surface-default bg-background-surface-primary px-3 py-2
|
|
143
|
+
'rounded-md border border-border-surface-default bg-background-surface-primary px-3 py-2 body-14-regular transition-[border-color,opacity,transform]',
|
|
144
144
|
draggedItemId === item.id ? 'opacity-50' : undefined,
|
|
145
145
|
activeItemId === item.id ? 'border-border-surface-focus-ring' : undefined,
|
|
146
146
|
]"
|
|
@@ -152,12 +152,12 @@ function onDragStart(event: DragEvent, itemId: string) {
|
|
|
152
152
|
{{ item.label }}
|
|
153
153
|
</div>
|
|
154
154
|
</div>
|
|
155
|
-
<div class="text-muted-foreground grid gap-1
|
|
155
|
+
<div class="text-muted-foreground grid gap-1 label-12-regular">
|
|
156
156
|
<span>Dragged item: {{ draggedItem?.label ?? 'none' }}</span>
|
|
157
157
|
<span>Active item: {{ activeItem?.label ?? 'none' }}</span>
|
|
158
158
|
<span>Original order: {{ originalItems?.map((item) => item.id).join(' -> ') ?? 'none' }}</span>
|
|
159
159
|
</div>
|
|
160
|
-
<pre class="rounded-md bg-background-surface-muted p-3
|
|
160
|
+
<pre class="rounded-md bg-background-surface-muted p-3 label-12-regular">{{ items.map((item) => item.id).join(' -> ') }}</pre>
|
|
161
161
|
</div>
|
|
162
162
|
</template>`,
|
|
163
163
|
},
|
|
@@ -201,7 +201,7 @@ function onDragStart(event: DragEvent, itemId: string) {
|
|
|
201
201
|
},
|
|
202
202
|
template: `
|
|
203
203
|
<div class="max-w-md space-y-3">
|
|
204
|
-
<p class="text-muted-foreground
|
|
204
|
+
<p class="text-muted-foreground body-14-regular">
|
|
205
205
|
Drag an item over another item. The helper keeps the native drag data,
|
|
206
206
|
creates an empty bordered ghost, and reorders on drop.
|
|
207
207
|
</p>
|
|
@@ -211,7 +211,7 @@ function onDragStart(event: DragEvent, itemId: string) {
|
|
|
211
211
|
:key="item.id"
|
|
212
212
|
draggable="true"
|
|
213
213
|
:class="[
|
|
214
|
-
'rounded-md border border-border-surface-default bg-background-surface-primary px-3 py-2
|
|
214
|
+
'rounded-md border border-border-surface-default bg-background-surface-primary px-3 py-2 body-14-regular transition-[border-color,opacity,transform]',
|
|
215
215
|
draggedItemId === item.id ? 'opacity-50' : undefined,
|
|
216
216
|
activeItemId === item.id ? 'border-border-surface-focus-ring' : undefined,
|
|
217
217
|
]"
|
|
@@ -223,12 +223,12 @@ function onDragStart(event: DragEvent, itemId: string) {
|
|
|
223
223
|
{{ item.label }}
|
|
224
224
|
</div>
|
|
225
225
|
</div>
|
|
226
|
-
<div class="text-muted-foreground grid gap-1
|
|
226
|
+
<div class="text-muted-foreground grid gap-1 label-12-regular">
|
|
227
227
|
<span>Dragged item: {{ draggedItem?.label ?? 'none' }}</span>
|
|
228
228
|
<span>Active item: {{ activeItem?.label ?? 'none' }}</span>
|
|
229
229
|
<span>Original order: {{ originalItems?.map((item) => item.id).join(' -> ') ?? 'none' }}</span>
|
|
230
230
|
</div>
|
|
231
|
-
<pre class="rounded-md bg-background-surface-muted p-3
|
|
231
|
+
<pre class="rounded-md bg-background-surface-muted p-3 label-12-regular">{{ items.map((item) => item.id).join(' -> ') }}</pre>
|
|
232
232
|
</div>
|
|
233
233
|
`,
|
|
234
234
|
}),
|
|
@@ -239,7 +239,7 @@ export const VerticalCards: Story = {
|
|
|
239
239
|
setup: setupCardDragStory,
|
|
240
240
|
template: `
|
|
241
241
|
<div class="max-w-lg space-y-3">
|
|
242
|
-
<p class="text-muted-foreground
|
|
242
|
+
<p class="text-muted-foreground body-14-regular">
|
|
243
243
|
Vertical card sorting with model-backed drop handling.
|
|
244
244
|
</p>
|
|
245
245
|
<div class="space-y-3">
|
|
@@ -258,7 +258,7 @@ export const VerticalCards: Story = {
|
|
|
258
258
|
@dragend="resetDragState"
|
|
259
259
|
>
|
|
260
260
|
<h3 class="label-14-medium text-content-on-surface-primary">{{ item.label }}</h3>
|
|
261
|
-
<p class="text-muted-foreground mt-1
|
|
261
|
+
<p class="text-muted-foreground mt-1 body-14-regular">{{ item.description }}</p>
|
|
262
262
|
</article>
|
|
263
263
|
</div>
|
|
264
264
|
</div>
|
|
@@ -271,7 +271,7 @@ export const GridCards: Story = {
|
|
|
271
271
|
setup: setupCardDragStory,
|
|
272
272
|
template: `
|
|
273
273
|
<div class="max-w-3xl space-y-3">
|
|
274
|
-
<p class="text-muted-foreground
|
|
274
|
+
<p class="text-muted-foreground body-14-regular">
|
|
275
275
|
Grid card sorting uses the same active-item model and default drop reorder.
|
|
276
276
|
</p>
|
|
277
277
|
<div class="grid gap-3 sm:grid-cols-2">
|
|
@@ -290,7 +290,7 @@ export const GridCards: Story = {
|
|
|
290
290
|
@dragend="resetDragState"
|
|
291
291
|
>
|
|
292
292
|
<h3 class="label-14-medium text-content-on-surface-primary">{{ item.label }}</h3>
|
|
293
|
-
<p class="text-muted-foreground mt-2
|
|
293
|
+
<p class="text-muted-foreground mt-2 body-14-regular">{{ item.description }}</p>
|
|
294
294
|
</article>
|
|
295
295
|
</div>
|
|
296
296
|
</div>
|
|
@@ -596,14 +596,14 @@ const appointmentDate = ref<DateValue>()
|
|
|
596
596
|
|
|
597
597
|
<template>
|
|
598
598
|
<div class="gap-y-2">
|
|
599
|
-
<label class="
|
|
599
|
+
<label class="label-14-medium">Appointment Date</label>
|
|
600
600
|
<UiDatePicker
|
|
601
601
|
v-model="appointmentDate"
|
|
602
602
|
placeholder="Select appointment date"
|
|
603
603
|
class="w-full"
|
|
604
604
|
aria-label="Select appointment date"
|
|
605
605
|
/>
|
|
606
|
-
<p class="
|
|
606
|
+
<p class="label-12-regular text-muted-foreground">
|
|
607
607
|
Choose a date for your appointment.
|
|
608
608
|
</p>
|
|
609
609
|
</div>
|
|
@@ -621,7 +621,7 @@ export const FormExample: Story = {
|
|
|
621
621
|
return { appointmentDate, args };
|
|
622
622
|
},
|
|
623
623
|
template: `<div class="gap-y-2">
|
|
624
|
-
<label class="
|
|
624
|
+
<label class="label-14-medium">Appointment Date</label>
|
|
625
625
|
<UiDatePicker
|
|
626
626
|
v-model="appointmentDate"
|
|
627
627
|
placeholder="Select appointment date"
|
|
@@ -630,7 +630,7 @@ export const FormExample: Story = {
|
|
|
630
630
|
:disabled="args.disabled"
|
|
631
631
|
:locale="args.locale"
|
|
632
632
|
/>
|
|
633
|
-
<p class="
|
|
633
|
+
<p class="label-12-regular text-muted-foreground">
|
|
634
634
|
Choose a date for your appointment.
|
|
635
635
|
</p>
|
|
636
636
|
</div>`,
|
|
@@ -863,7 +863,7 @@ const travelDates = ref<DateRange>()
|
|
|
863
863
|
|
|
864
864
|
<template>
|
|
865
865
|
<div class="gap-y-2 max-w-sm">
|
|
866
|
-
<label for="travel-dates" class="
|
|
866
|
+
<label for="travel-dates" class="label-14-medium">
|
|
867
867
|
Travel Dates
|
|
868
868
|
</label>
|
|
869
869
|
<UiDatePicker
|
|
@@ -874,7 +874,7 @@ const travelDates = ref<DateRange>()
|
|
|
874
874
|
placeholder="Select dates"
|
|
875
875
|
aria-label="Select travel dates"
|
|
876
876
|
/>
|
|
877
|
-
<p class="
|
|
877
|
+
<p class="label-12-regular text-muted-foreground">
|
|
878
878
|
Choose your check-in and check-out dates.
|
|
879
879
|
</p>
|
|
880
880
|
</div>
|
|
@@ -897,7 +897,7 @@ export const RangeFormExample: Story = {
|
|
|
897
897
|
return { travelDates, args };
|
|
898
898
|
},
|
|
899
899
|
template: `<div class="gap-y-2 max-w-sm">
|
|
900
|
-
<label for="travel-dates" class="
|
|
900
|
+
<label for="travel-dates" class="label-14-medium">
|
|
901
901
|
Travel Dates
|
|
902
902
|
</label>
|
|
903
903
|
<UiDatePicker
|
|
@@ -910,7 +910,7 @@ export const RangeFormExample: Story = {
|
|
|
910
910
|
:disabled="args.disabled"
|
|
911
911
|
:locale="args.locale"
|
|
912
912
|
/>
|
|
913
|
-
<p class="
|
|
913
|
+
<p class="label-12-regular text-muted-foreground">
|
|
914
914
|
Choose your check-in and check-out dates.
|
|
915
915
|
</p>
|
|
916
916
|
</div>`,
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* UiFloatActionItems renders a pill-shaped floating toolbar and its action items.
|
|
4
|
+
*
|
|
5
|
+
* Use the root (default `type="toolbar"`) as the container and nest child items
|
|
6
|
+
* for buttons, inputs, text labels, groups, and separators. Follows the WAI-ARIA
|
|
7
|
+
* APG toolbar pattern with roving arrow-key navigation.
|
|
8
|
+
*
|
|
9
|
+
* @component UiFloatActionItems
|
|
10
|
+
* @property {'toolbar' | 'button' | 'input' | 'text' | 'group' | 'separator'} [type='toolbar'] -
|
|
11
|
+
* Item role. Omit or use `toolbar` for the root pill container.
|
|
12
|
+
* @property {string} [ariaLabel] -
|
|
13
|
+
* Accessible label. **Required** for `toolbar`, `button`, and `input` types.
|
|
14
|
+
* @property {'horizontal' | 'vertical'} [orientation='horizontal'] -
|
|
15
|
+
* Arrow-key navigation direction for toolbar items.
|
|
16
|
+
* @property {boolean} [disabled=false] -
|
|
17
|
+
* Disables interaction for `button` and `input` items.
|
|
18
|
+
* @property {string} [placeholder] -
|
|
19
|
+
* Placeholder text for `input` items.
|
|
20
|
+
* @slot default
|
|
21
|
+
* Icon or label content for `button`, `text`, and `toolbar` items.
|
|
22
|
+
* @example Flat action bar
|
|
23
|
+
* ```vue
|
|
24
|
+
* <UiFloatActionItems aria-label="Text actions">
|
|
25
|
+
* <UiFloatActionItems type="button" aria-label="Edit">
|
|
26
|
+
* <UiIcon name="edit" size="s" />
|
|
27
|
+
* </UiFloatActionItems>
|
|
28
|
+
* <UiFloatActionItems type="button" aria-label="Copy">
|
|
29
|
+
* <UiIcon name="copy" size="s" />
|
|
30
|
+
* </UiFloatActionItems>
|
|
31
|
+
* </UiFloatActionItems>
|
|
32
|
+
* ```
|
|
33
|
+
* @example Pagination group
|
|
34
|
+
* ```vue
|
|
35
|
+
* <UiFloatActionItems aria-label="Pagination">
|
|
36
|
+
* <UiFloatActionItems type="group">
|
|
37
|
+
* <UiFloatActionItems type="button" aria-label="Previous"><</UiFloatActionItems>
|
|
38
|
+
* <UiFloatActionItems type="text">2/2</UiFloatActionItems>
|
|
39
|
+
* <UiFloatActionItems type="button" aria-label="Next">></UiFloatActionItems>
|
|
40
|
+
* </UiFloatActionItems>
|
|
41
|
+
* </UiFloatActionItems>
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
import { cn, omitClass } from '@/lib/utils';
|
|
45
|
+
import {
|
|
46
|
+
computed,
|
|
47
|
+
inject,
|
|
48
|
+
onBeforeUnmount,
|
|
49
|
+
provide,
|
|
50
|
+
ref,
|
|
51
|
+
useAttrs,
|
|
52
|
+
watch,
|
|
53
|
+
} from 'vue';
|
|
54
|
+
import {
|
|
55
|
+
FLOAT_ACTION_ITEM_SELECTOR,
|
|
56
|
+
FLOAT_ACTION_ITEM_CONTEXT,
|
|
57
|
+
type FloatActionItemContext,
|
|
58
|
+
} from './floatActionItemContext';
|
|
59
|
+
import type { UiFloatActionItemsEmits, UiFloatActionItemsProps } from './types';
|
|
60
|
+
|
|
61
|
+
defineOptions({
|
|
62
|
+
name: 'UiFloatActionItems',
|
|
63
|
+
inheritAttrs: false,
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
const props = withDefaults(defineProps<UiFloatActionItemsProps>(), {
|
|
67
|
+
type: 'toolbar',
|
|
68
|
+
disabled: false,
|
|
69
|
+
orientation: 'horizontal',
|
|
70
|
+
ariaLabel: undefined,
|
|
71
|
+
placeholder: undefined,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const emit = defineEmits<UiFloatActionItemsEmits>();
|
|
75
|
+
const attrs = useAttrs();
|
|
76
|
+
|
|
77
|
+
const itemId = Symbol('UiFloatActionItems');
|
|
78
|
+
const itemRef = ref<HTMLElement | null>(null);
|
|
79
|
+
const parentContext = inject<FloatActionItemContext | null>(
|
|
80
|
+
FLOAT_ACTION_ITEM_CONTEXT,
|
|
81
|
+
null,
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
const isToolbar = computed(
|
|
85
|
+
() => props.type === 'toolbar' || props.type === undefined,
|
|
86
|
+
);
|
|
87
|
+
const isButton = computed(() => props.type === 'button');
|
|
88
|
+
const isInput = computed(() => props.type === 'input');
|
|
89
|
+
const isText = computed(() => props.type === 'text');
|
|
90
|
+
const isGroup = computed(() => props.type === 'group');
|
|
91
|
+
const isSeparator = computed(() => props.type === 'separator');
|
|
92
|
+
|
|
93
|
+
const activeIndex = ref(0);
|
|
94
|
+
const registeredItems = ref<Array<{ id: symbol }>>([]);
|
|
95
|
+
|
|
96
|
+
const toolbarOrientation = computed(() => props.orientation ?? 'horizontal');
|
|
97
|
+
|
|
98
|
+
const toolbarContext: FloatActionItemContext = {
|
|
99
|
+
registerItem(id) {
|
|
100
|
+
registeredItems.value.push({ id });
|
|
101
|
+
},
|
|
102
|
+
unregisterItem(id) {
|
|
103
|
+
registeredItems.value = registeredItems.value.filter(
|
|
104
|
+
(item) => item.id !== id,
|
|
105
|
+
);
|
|
106
|
+
},
|
|
107
|
+
onItemFocus(id) {
|
|
108
|
+
const index = registeredItems.value.findIndex((item) => item.id === id);
|
|
109
|
+
if (index !== -1) activeIndex.value = index;
|
|
110
|
+
},
|
|
111
|
+
getTabIndex(id) {
|
|
112
|
+
const index = registeredItems.value.findIndex((item) => item.id === id);
|
|
113
|
+
if (index === -1) return -1;
|
|
114
|
+
return index === activeIndex.value ? 0 : -1;
|
|
115
|
+
},
|
|
116
|
+
orientation: toolbarOrientation,
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
if (isToolbar.value) {
|
|
120
|
+
provide(FLOAT_ACTION_ITEM_CONTEXT, toolbarContext);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
watch(
|
|
124
|
+
itemRef,
|
|
125
|
+
(element) => {
|
|
126
|
+
if (!parentContext || (!isButton.value && !isInput.value)) return;
|
|
127
|
+
if (element) {
|
|
128
|
+
parentContext.registerItem(itemId);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
parentContext.unregisterItem(itemId);
|
|
132
|
+
},
|
|
133
|
+
{ immediate: true },
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
onBeforeUnmount(() => {
|
|
137
|
+
parentContext?.unregisterItem(itemId);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
function focusableItems(): HTMLElement[] {
|
|
141
|
+
const root = itemRef.value;
|
|
142
|
+
if (!root) return [];
|
|
143
|
+
return Array.from(
|
|
144
|
+
root.querySelectorAll<HTMLElement>(FLOAT_ACTION_ITEM_SELECTOR),
|
|
145
|
+
).filter((element) => !element.hasAttribute('disabled'));
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function focusItemAt(index: number) {
|
|
149
|
+
const items = focusableItems();
|
|
150
|
+
if (items.length === 0) return;
|
|
151
|
+
|
|
152
|
+
const nextIndex = (index + items.length) % items.length;
|
|
153
|
+
activeIndex.value = nextIndex;
|
|
154
|
+
items[nextIndex]?.focus();
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function onToolbarKeydown(event: KeyboardEvent) {
|
|
158
|
+
const orientation = toolbarOrientation.value;
|
|
159
|
+
const items = focusableItems();
|
|
160
|
+
if (items.length === 0) return;
|
|
161
|
+
|
|
162
|
+
const currentIndex = items.findIndex(
|
|
163
|
+
(element) => element === document.activeElement,
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
switch (event.key) {
|
|
167
|
+
case 'ArrowRight':
|
|
168
|
+
if (orientation === 'horizontal') {
|
|
169
|
+
event.preventDefault();
|
|
170
|
+
focusItemAt(currentIndex + 1);
|
|
171
|
+
}
|
|
172
|
+
break;
|
|
173
|
+
case 'ArrowLeft':
|
|
174
|
+
if (orientation === 'horizontal') {
|
|
175
|
+
event.preventDefault();
|
|
176
|
+
focusItemAt(currentIndex - 1);
|
|
177
|
+
}
|
|
178
|
+
break;
|
|
179
|
+
case 'ArrowDown':
|
|
180
|
+
if (orientation === 'vertical') {
|
|
181
|
+
event.preventDefault();
|
|
182
|
+
focusItemAt(currentIndex + 1);
|
|
183
|
+
}
|
|
184
|
+
break;
|
|
185
|
+
case 'ArrowUp':
|
|
186
|
+
if (orientation === 'vertical') {
|
|
187
|
+
event.preventDefault();
|
|
188
|
+
focusItemAt(currentIndex - 1);
|
|
189
|
+
}
|
|
190
|
+
break;
|
|
191
|
+
case 'Home':
|
|
192
|
+
event.preventDefault();
|
|
193
|
+
focusItemAt(0);
|
|
194
|
+
break;
|
|
195
|
+
case 'End':
|
|
196
|
+
event.preventDefault();
|
|
197
|
+
focusItemAt(items.length - 1);
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function onItemFocus() {
|
|
203
|
+
parentContext?.onItemFocus(itemId);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function onButtonClick(event: MouseEvent) {
|
|
207
|
+
if (props.disabled) {
|
|
208
|
+
event.preventDefault();
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
emit('click', event);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const tabIndex = computed(() =>
|
|
215
|
+
parentContext ? parentContext.getTabIndex(itemId) : undefined,
|
|
216
|
+
);
|
|
217
|
+
|
|
218
|
+
// Forward inherited attributes (minus `class`, which is merged via `cn` into the
|
|
219
|
+
// element class) so a `button` item can compose with wrappers like UiTooltip that
|
|
220
|
+
// rely on `as-child` to pass event handlers and ARIA attributes to the trigger.
|
|
221
|
+
const forwardedAttrs = computed(() => omitClass(attrs));
|
|
222
|
+
|
|
223
|
+
const toolbarClass = computed(() =>
|
|
224
|
+
cn(
|
|
225
|
+
'inline-flex items-center gap-0.5 rounded-full border border-border-surface-default bg-background-surface-floating p-1 shadow-xs',
|
|
226
|
+
attrs.class ?? '',
|
|
227
|
+
),
|
|
228
|
+
);
|
|
229
|
+
|
|
230
|
+
const buttonClass = computed(() =>
|
|
231
|
+
cn(
|
|
232
|
+
'inline-flex h-8 w-8 shrink-0 cursor-pointer items-center justify-center rounded-full border-0 bg-transparent text-content-on-surface-primary transition-colors hover:bg-background-surface-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-border-surface-focus-ring disabled:cursor-not-allowed disabled:opacity-50',
|
|
233
|
+
attrs.class ?? '',
|
|
234
|
+
),
|
|
235
|
+
);
|
|
236
|
+
|
|
237
|
+
const inputClass = computed(() =>
|
|
238
|
+
cn(
|
|
239
|
+
'h-8 min-w-16 rounded-full border-0 bg-background-input-default px-3 label-14-regular text-content-on-surface-primary outline-none focus-visible:ring-2 focus-visible:ring-border-surface-focus-ring',
|
|
240
|
+
attrs.class ?? '',
|
|
241
|
+
),
|
|
242
|
+
);
|
|
243
|
+
|
|
244
|
+
const textClass = computed(() =>
|
|
245
|
+
cn(
|
|
246
|
+
'inline-flex h-8 min-w-8 items-center justify-center px-1 label-14-regular text-content-on-surface-primary',
|
|
247
|
+
attrs.class ?? '',
|
|
248
|
+
),
|
|
249
|
+
);
|
|
250
|
+
|
|
251
|
+
const groupClass = computed(() =>
|
|
252
|
+
cn('inline-flex items-center gap-0.5', attrs.class ?? ''),
|
|
253
|
+
);
|
|
254
|
+
|
|
255
|
+
const separatorClass = computed(() =>
|
|
256
|
+
cn('mx-0.5 h-5 w-px shrink-0 bg-border-surface-default', attrs.class ?? ''),
|
|
257
|
+
);
|
|
258
|
+
</script>
|
|
259
|
+
|
|
260
|
+
<template>
|
|
261
|
+
<!-- Follows the WAI-ARIA APG toolbar pattern: role="toolbar" with roving
|
|
262
|
+
arrow-key navigation handled via keydown. The plugin's interactive-role
|
|
263
|
+
allowlist omits "toolbar", so the handler is flagged despite being correct. -->
|
|
264
|
+
<!-- eslint-disable-next-line vuejs-accessibility/no-static-element-interactions -->
|
|
265
|
+
<div
|
|
266
|
+
v-if="isToolbar"
|
|
267
|
+
ref="itemRef"
|
|
268
|
+
role="toolbar"
|
|
269
|
+
data-slot="float-item-toolbar"
|
|
270
|
+
:aria-label="props.ariaLabel"
|
|
271
|
+
:aria-orientation="toolbarOrientation"
|
|
272
|
+
:class="toolbarClass"
|
|
273
|
+
@keydown="onToolbarKeydown"
|
|
274
|
+
>
|
|
275
|
+
<slot />
|
|
276
|
+
</div>
|
|
277
|
+
|
|
278
|
+
<button
|
|
279
|
+
v-else-if="isButton"
|
|
280
|
+
ref="itemRef"
|
|
281
|
+
v-bind="forwardedAttrs"
|
|
282
|
+
type="button"
|
|
283
|
+
data-slot="float-item-action"
|
|
284
|
+
:aria-label="props.ariaLabel"
|
|
285
|
+
:disabled="props.disabled"
|
|
286
|
+
:tabindex="tabIndex"
|
|
287
|
+
:class="buttonClass"
|
|
288
|
+
@focus="onItemFocus"
|
|
289
|
+
@click="onButtonClick"
|
|
290
|
+
>
|
|
291
|
+
<slot />
|
|
292
|
+
</button>
|
|
293
|
+
|
|
294
|
+
<input
|
|
295
|
+
v-else-if="isInput"
|
|
296
|
+
ref="itemRef"
|
|
297
|
+
data-slot="float-item-action"
|
|
298
|
+
type="text"
|
|
299
|
+
:aria-label="props.ariaLabel"
|
|
300
|
+
:placeholder="props.placeholder"
|
|
301
|
+
:disabled="props.disabled"
|
|
302
|
+
:tabindex="tabIndex"
|
|
303
|
+
:class="inputClass"
|
|
304
|
+
@focus="onItemFocus"
|
|
305
|
+
/>
|
|
306
|
+
|
|
307
|
+
<span v-else-if="isText" data-slot="float-item-text" :class="textClass">
|
|
308
|
+
<slot />
|
|
309
|
+
</span>
|
|
310
|
+
|
|
311
|
+
<div
|
|
312
|
+
v-else-if="isGroup"
|
|
313
|
+
role="group"
|
|
314
|
+
data-slot="float-item-group"
|
|
315
|
+
:class="groupClass"
|
|
316
|
+
>
|
|
317
|
+
<slot />
|
|
318
|
+
</div>
|
|
319
|
+
|
|
320
|
+
<span
|
|
321
|
+
v-else-if="isSeparator"
|
|
322
|
+
role="separator"
|
|
323
|
+
aria-orientation="vertical"
|
|
324
|
+
data-slot="float-item-separator"
|
|
325
|
+
:class="separatorClass"
|
|
326
|
+
/>
|
|
327
|
+
</template>
|