@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.
Files changed (98) hide show
  1. package/dist/system/components/UiTooltip/UiTooltip.vue.d.ts +1 -0
  2. package/dist/system/components/UiTooltip/types.d.ts +8 -0
  3. package/dist/system/components/core/tooltip/TooltipContent.vue.d.ts +2 -0
  4. package/dist/system/index.d.ts +1 -0
  5. package/dist/system/lib/useAnchorFloat.d.ts +143 -0
  6. package/dist/system/lib.js +18787 -18280
  7. package/dist/system/patterns/UiFloatActions/UiFloatActionItems.vue.d.ts +35 -0
  8. package/dist/system/patterns/UiFloatActions/UiFloatActions.vue.d.ts +45 -0
  9. package/dist/system/patterns/UiFloatActions/floatActionItemContext.d.ts +16 -0
  10. package/dist/system/patterns/UiFloatActions/index.d.ts +3 -0
  11. package/dist/system/patterns/UiFloatActions/types.d.ts +127 -0
  12. package/dist/system/patterns/index.d.ts +1 -0
  13. package/docs/public-docs/quick-start.md +43 -0
  14. package/package.json +1 -1
  15. package/src/components/UiAccordion/UiAccordion.stories.ts +2 -2
  16. package/src/components/UiAutocomplete/UiAutocomplete.stories.ts +2 -2
  17. package/src/components/UiAutocomplete/UiAutocomplete.vue +3 -3
  18. package/src/components/UiBadge/UiBadge.stories.ts +9 -9
  19. package/src/components/UiDropdownMenu/UiDropdownMenu.stories.ts +4 -4
  20. package/src/components/UiField/UiField.stories.ts +6 -6
  21. package/src/components/UiInput/UiInput.vue +1 -1
  22. package/src/components/UiKbd/UiKbd.stories.ts +3 -3
  23. package/src/components/UiKbd/UiKbd.vue +1 -1
  24. package/src/components/UiNavigationMenu/UiNavigationMenu.stories.ts +28 -28
  25. package/src/components/UiPopover/UiPopover.stories.ts +20 -20
  26. package/src/components/UiRadioGroup/UiRadioGroup.stories.ts +24 -24
  27. package/src/components/UiResizable/UiResizable.stories.ts +14 -14
  28. package/src/components/UiSelect/UiSelect.stories.ts +1 -1
  29. package/src/components/UiSheet/UiSheet.stories.ts +14 -14
  30. package/src/components/UiSlider/UiSlider.stories.ts +8 -8
  31. package/src/components/UiSpinner/UiSpinner.stories.ts +8 -8
  32. package/src/components/UiSwitch/UiSwitch.stories.ts +4 -4
  33. package/src/components/UiTabs/UiTabs.stories.ts +46 -46
  34. package/src/components/UiToggleGroup/UiToggleGroup.stories.ts +14 -14
  35. package/src/components/UiTooltip/UiTooltip.vue +2 -0
  36. package/src/components/UiTooltip/types.ts +9 -0
  37. package/src/components/core/accordion/AccordionContent.vue +1 -1
  38. package/src/components/core/accordion/AccordionTrigger.vue +1 -1
  39. package/src/components/core/alert/AlertDescription.vue +1 -1
  40. package/src/components/core/alert/index.ts +1 -1
  41. package/src/components/core/calendar/Calendar.vue +4 -4
  42. package/src/components/core/calendar/CalendarCell.vue +1 -1
  43. package/src/components/core/drawer/DrawerDescription.vue +1 -1
  44. package/src/components/core/dropdown-menu/DropdownMenuCheckboxItem.vue +1 -1
  45. package/src/components/core/dropdown-menu/DropdownMenuItem.vue +1 -1
  46. package/src/components/core/dropdown-menu/DropdownMenuLabel.vue +1 -3
  47. package/src/components/core/dropdown-menu/DropdownMenuRadioItem.vue +1 -1
  48. package/src/components/core/dropdown-menu/DropdownMenuShortcut.vue +4 -1
  49. package/src/components/core/dropdown-menu/DropdownMenuSubTrigger.vue +1 -1
  50. package/src/components/core/field/FieldDescription.vue +1 -1
  51. package/src/components/core/field/FieldLegend.vue +2 -2
  52. package/src/components/core/field/FieldSeparator.vue +1 -1
  53. package/src/components/core/input/Input.vue +1 -1
  54. package/src/components/core/item/index.ts +1 -1
  55. package/src/components/core/label/Label.vue +1 -1
  56. package/src/components/core/listbox/ListboxFilter.vue +1 -1
  57. package/src/components/core/listbox/ListboxGroupLabel.vue +1 -1
  58. package/src/components/core/listbox/ListboxItem.vue +1 -1
  59. package/src/components/core/native-select/NativeSelect.vue +1 -1
  60. package/src/components/core/navigation-menu/NavigationMenuLink.vue +1 -1
  61. package/src/components/core/navigation-menu/index.ts +1 -1
  62. package/src/components/core/range-calendar/RangeCalendarCell.vue +1 -1
  63. package/src/components/core/select/SelectItem.vue +1 -1
  64. package/src/components/core/select/SelectLabel.vue +3 -1
  65. package/src/components/core/select/SelectTrigger.vue +1 -1
  66. package/src/components/core/sidebar/SidebarGroupContent.vue +1 -1
  67. package/src/components/core/sidebar/SidebarGroupLabel.vue +1 -1
  68. package/src/components/core/sidebar/SidebarMenuBadge.vue +1 -1
  69. package/src/components/core/sidebar/SidebarMenuSubButton.vue +2 -2
  70. package/src/components/core/sidebar/index.ts +4 -4
  71. package/src/components/core/slider/Slider.vue +3 -3
  72. package/src/components/core/stepper/StepperDescription.vue +1 -1
  73. package/src/components/core/table/Table.vue +1 -1
  74. package/src/components/core/table/TableEmpty.vue +1 -1
  75. package/src/components/core/tabs/TabsTrigger.vue +1 -1
  76. package/src/components/core/tags-input/TagsInput.vue +1 -1
  77. package/src/components/core/tags-input/TagsInputItem.vue +1 -1
  78. package/src/components/core/textarea/Textarea.vue +1 -1
  79. package/src/components/core/toggle/index.ts +1 -1
  80. package/src/components/core/toggle-group/index.ts +1 -1
  81. package/src/components/core/tooltip/TooltipContent.vue +10 -4
  82. package/src/index.ts +1 -0
  83. package/src/lib/useAnchorFloat.test.ts +166 -0
  84. package/src/lib/useAnchorFloat.ts +437 -0
  85. package/src/lib/useDrag.stories.ts +12 -12
  86. package/src/patterns/UiDatePicker/UiDatePicker.stories.ts +8 -8
  87. package/src/patterns/UiFloatActions/UiFloatActionItems.vue +327 -0
  88. package/src/patterns/UiFloatActions/UiFloatActions.stories.ts +900 -0
  89. package/src/patterns/UiFloatActions/UiFloatActions.vue +224 -0
  90. package/src/patterns/UiFloatActions/__tests__/UiFloatActionItems.test.ts +104 -0
  91. package/src/patterns/UiFloatActions/__tests__/UiFloatActions.a11y.test.ts +152 -0
  92. package/src/patterns/UiFloatActions/__tests__/UiFloatActions.test.ts +86 -0
  93. package/src/patterns/UiFloatActions/floatActionItemContext.ts +20 -0
  94. package/src/patterns/UiFloatActions/index.ts +3 -0
  95. package/src/patterns/UiFloatActions/types.ts +155 -0
  96. package/src/patterns/UiSidebar/UiSidebarGroupLabel.stories.ts +2 -2
  97. package/src/patterns/UiSidebar/UiSidebarMenuButton.stories.ts +3 -3
  98. package/src/patterns/index.ts +1 -0
@@ -0,0 +1,900 @@
1
+ import type { Meta, StoryObj } from '@storybook/vue3-vite';
2
+ import { ref, useId, watch } from 'vue';
3
+ import UiFloatActions from './UiFloatActions.vue';
4
+ import { UiFloatActionItems } from './index';
5
+ import { UiIcon } from '../../components/UiIcon';
6
+ import { UiTooltip } from '../../components/UiTooltip';
7
+ import { useAnchorFloat } from '../../lib/useAnchorFloat';
8
+ import type { UiFloatActionsPlacement, UiFloatActionsTrigger } from './types';
9
+
10
+ const PLACEMENT_OPTIONS: UiFloatActionsPlacement[] = [
11
+ 'top',
12
+ 'top-start',
13
+ 'top-end',
14
+ 'bottom',
15
+ 'bottom-start',
16
+ 'bottom-end',
17
+ 'left',
18
+ 'left-start',
19
+ 'left-end',
20
+ 'right',
21
+ 'right-start',
22
+ 'right-end',
23
+ ];
24
+
25
+ const meta = {
26
+ title: 'Patterns/UiFloatActions',
27
+ component: UiFloatActions,
28
+ tags: ['autodocs', 'experimental'],
29
+ argTypes: {
30
+ trigger: {
31
+ control: 'select',
32
+ options: [
33
+ 'hover',
34
+ 'click',
35
+ 'focus',
36
+ 'manual',
37
+ ] satisfies UiFloatActionsTrigger[],
38
+ description: 'How the floating panel opens',
39
+ },
40
+ placement: {
41
+ control: 'select',
42
+ options: PLACEMENT_OPTIONS,
43
+ description: 'Preferred placement relative to the anchor',
44
+ },
45
+ offset: {
46
+ control: { type: 'number', min: 0, max: 48, step: 1 },
47
+ description: 'Distance from the anchor in pixels',
48
+ },
49
+ open: {
50
+ control: 'boolean',
51
+ description:
52
+ 'Controlled open state. Use with `manual` trigger, or to force the panel open.',
53
+ },
54
+ openDelay: {
55
+ control: { type: 'number', min: 0, max: 1000, step: 50 },
56
+ description: 'Delay in ms before opening on pointer hover',
57
+ },
58
+ closeDelay: {
59
+ control: { type: 'number', min: 0, max: 1000, step: 50 },
60
+ description: 'Delay in ms before closing on pointer leave',
61
+ },
62
+ dismissOnOutsideClick: {
63
+ control: 'boolean',
64
+ description: 'Close when clicking outside the anchor and panel',
65
+ },
66
+ dismissOnEscape: {
67
+ control: 'boolean',
68
+ description: 'Close on Escape and restore focus to the anchor',
69
+ },
70
+ ariaLabel: {
71
+ control: 'text',
72
+ description:
73
+ 'Accessible name for the anchor when visible text is insufficient',
74
+ },
75
+ },
76
+ args: {
77
+ trigger: 'hover',
78
+ placement: 'top',
79
+ offset: 10,
80
+ open: false,
81
+ openDelay: 150,
82
+ closeDelay: 150,
83
+ dismissOnOutsideClick: true,
84
+ dismissOnEscape: true,
85
+ ariaLabel: 'Paragraph actions',
86
+ },
87
+ } satisfies Meta<typeof UiFloatActions>;
88
+
89
+ export default meta;
90
+ type Story = StoryObj<typeof meta>;
91
+
92
+ type FloatRenderConfig = {
93
+ helperText?: string;
94
+ anchorText?: string;
95
+ anchorClass?: string;
96
+ useCardAnchor?: boolean;
97
+ showPagination?: boolean;
98
+ };
99
+
100
+ function createFloatRender(config: FloatRenderConfig = {}) {
101
+ const {
102
+ helperText,
103
+ anchorText = 'Hover or Tab to this paragraph to reveal contextual actions.',
104
+ anchorClass = 'max-w-sm rounded-md border border-border-surface-default bg-background-surface-primary px-4 py-6 body-14-regular leading-6',
105
+ useCardAnchor = false,
106
+ showPagination = false,
107
+ } = config;
108
+
109
+ return (args: Story['args']) => ({
110
+ components: { UiFloatActions, UiFloatActionItems, UiIcon },
111
+ setup() {
112
+ const open = ref(args?.open ?? false);
113
+ const page = ref(2);
114
+ const total = ref(2);
115
+
116
+ watch(
117
+ () => args?.open,
118
+ (value) => {
119
+ if (value !== undefined) open.value = value;
120
+ },
121
+ );
122
+
123
+ function previousPage() {
124
+ page.value = Math.max(1, page.value - 1);
125
+ }
126
+
127
+ function nextPage() {
128
+ page.value = Math.min(total.value, page.value + 1);
129
+ }
130
+
131
+ return {
132
+ args,
133
+ open,
134
+ page,
135
+ total,
136
+ previousPage,
137
+ nextPage,
138
+ helperText,
139
+ anchorText,
140
+ anchorClass,
141
+ useCardAnchor,
142
+ showPagination,
143
+ };
144
+ },
145
+ template: `
146
+ <div :class="showPagination ? 'mx-auto max-w-2xl space-y-4 p-8' : 'flex min-h-64 flex-col items-center justify-center gap-3 p-8'">
147
+ <p v-if="helperText" class="text-muted-foreground max-w-sm body-14-regular">
148
+ {{ helperText }}
149
+ </p>
150
+ <UiFloatActions
151
+ v-model:open="open"
152
+ :trigger="args.trigger"
153
+ :placement="args.placement"
154
+ :offset="args.offset"
155
+ :open-delay="args.openDelay"
156
+ :close-delay="args.closeDelay"
157
+ :dismiss-on-outside-click="args.dismissOnOutsideClick"
158
+ :dismiss-on-escape="args.dismissOnEscape"
159
+ :aria-label="args.ariaLabel"
160
+ >
161
+ <template #container>
162
+ <article
163
+ v-if="useCardAnchor"
164
+ class="rounded-lg border border-border-surface-default bg-background-surface-secondary p-4 shadow-lg"
165
+ >
166
+ <h3 class="label-14-medium">Floating card</h3>
167
+ <p class="text-muted-foreground mt-2 body-14-regular">{{ anchorText }}</p>
168
+ </article>
169
+ <p v-else :class="anchorClass">{{ anchorText }}</p>
170
+ </template>
171
+ <template #action>
172
+ <UiFloatActionItems aria-label="Text actions">
173
+ <UiFloatActionItems type="button" aria-label="Edit">
174
+ <UiIcon name="edit" size="s" />
175
+ </UiFloatActionItems>
176
+ <UiFloatActionItems type="button" aria-label="Copy">
177
+ <UiIcon name="copy" size="s" />
178
+ </UiFloatActionItems>
179
+ <UiFloatActionItems v-if="showPagination" type="separator" />
180
+ <UiFloatActionItems v-if="showPagination" type="group">
181
+ <UiFloatActionItems
182
+ type="button"
183
+ aria-label="Previous match"
184
+ :disabled="page <= 1"
185
+ @click="previousPage"
186
+ >
187
+ <UiIcon name="chevron-left" size="s" />
188
+ </UiFloatActionItems>
189
+ <UiFloatActionItems type="text">{{ page }}/{{ total }}</UiFloatActionItems>
190
+ <UiFloatActionItems
191
+ type="button"
192
+ aria-label="Next match"
193
+ :disabled="page >= total"
194
+ @click="nextPage"
195
+ >
196
+ <UiIcon name="chevron-right" size="s" />
197
+ </UiFloatActionItems>
198
+ </UiFloatActionItems>
199
+ <template v-if="!showPagination">
200
+ <UiFloatActionItems type="button" aria-label="Comment">
201
+ <UiIcon name="message-circle" size="s" />
202
+ </UiFloatActionItems>
203
+ <UiFloatActionItems type="button" aria-label="Delete">
204
+ <UiIcon name="trash" size="s" />
205
+ </UiFloatActionItems>
206
+ </template>
207
+ </UiFloatActionItems>
208
+ </template>
209
+ </UiFloatActions>
210
+ </div>
211
+ `,
212
+ });
213
+ }
214
+
215
+ const flatActionsSource = `<script setup lang="ts">
216
+ import { UiFloatActions, UiFloatActionItems, UiIcon, UiTooltip } from '@aleph-alpha/ui-library';
217
+ </script>
218
+
219
+ <template>
220
+ <UiFloatActions trigger="hover" placement="top" :offset="10">
221
+ <template #container>
222
+ <p>Hover or Tab to this paragraph to reveal contextual actions.</p>
223
+ </template>
224
+ <template #action="{ panelEl }">
225
+ <UiFloatActionItems aria-label="Text actions">
226
+ <!-- Icon-only buttons: wrap each in a tooltip to name the action.
227
+ Teleport the tooltip into the top-layer panel (:to="panelEl") so it
228
+ is not painted underneath it. -->
229
+ <UiTooltip content="Edit" :to="panelEl">
230
+ <UiFloatActionItems type="button" aria-label="Edit">
231
+ <UiIcon name="edit" size="s" />
232
+ </UiFloatActionItems>
233
+ </UiTooltip>
234
+ <UiTooltip content="Copy" :to="panelEl">
235
+ <UiFloatActionItems type="button" aria-label="Copy">
236
+ <UiIcon name="copy" size="s" />
237
+ </UiFloatActionItems>
238
+ </UiTooltip>
239
+ </UiFloatActionItems>
240
+ </template>
241
+ </UiFloatActions>
242
+ </template>`;
243
+
244
+ /**
245
+ * Flat row of icon-only actions revealed on pointer hover or keyboard focus.
246
+ * Each icon button is wrapped in a `UiTooltip` so its purpose is discoverable —
247
+ * a `button` item forwards attributes, so it can be dropped inside any wrapper.
248
+ * Use the controls panel to try triggers, placement, offset, and dismiss behaviour.
249
+ */
250
+ export const FlatActions: Story = {
251
+ render: (args) => ({
252
+ components: { UiFloatActions, UiFloatActionItems, UiIcon, UiTooltip },
253
+ setup() {
254
+ const open = ref(args?.open ?? false);
255
+ watch(
256
+ () => args?.open,
257
+ (value) => {
258
+ if (value !== undefined) open.value = value;
259
+ },
260
+ );
261
+ return { args, open };
262
+ },
263
+ template: `
264
+ <div class="flex min-h-64 flex-col items-center justify-center gap-3 p-8">
265
+ <UiFloatActions
266
+ v-model:open="open"
267
+ :trigger="args.trigger"
268
+ :placement="args.placement"
269
+ :offset="args.offset"
270
+ :open-delay="args.openDelay"
271
+ :close-delay="args.closeDelay"
272
+ :dismiss-on-outside-click="args.dismissOnOutsideClick"
273
+ :dismiss-on-escape="args.dismissOnEscape"
274
+ :aria-label="args.ariaLabel"
275
+ >
276
+ <template #container>
277
+ <p class="max-w-sm rounded-md border border-border-surface-default bg-background-surface-primary px-4 py-6 body-14-regular leading-6">
278
+ Hover or Tab to this paragraph to reveal contextual actions.
279
+ </p>
280
+ </template>
281
+ <template #action="{ panelEl }">
282
+ <UiFloatActionItems aria-label="Text actions">
283
+ <UiTooltip content="Edit" :to="panelEl">
284
+ <UiFloatActionItems type="button" aria-label="Edit">
285
+ <UiIcon name="edit" size="s" />
286
+ </UiFloatActionItems>
287
+ </UiTooltip>
288
+ <UiTooltip content="Copy" :to="panelEl">
289
+ <UiFloatActionItems type="button" aria-label="Copy">
290
+ <UiIcon name="copy" size="s" />
291
+ </UiFloatActionItems>
292
+ </UiTooltip>
293
+ <UiTooltip content="Comment" :to="panelEl">
294
+ <UiFloatActionItems type="button" aria-label="Comment">
295
+ <UiIcon name="message-circle" size="s" />
296
+ </UiFloatActionItems>
297
+ </UiTooltip>
298
+ <UiTooltip content="Delete" :to="panelEl">
299
+ <UiFloatActionItems type="button" aria-label="Delete">
300
+ <UiIcon name="trash" size="s" />
301
+ </UiFloatActionItems>
302
+ </UiTooltip>
303
+ </UiFloatActionItems>
304
+ </template>
305
+ </UiFloatActions>
306
+ </div>
307
+ `,
308
+ }),
309
+ parameters: {
310
+ docs: { source: { code: flatActionsSource } },
311
+ },
312
+ };
313
+
314
+ const clickTriggerSource = `<script setup lang="ts">
315
+ import { UiFloatActions, UiFloatActionItems, UiIcon } from '@aleph-alpha/ui-library';
316
+ </script>
317
+
318
+ <template>
319
+ <UiFloatActions trigger="click" placement="bottom" :offset="10" aria-label="Open text actions">
320
+ <template #container>
321
+ <p>Click this paragraph to toggle the floating toolbar.</p>
322
+ </template>
323
+ <template #action>
324
+ <UiFloatActionItems aria-label="Text actions">
325
+ <!-- Icon + visible text label: no tooltip needed. -->
326
+ <UiFloatActionItems type="button" aria-label="Edit" class="w-auto gap-1.5 px-3 label-14-medium">
327
+ <UiIcon name="edit" size="s" />Edit
328
+ </UiFloatActionItems>
329
+ <UiFloatActionItems type="button" aria-label="Copy" class="w-auto gap-1.5 px-3 label-14-medium">
330
+ <UiIcon name="copy" size="s" />Copy
331
+ </UiFloatActionItems>
332
+ </UiFloatActionItems>
333
+ </template>
334
+ </UiFloatActions>
335
+ </template>`;
336
+
337
+ /**
338
+ * Click trigger for toggling a floating toolbar with pointer or keyboard.
339
+ * Actions pair an icon with a visible text label, so no tooltip is required.
340
+ * The anchor exposes `aria-expanded`, `aria-haspopup`, and `aria-controls`
341
+ * for screen readers. Enter and Space also toggle the panel.
342
+ */
343
+ export const ClickTrigger: Story = {
344
+ args: {
345
+ trigger: 'click',
346
+ placement: 'bottom',
347
+ ariaLabel: 'Open text actions',
348
+ },
349
+ render: (args) => ({
350
+ components: { UiFloatActions, UiFloatActionItems, UiIcon },
351
+ setup() {
352
+ const open = ref(args?.open ?? false);
353
+ watch(
354
+ () => args?.open,
355
+ (value) => {
356
+ if (value !== undefined) open.value = value;
357
+ },
358
+ );
359
+ return { args, open };
360
+ },
361
+ template: `
362
+ <div class="flex min-h-64 flex-col items-center justify-center gap-3 p-8">
363
+ <UiFloatActions
364
+ v-model:open="open"
365
+ :trigger="args.trigger"
366
+ :placement="args.placement"
367
+ :offset="args.offset"
368
+ :open-delay="args.openDelay"
369
+ :close-delay="args.closeDelay"
370
+ :dismiss-on-outside-click="args.dismissOnOutsideClick"
371
+ :dismiss-on-escape="args.dismissOnEscape"
372
+ :aria-label="args.ariaLabel"
373
+ >
374
+ <template #container>
375
+ <p class="max-w-sm rounded-md border border-border-surface-default bg-background-surface-primary px-4 py-6 body-14-regular">
376
+ Click this paragraph to toggle the floating toolbar.
377
+ </p>
378
+ </template>
379
+ <template #action>
380
+ <UiFloatActionItems aria-label="Text actions">
381
+ <UiFloatActionItems type="button" aria-label="Edit" class="w-auto gap-1.5 px-3 label-14-medium">
382
+ <UiIcon name="edit" size="s" />Edit
383
+ </UiFloatActionItems>
384
+ <UiFloatActionItems type="button" aria-label="Copy" class="w-auto gap-1.5 px-3 label-14-medium">
385
+ <UiIcon name="copy" size="s" />Copy
386
+ </UiFloatActionItems>
387
+ </UiFloatActionItems>
388
+ </template>
389
+ </UiFloatActions>
390
+ </div>
391
+ `,
392
+ }),
393
+ parameters: {
394
+ docs: { source: { code: clickTriggerSource } },
395
+ },
396
+ };
397
+
398
+ /**
399
+ * Focus-only trigger for keyboard-first workflows.
400
+ * The panel opens when the anchor receives focus and closes on blur or Escape.
401
+ * Focus stays on the anchor; Tab into toolbar items to use arrow-key navigation.
402
+ */
403
+ export const FocusTrigger: Story = {
404
+ args: {
405
+ trigger: 'focus',
406
+ placement: 'top',
407
+ offset: 10,
408
+ ariaLabel: 'Paragraph actions',
409
+ },
410
+ render: createFloatRender({
411
+ helperText:
412
+ 'Tab to the paragraph below. The toolbar opens on focus. Tab again to reach toolbar actions, then use arrow keys to move between them.',
413
+ anchorText: 'Tab here to reveal focus-triggered actions.',
414
+ }),
415
+ };
416
+
417
+ /**
418
+ * Placement and offset configuration.
419
+ * The panel auto-flips via floating-ui when there is not enough viewport space.
420
+ */
421
+ export const Placements: Story = {
422
+ render: (args) => ({
423
+ components: { UiFloatActions, UiFloatActionItems, UiIcon },
424
+ setup() {
425
+ return { args };
426
+ },
427
+ template: `
428
+ <div class="grid min-h-96 grid-cols-2 place-items-center gap-8 p-8">
429
+ <UiFloatActions
430
+ v-for="placement in ['top', 'bottom', 'left', 'right']"
431
+ :key="placement"
432
+ :trigger="args.trigger"
433
+ :placement="placement"
434
+ :offset="args.offset"
435
+ :open-delay="args.openDelay"
436
+ :close-delay="args.closeDelay"
437
+ :aria-label="placement + ' placement demo'"
438
+ >
439
+ <template #container>
440
+ <span class="rounded-md border border-border-surface-default px-4 py-2 body-14-regular capitalize">
441
+ {{ placement }}
442
+ </span>
443
+ </template>
444
+ <template #action>
445
+ <UiFloatActionItems :aria-label="placement + ' actions'">
446
+ <UiFloatActionItems type="button" aria-label="Action">
447
+ <UiIcon name="more-vertical" size="s" />
448
+ </UiFloatActionItems>
449
+ </UiFloatActionItems>
450
+ </template>
451
+ </UiFloatActions>
452
+ </div>
453
+ `,
454
+ }),
455
+ argTypes: {
456
+ placement: { control: false },
457
+ open: { control: false },
458
+ ariaLabel: { control: false },
459
+ },
460
+ };
461
+
462
+ /**
463
+ * UiFloatActionItems item types: `button`, `input`, `text`, `group`, and `separator`.
464
+ * Nest items inside a root `toolbar` container. Each icon button requires an
465
+ * `aria-label` because it renders without visible text.
466
+ */
467
+ const toolbarItemTypesTemplateSource = `<script setup lang="ts">
468
+ import { UiFloatActions, UiFloatActionItems, UiIcon } from '@aleph-alpha/ui-library';
469
+ </script>
470
+
471
+ <template>
472
+ <UiFloatActions trigger="hover" placement="top" :offset="10">
473
+ <template #container>
474
+ <p>Hover or Tab to explore toolbar item types.</p>
475
+ </template>
476
+ <template #action>
477
+ <UiFloatActionItems aria-label="Mixed actions">
478
+ <UiFloatActionItems type="button" aria-label="Edit">
479
+ <UiIcon name="edit" size="s" />
480
+ </UiFloatActionItems>
481
+ <UiFloatActionItems type="button" aria-label="Copy">
482
+ <UiIcon name="copy" size="s" />
483
+ </UiFloatActionItems>
484
+ <UiFloatActionItems type="separator" />
485
+ <UiFloatActionItems type="group">
486
+ <UiFloatActionItems type="button" aria-label="Previous page">
487
+ <UiIcon name="chevron-left" size="s" />
488
+ </UiFloatActionItems>
489
+ <UiFloatActionItems type="text">2/2</UiFloatActionItems>
490
+ <UiFloatActionItems type="button" aria-label="Next page">
491
+ <UiIcon name="chevron-right" size="s" />
492
+ </UiFloatActionItems>
493
+ </UiFloatActionItems>
494
+ </UiFloatActionItems>
495
+ </template>
496
+ </UiFloatActions>
497
+ </template>`;
498
+
499
+ export const ToolbarItemTypes: Story = {
500
+ render: () => ({
501
+ components: { UiFloatActions, UiFloatActionItems, UiIcon },
502
+ template: `
503
+ <div class="flex min-h-48 flex-col items-center justify-center gap-6 p-8">
504
+ <UiFloatActions trigger="hover" placement="top" :offset="10">
505
+ <template #container>
506
+ <p class="max-w-sm rounded-md border border-border-surface-default bg-background-surface-primary px-4 py-6 body-14-regular">
507
+ Hover or Tab to explore toolbar item types.
508
+ </p>
509
+ </template>
510
+ <template #action>
511
+ <UiFloatActionItems aria-label="Mixed actions">
512
+ <UiFloatActionItems type="button" aria-label="Edit">
513
+ <UiIcon name="edit" size="s" />
514
+ </UiFloatActionItems>
515
+ <UiFloatActionItems type="button" aria-label="Copy">
516
+ <UiIcon name="copy" size="s" />
517
+ </UiFloatActionItems>
518
+ <UiFloatActionItems type="separator" />
519
+ <UiFloatActionItems type="group">
520
+ <UiFloatActionItems type="button" aria-label="Previous page">
521
+ <UiIcon name="chevron-left" size="s" />
522
+ </UiFloatActionItems>
523
+ <UiFloatActionItems type="text">2/2</UiFloatActionItems>
524
+ <UiFloatActionItems type="button" aria-label="Next page">
525
+ <UiIcon name="chevron-right" size="s" />
526
+ </UiFloatActionItems>
527
+ </UiFloatActionItems>
528
+ </UiFloatActionItems>
529
+ </template>
530
+ </UiFloatActions>
531
+
532
+ <UiFloatActionItems aria-label="Filter actions">
533
+ <UiFloatActionItems
534
+ type="input"
535
+ aria-label="Filter value"
536
+ placeholder="Filter..."
537
+ />
538
+ <UiFloatActionItems type="button" aria-label="Apply filter">
539
+ <UiIcon name="check" size="s" />
540
+ </UiFloatActionItems>
541
+ </UiFloatActionItems>
542
+ </div>
543
+ `,
544
+ }),
545
+ parameters: {
546
+ controls: { disable: true },
547
+ docs: { source: { code: toolbarItemTypesTemplateSource } },
548
+ },
549
+ };
550
+
551
+ /**
552
+ * Text-selection toolbar with pagination controls.
553
+ * Demonstrates a decoupled pattern: the float anchors to any element without
554
+ * coupling toolbar items to a specific domain model. Arrow keys navigate items.
555
+ */
556
+ export const TextSelectionToolbar: Story = {
557
+ args: {
558
+ trigger: 'hover',
559
+ placement: 'top',
560
+ offset: 10,
561
+ },
562
+ render: createFloatRender({
563
+ showPagination: true,
564
+ helperText:
565
+ 'Hover or Tab to the highlighted paragraph to reveal the floating action bar. Tab into toolbar actions, then use arrow keys to move between them.',
566
+ anchorText:
567
+ 'Design systems thrive when primitives stay decoupled. This pattern anchors a pill toolbar to any element without coupling the toolbar items to a specific domain model.',
568
+ }),
569
+ };
570
+
571
+ /**
572
+ * Click-bound card actions anchored below the card.
573
+ * Use `placement="bottom-start"` to align the toolbar with the card's leading edge.
574
+ */
575
+ export const ClickBoundCardActions: Story = {
576
+ args: {
577
+ trigger: 'click',
578
+ placement: 'bottom-start',
579
+ ariaLabel: 'Open card actions',
580
+ },
581
+ render: createFloatRender({
582
+ useCardAnchor: true,
583
+ anchorText: 'Click anywhere on this card to reveal inline actions.',
584
+ }),
585
+ };
586
+
587
+ /**
588
+ * All float states and variations in a single view for visual QA and reference.
589
+ */
590
+ export const AllStates: Story = {
591
+ render: () => ({
592
+ components: { UiFloatActions, UiFloatActionItems, UiIcon },
593
+ setup() {
594
+ const openPanel = ref(true);
595
+ const closedPanel = ref(false);
596
+ return { openPanel, closedPanel };
597
+ },
598
+ template: `
599
+ <div class="flex flex-col gap-10 p-8">
600
+ <section class="flex flex-col gap-4">
601
+ <h3 class="body-16-medium text-content-on-surface-primary">Triggers</h3>
602
+ <div class="grid gap-6 md:grid-cols-3">
603
+ <div class="flex flex-col items-center gap-2">
604
+ <span class="label-14-medium text-content-on-surface-secondary">Hover</span>
605
+ <UiFloatActions trigger="hover" placement="top" :offset="10">
606
+ <template #container>
607
+ <span class="rounded-md border border-border-surface-default px-4 py-2 body-14-regular">
608
+ Hover or Tab
609
+ </span>
610
+ </template>
611
+ <template #action>
612
+ <UiFloatActionItems aria-label="Hover actions">
613
+ <UiFloatActionItems type="button" aria-label="Edit">
614
+ <UiIcon name="edit" size="s" />
615
+ </UiFloatActionItems>
616
+ </UiFloatActionItems>
617
+ </template>
618
+ </UiFloatActions>
619
+ </div>
620
+ <div class="flex flex-col items-center gap-2">
621
+ <span class="label-14-medium text-content-on-surface-secondary">Click</span>
622
+ <UiFloatActions trigger="click" placement="top" :offset="10" aria-label="Click actions">
623
+ <template #container>
624
+ <span class="rounded-md border border-border-surface-default px-4 py-2 body-14-regular">
625
+ Click or Enter
626
+ </span>
627
+ </template>
628
+ <template #action>
629
+ <UiFloatActionItems aria-label="Click actions">
630
+ <UiFloatActionItems type="button" aria-label="Copy">
631
+ <UiIcon name="copy" size="s" />
632
+ </UiFloatActionItems>
633
+ </UiFloatActionItems>
634
+ </template>
635
+ </UiFloatActions>
636
+ </div>
637
+ <div class="flex flex-col items-center gap-2">
638
+ <span class="label-14-medium text-content-on-surface-secondary">Focus</span>
639
+ <UiFloatActions trigger="focus" placement="top" :offset="10" aria-label="Focus actions">
640
+ <template #container>
641
+ <span class="rounded-md border border-border-surface-default px-4 py-2 body-14-regular">
642
+ Tab to focus
643
+ </span>
644
+ </template>
645
+ <template #action>
646
+ <UiFloatActionItems aria-label="Focus actions">
647
+ <UiFloatActionItems type="button" aria-label="Comment">
648
+ <UiIcon name="message-circle" size="s" />
649
+ </UiFloatActionItems>
650
+ </UiFloatActionItems>
651
+ </template>
652
+ </UiFloatActions>
653
+ </div>
654
+ </div>
655
+ </section>
656
+
657
+ <section class="flex flex-col gap-4">
658
+ <h3 class="body-16-medium text-content-on-surface-primary">Placements</h3>
659
+ <div class="grid min-h-80 grid-cols-2 place-items-center gap-8">
660
+ <UiFloatActions
661
+ v-for="placement in ['top', 'bottom', 'left', 'right']"
662
+ :key="'placement-' + placement"
663
+ trigger="manual"
664
+ v-model:open="openPanel"
665
+ :placement="placement"
666
+ :offset="12"
667
+ :aria-label="placement + ' placement'"
668
+ >
669
+ <template #container>
670
+ <span class="rounded-md border border-border-surface-default px-4 py-2 body-14-regular capitalize">
671
+ {{ placement }}
672
+ </span>
673
+ </template>
674
+ <template #action>
675
+ <UiFloatActionItems :aria-label="placement + ' actions'">
676
+ <UiFloatActionItems type="button" aria-label="Action">
677
+ <UiIcon name="more-vertical" size="s" />
678
+ </UiFloatActionItems>
679
+ </UiFloatActionItems>
680
+ </template>
681
+ </UiFloatActions>
682
+ </div>
683
+ </section>
684
+
685
+ <section class="flex flex-col gap-4">
686
+ <h3 class="body-16-medium text-content-on-surface-primary">Open vs closed</h3>
687
+ <div class="grid gap-8 md:grid-cols-2">
688
+ <div class="flex flex-col items-center gap-2">
689
+ <span class="label-14-medium text-content-on-surface-secondary">Open</span>
690
+ <UiFloatActions trigger="manual" v-model:open="openPanel" placement="top" :offset="10" aria-label="Open panel">
691
+ <template #container>
692
+ <span class="rounded-md border border-border-surface-default px-4 py-2 body-14-regular">
693
+ Panel open
694
+ </span>
695
+ </template>
696
+ <template #action>
697
+ <UiFloatActionItems aria-label="Open panel actions">
698
+ <UiFloatActionItems type="button" aria-label="Edit">
699
+ <UiIcon name="edit" size="s" />
700
+ </UiFloatActionItems>
701
+ <UiFloatActionItems type="button" aria-label="Copy">
702
+ <UiIcon name="copy" size="s" />
703
+ </UiFloatActionItems>
704
+ </UiFloatActionItems>
705
+ </template>
706
+ </UiFloatActions>
707
+ </div>
708
+ <div class="flex flex-col items-center gap-2">
709
+ <span class="label-14-medium text-content-on-surface-secondary">Closed</span>
710
+ <UiFloatActions trigger="manual" v-model:open="closedPanel" placement="top" :offset="10" aria-label="Closed panel">
711
+ <template #container>
712
+ <span class="rounded-md border border-border-surface-default px-4 py-2 body-14-regular">
713
+ Panel closed
714
+ </span>
715
+ </template>
716
+ <template #action>
717
+ <UiFloatActionItems aria-label="Closed panel actions">
718
+ <UiFloatActionItems type="button" aria-label="Edit">
719
+ <UiIcon name="edit" size="s" />
720
+ </UiFloatActionItems>
721
+ </UiFloatActionItems>
722
+ </template>
723
+ </UiFloatActions>
724
+ </div>
725
+ </div>
726
+ </section>
727
+
728
+ <section class="flex flex-col gap-4">
729
+ <h3 class="body-16-medium text-content-on-surface-primary">Toolbar item types</h3>
730
+ <div class="flex flex-col items-center gap-6">
731
+ <UiFloatActionItems aria-label="Mixed actions">
732
+ <UiFloatActionItems type="button" aria-label="Edit">
733
+ <UiIcon name="edit" size="s" />
734
+ </UiFloatActionItems>
735
+ <UiFloatActionItems type="button" aria-label="Copy">
736
+ <UiIcon name="copy" size="s" />
737
+ </UiFloatActionItems>
738
+ <UiFloatActionItems type="separator" />
739
+ <UiFloatActionItems type="group">
740
+ <UiFloatActionItems type="button" aria-label="Previous page">
741
+ <UiIcon name="chevron-left" size="s" />
742
+ </UiFloatActionItems>
743
+ <UiFloatActionItems type="text">2/2</UiFloatActionItems>
744
+ <UiFloatActionItems type="button" aria-label="Next page">
745
+ <UiIcon name="chevron-right" size="s" />
746
+ </UiFloatActionItems>
747
+ </UiFloatActionItems>
748
+ </UiFloatActionItems>
749
+ <UiFloatActionItems aria-label="Filter actions">
750
+ <UiFloatActionItems type="input" aria-label="Filter value" placeholder="Filter..." />
751
+ <UiFloatActionItems type="button" aria-label="Apply filter">
752
+ <UiIcon name="check" size="s" />
753
+ </UiFloatActionItems>
754
+ </UiFloatActionItems>
755
+ </div>
756
+ </section>
757
+ </div>
758
+ `,
759
+ }),
760
+ tags: ['!autodocs'],
761
+ parameters: {
762
+ controls: { disable: true },
763
+ chromatic: { disableSnapshot: true },
764
+ docs: { canvas: { sourceState: 'none' } },
765
+ },
766
+ };
767
+
768
+ const composableUsageTemplateSource = `<script setup lang="ts">
769
+ import { useId } from 'vue';
770
+ import { useAnchorFloat, UiFloatActions, UiFloatActionItems, UiIcon } from '@aleph-alpha/ui-library';
771
+
772
+ // Prefer UiFloatActions for the standard component API. Use useAnchorFloat when
773
+ // you need full control over markup, animation, or teleport targets.
774
+
775
+ const contentId = useId();
776
+
777
+ const {
778
+ referenceRef,
779
+ floatingRef,
780
+ open,
781
+ floatingStyles,
782
+ isPositioned,
783
+ onReferenceMouseEnter,
784
+ onReferenceMouseLeave,
785
+ onReferenceFocus,
786
+ onReferenceBlur,
787
+ onFloatingMouseEnter,
788
+ onFloatingMouseLeave,
789
+ onFloatingFocusIn,
790
+ onFloatingFocusOut,
791
+ } = useAnchorFloat({ trigger: 'hover', placement: 'top', offset: 8 });
792
+ </script>
793
+
794
+ <template>
795
+ <button
796
+ ref="referenceRef"
797
+ type="button"
798
+ aria-label="Paragraph actions"
799
+ :aria-expanded="open"
800
+ aria-haspopup="true"
801
+ :aria-controls="open ? contentId : undefined"
802
+ @mouseenter="onReferenceMouseEnter"
803
+ @mouseleave="onReferenceMouseLeave"
804
+ @focus="onReferenceFocus"
805
+ @blur="onReferenceBlur"
806
+ >
807
+ Hover or Tab to reveal actions
808
+ </button>
809
+ <!-- popover="manual" promotes the panel to the top layer and, when shown via
810
+ showPopover({ source }), wires the anchor → panel keyboard focus order. -->
811
+ <Teleport to="body">
812
+ <div
813
+ v-if="open"
814
+ :id="contentId"
815
+ ref="floatingRef"
816
+ popover="manual"
817
+ :style="floatingStyles"
818
+ :class="[
819
+ 'z-50 m-0 inset-auto border-0 bg-transparent p-0 overflow-visible transition-opacity duration-200',
820
+ isPositioned ? 'opacity-100' : 'opacity-0',
821
+ ]"
822
+ @mouseenter="onFloatingMouseEnter"
823
+ @mouseleave="onFloatingMouseLeave"
824
+ @focusin="onFloatingFocusIn"
825
+ @focusout="onFloatingFocusOut"
826
+ >
827
+ <UiFloatActionItems aria-label="Actions">…</UiFloatActionItems>
828
+ </div>
829
+ </Teleport>
830
+ </template>`;
831
+
832
+ /**
833
+ * Headless usage with the `useAnchorFloat` composable.
834
+ * Use when you need full control over markup, animation, or teleport targets
835
+ * beyond what {@link UiFloatActions} provides. Wire focus handlers and popup ARIA on
836
+ * the anchor yourself when using `hover` or `focus` triggers.
837
+ */
838
+ export const ComposableUsage: Story = {
839
+ render: () => ({
840
+ components: { UiFloatActionItems, UiIcon },
841
+ setup() {
842
+ const contentId = useId();
843
+ const float = useAnchorFloat({
844
+ trigger: 'hover',
845
+ placement: 'top',
846
+ offset: 10,
847
+ });
848
+ return { contentId, ...float };
849
+ },
850
+ template: `
851
+ <div class="flex min-h-48 items-center justify-center p-8">
852
+ <button
853
+ ref="referenceRef"
854
+ type="button"
855
+ aria-label="Composable float actions"
856
+ :aria-expanded="open"
857
+ aria-haspopup="true"
858
+ :aria-controls="open ? contentId : undefined"
859
+ class="rounded-md border border-border-surface-default bg-background-surface-primary px-6 py-10 body-14-regular outline-none transition-[color,box-shadow,background-color,border-color] focus-visible:border-border-surface-focus-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]"
860
+ @mouseenter="onReferenceMouseEnter"
861
+ @mouseleave="onReferenceMouseLeave"
862
+ @focus="onReferenceFocus"
863
+ @blur="onReferenceBlur"
864
+ >
865
+ Hover or Tab to reveal a composable-driven floating action
866
+ </button>
867
+ <Teleport to="body">
868
+ <div
869
+ v-if="open"
870
+ :id="contentId"
871
+ ref="floatingRef"
872
+ popover="manual"
873
+ :style="floatingStyles"
874
+ :class="[
875
+ 'z-50 m-0 inset-auto border-0 bg-transparent p-0 overflow-visible outline-none transition-opacity duration-200 ease-out motion-reduce:transition-none',
876
+ isPositioned ? 'opacity-100' : 'opacity-0',
877
+ ]"
878
+ @mouseenter="onFloatingMouseEnter"
879
+ @mouseleave="onFloatingMouseLeave"
880
+ @focusin="onFloatingFocusIn"
881
+ @focusout="onFloatingFocusOut"
882
+ >
883
+ <UiFloatActionItems aria-label="Composable actions">
884
+ <UiFloatActionItems type="button" aria-label="Star">
885
+ <UiIcon name="star" size="s" />
886
+ </UiFloatActionItems>
887
+ <UiFloatActionItems type="button" aria-label="Pin">
888
+ <UiIcon name="pin" size="s" />
889
+ </UiFloatActionItems>
890
+ </UiFloatActionItems>
891
+ </div>
892
+ </Teleport>
893
+ </div>
894
+ `,
895
+ }),
896
+ parameters: {
897
+ controls: { disable: true },
898
+ docs: { source: { code: composableUsageTemplateSource } },
899
+ },
900
+ };