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