@aleph-alpha/ui-library 5.1.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/README.md +2 -0
- package/dist/system/components/core/sidebar/SidebarInset.vue.d.ts +14 -1
- package/dist/system/index.d.ts +1 -0
- package/dist/system/lib/useAnchorFloat.d.ts +143 -0
- package/dist/system/lib.js +19421 -18919
- 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 +12 -3
- package/src/components/UiButton/UiButton.stories.ts +526 -38
- package/src/components/core/sidebar/SidebarInset.vue +19 -2
- 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/UiSidebar/UiSidebarInset.stories.ts +259 -0
- package/src/patterns/UiSidebar/__tests__/UiSidebarInset.test.ts +20 -0
- package/src/patterns/index.ts +1 -0
|
@@ -0,0 +1,321 @@
|
|
|
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 } 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
|
+
const toolbarClass = computed(() =>
|
|
219
|
+
cn(
|
|
220
|
+
'inline-flex items-center gap-0.5 rounded-full border border-border-surface-default bg-background-surface-floating p-1 shadow-xs',
|
|
221
|
+
attrs.class ?? '',
|
|
222
|
+
),
|
|
223
|
+
);
|
|
224
|
+
|
|
225
|
+
const buttonClass = computed(() =>
|
|
226
|
+
cn(
|
|
227
|
+
'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',
|
|
228
|
+
attrs.class ?? '',
|
|
229
|
+
),
|
|
230
|
+
);
|
|
231
|
+
|
|
232
|
+
const inputClass = computed(() =>
|
|
233
|
+
cn(
|
|
234
|
+
'h-8 min-w-16 rounded-full border-0 bg-background-input-default px-3 text-sm text-content-on-surface-primary outline-none focus-visible:ring-2 focus-visible:ring-border-surface-focus-ring',
|
|
235
|
+
attrs.class ?? '',
|
|
236
|
+
),
|
|
237
|
+
);
|
|
238
|
+
|
|
239
|
+
const textClass = computed(() =>
|
|
240
|
+
cn(
|
|
241
|
+
'inline-flex h-8 min-w-8 items-center justify-center px-1 text-sm text-content-on-surface-primary',
|
|
242
|
+
attrs.class ?? '',
|
|
243
|
+
),
|
|
244
|
+
);
|
|
245
|
+
|
|
246
|
+
const groupClass = computed(() =>
|
|
247
|
+
cn('inline-flex items-center gap-0.5', attrs.class ?? ''),
|
|
248
|
+
);
|
|
249
|
+
|
|
250
|
+
const separatorClass = computed(() =>
|
|
251
|
+
cn('mx-0.5 h-5 w-px shrink-0 bg-border-surface-default', attrs.class ?? ''),
|
|
252
|
+
);
|
|
253
|
+
</script>
|
|
254
|
+
|
|
255
|
+
<template>
|
|
256
|
+
<!-- Follows the WAI-ARIA APG toolbar pattern: role="toolbar" with roving
|
|
257
|
+
arrow-key navigation handled via keydown. The plugin's interactive-role
|
|
258
|
+
allowlist omits "toolbar", so the handler is flagged despite being correct. -->
|
|
259
|
+
<!-- eslint-disable-next-line vuejs-accessibility/no-static-element-interactions -->
|
|
260
|
+
<div
|
|
261
|
+
v-if="isToolbar"
|
|
262
|
+
ref="itemRef"
|
|
263
|
+
role="toolbar"
|
|
264
|
+
data-slot="float-item-toolbar"
|
|
265
|
+
:aria-label="props.ariaLabel"
|
|
266
|
+
:aria-orientation="toolbarOrientation"
|
|
267
|
+
:class="toolbarClass"
|
|
268
|
+
@keydown="onToolbarKeydown"
|
|
269
|
+
>
|
|
270
|
+
<slot />
|
|
271
|
+
</div>
|
|
272
|
+
|
|
273
|
+
<button
|
|
274
|
+
v-else-if="isButton"
|
|
275
|
+
ref="itemRef"
|
|
276
|
+
type="button"
|
|
277
|
+
data-slot="float-item-action"
|
|
278
|
+
:aria-label="props.ariaLabel"
|
|
279
|
+
:disabled="props.disabled"
|
|
280
|
+
:tabindex="tabIndex"
|
|
281
|
+
:class="buttonClass"
|
|
282
|
+
@focus="onItemFocus"
|
|
283
|
+
@click="onButtonClick"
|
|
284
|
+
>
|
|
285
|
+
<slot />
|
|
286
|
+
</button>
|
|
287
|
+
|
|
288
|
+
<input
|
|
289
|
+
v-else-if="isInput"
|
|
290
|
+
ref="itemRef"
|
|
291
|
+
data-slot="float-item-action"
|
|
292
|
+
type="text"
|
|
293
|
+
:aria-label="props.ariaLabel"
|
|
294
|
+
:placeholder="props.placeholder"
|
|
295
|
+
:disabled="props.disabled"
|
|
296
|
+
:tabindex="tabIndex"
|
|
297
|
+
:class="inputClass"
|
|
298
|
+
@focus="onItemFocus"
|
|
299
|
+
/>
|
|
300
|
+
|
|
301
|
+
<span v-else-if="isText" data-slot="float-item-text" :class="textClass">
|
|
302
|
+
<slot />
|
|
303
|
+
</span>
|
|
304
|
+
|
|
305
|
+
<div
|
|
306
|
+
v-else-if="isGroup"
|
|
307
|
+
role="group"
|
|
308
|
+
data-slot="float-item-group"
|
|
309
|
+
:class="groupClass"
|
|
310
|
+
>
|
|
311
|
+
<slot />
|
|
312
|
+
</div>
|
|
313
|
+
|
|
314
|
+
<span
|
|
315
|
+
v-else-if="isSeparator"
|
|
316
|
+
role="separator"
|
|
317
|
+
aria-orientation="vertical"
|
|
318
|
+
data-slot="float-item-separator"
|
|
319
|
+
:class="separatorClass"
|
|
320
|
+
/>
|
|
321
|
+
</template>
|