@aleph-alpha/ui-library 5.8.0 → 5.10.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 +8 -7
- package/config.js +157 -4
- package/dist/system/__tests__/test-utils.d.ts +24 -0
- package/dist/system/components/UiAutocomplete/UiAutocomplete.vue.d.ts +8 -4
- package/dist/system/components/UiAutocomplete/types.d.ts +11 -0
- package/dist/system/components/UiFadeMask/UiFadeMask.vue.d.ts +21 -0
- package/dist/system/components/UiFadeMask/index.d.ts +2 -0
- package/dist/system/components/UiFadeMask/types.d.ts +33 -0
- package/dist/system/components/UiFileItem/UiFileItem.vue.d.ts +3 -1
- package/dist/system/components/UiFileType/types.d.ts +2 -1
- package/dist/system/components/UiListbox/UiListboxVirtualizer.vue.d.ts +21 -0
- package/dist/system/components/UiListbox/index.d.ts +1 -0
- package/dist/system/components/UiListbox/types.d.ts +36 -0
- package/dist/system/components/UiSelect/UiSelectVirtualizer.vue.d.ts +21 -0
- package/dist/system/components/UiSelect/index.d.ts +1 -0
- package/dist/system/components/UiSelect/types.d.ts +36 -0
- package/dist/system/components/UiSwitch/UiSwitch.vue.d.ts +1 -0
- package/dist/system/components/UiSwitch/types.d.ts +12 -0
- package/dist/system/components/core/native-select/NativeSelectOptGroup.vue.d.ts +2 -2
- package/dist/system/components/core/native-select/NativeSelectOption.vue.d.ts +2 -2
- package/dist/system/components/core/switch/Switch.vue.d.ts +2 -0
- package/dist/system/components/core/switch/index.d.ts +8 -0
- package/dist/system/components/index.d.ts +1 -0
- package/dist/system/index.d.ts +1 -0
- package/dist/system/lib/scrollbar.d.ts +37 -0
- package/dist/system/lib/useAnchorFloat.d.ts +0 -2
- package/dist/system/lib/useIsTruncated.d.ts +15 -0
- package/dist/system/lib.js +22660 -21292
- package/dist/system/mobile-device-frame.png +0 -0
- package/dist/system/patterns/UiFloatActions/types.d.ts +2 -2
- package/dist/system/patterns/UiProfileCard/index.d.ts +7 -0
- package/dist/system/patterns/UiTopBar/UiTopBar.vue.d.ts +23 -0
- package/dist/system/patterns/UiTopBar/index.d.ts +2 -0
- package/dist/system/patterns/UiTopBar/types.d.ts +28 -0
- package/dist/system/patterns/index.d.ts +2 -0
- package/dist/system/story-sidebar-icons.json +7 -1
- package/docs/public-docs/foundations.md +17 -15
- package/package.json +4 -3
- package/src/__tests__/test-utils.ts +74 -0
- package/src/components/UiAutocomplete/UiAutocomplete.stories.ts +94 -0
- package/src/components/UiAutocomplete/UiAutocomplete.vue +164 -44
- package/src/components/UiAutocomplete/__tests__/UiAutocompleteVirtualized.test.ts +107 -0
- package/src/components/UiAutocomplete/types.ts +11 -0
- package/src/components/UiCodeBlock/UiCodeBlock.stories.ts +54 -0
- package/src/components/UiCodeBlock/UiCodeBlock.vue +84 -32
- package/src/components/UiCodeBlock/__tests__/UiCodeBlock.test.ts +65 -21
- package/src/components/UiDropdownMenu/UiDropdownMenu.stories.ts +760 -0
- package/src/components/UiFadeMask/UiFadeMask.stories.ts +563 -0
- package/src/components/UiFadeMask/UiFadeMask.vue +86 -0
- package/src/components/UiFadeMask/__tests__/UiFadeMask.test.ts +52 -0
- package/src/components/UiFadeMask/index.ts +6 -0
- package/src/components/UiFadeMask/types.ts +35 -0
- package/src/components/UiFileItem/UiFileItem.vue +17 -4
- package/src/components/UiFileItem/__tests__/UiFileItem.test.ts +49 -90
- package/src/components/UiFileType/UiFileType.stories.ts +13 -2
- package/src/components/UiFileType/UiFileType.vue +8 -0
- package/src/components/UiFileType/__tests__/UiFileType.test.ts +10 -0
- package/src/components/UiFileType/types.ts +3 -1
- package/src/components/UiListbox/UiListbox.stories.ts +121 -0
- package/src/components/UiListbox/UiListboxVirtualizer.vue +42 -0
- package/src/components/UiListbox/__tests__/UiListboxVirtualizer.test.ts +96 -0
- package/src/components/UiListbox/index.ts +1 -0
- package/src/components/UiListbox/types.ts +42 -0
- package/src/components/UiSelect/UiSelect.stories.ts +109 -1
- package/src/components/UiSelect/UiSelectVirtualizer.vue +373 -0
- package/src/components/UiSelect/__tests__/UiSelectVirtualizer.test.ts +185 -0
- package/src/components/UiSelect/index.ts +1 -0
- package/src/components/UiSelect/types.ts +38 -0
- package/src/components/UiSnackbar/UiSnackbar.stories.ts +4 -5
- package/src/components/UiSwitch/UiSwitch.stories.ts +658 -7
- package/src/components/UiSwitch/UiSwitch.vue +1 -0
- package/src/components/UiSwitch/__tests__/UiSwitch.test.ts +48 -0
- package/src/components/UiSwitch/types.ts +13 -0
- package/src/components/UiToggleGroup/UiToggleGroup.vue +1 -1
- package/src/components/core/dropdown-menu/DropdownMenuCheckboxItem.vue +8 -2
- package/src/components/core/dropdown-menu/DropdownMenuItem.vue +1 -1
- package/src/components/core/dropdown-menu/DropdownMenuRadioItem.vue +8 -2
- package/src/components/core/dropdown-menu/DropdownMenuSubTrigger.vue +1 -1
- package/src/components/core/field/FieldLabel.vue +1 -1
- package/src/components/core/label/Label.vue +1 -1
- package/src/components/core/listbox/ListboxItem.vue +1 -1
- package/src/components/core/switch/Switch.vue +23 -17
- package/src/components/core/switch/index.ts +36 -0
- package/src/components/index.ts +1 -0
- package/src/index.ts +3 -0
- package/src/lib/scrollbar.ts +295 -0
- package/src/lib/useAnchorFloat.ts +0 -2
- package/src/lib/useIsTruncated.test.ts +174 -0
- package/src/lib/useIsTruncated.ts +75 -0
- package/src/patterns/UiFileUpload/UiFileItem.stories.ts +1162 -0
- package/src/patterns/UiFileUpload/UiFileUpload.stories.ts +552 -1
- package/src/patterns/UiFileUpload/__tests__/UiFileUpload.test.ts +5 -21
- package/src/patterns/UiFloatActions/UiFloatActionItems.vue +0 -1
- package/src/patterns/UiFloatActions/UiFloatActions.stories.ts +4 -6
- package/src/patterns/UiFloatActions/UiFloatActions.vue +23 -12
- package/src/patterns/UiFloatActions/__tests__/UiFloatActions.test.ts +23 -0
- package/src/patterns/UiFloatActions/types.ts +2 -2
- package/src/patterns/UiProfileCard/UiProfileCard.stories.ts +1079 -0
- package/src/patterns/UiProfileCard/index.ts +7 -0
- package/src/patterns/UiTopBar/UiTopBar.stories.ts +1121 -0
- package/src/patterns/UiTopBar/UiTopBar.vue +166 -0
- package/src/patterns/UiTopBar/__tests__/UiTopBar.test.ts +245 -0
- package/src/patterns/UiTopBar/index.ts +2 -0
- package/src/patterns/UiTopBar/types.ts +29 -0
- package/src/patterns/index.ts +2 -0
- package/src/theme/Background.stories.ts +27 -1
- package/src/theme/BorderRadius.stories.ts +5 -0
- package/src/theme/Overlay.stories.ts +12 -1
- package/src/theme/Scrollbar.stories.ts +260 -0
- package/tokens.json +224 -2
- package/src/components/UiFileItem/UiFileItem.stories.ts +0 -442
|
@@ -0,0 +1,1162 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/vue3-vite';
|
|
2
|
+
import { expect, fn, userEvent, within } from 'storybook/test';
|
|
3
|
+
import { UiFileItem } from '@/components/UiFileItem';
|
|
4
|
+
|
|
5
|
+
// `UiFileItem` emits `remove` with no payload and declares no handler prop, so
|
|
6
|
+
// the plays bind a module-level spy via `@remove` and clear it per story.
|
|
7
|
+
const onRemove = fn();
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* `UiFileItem` is a single-row primitive that represents a file with
|
|
11
|
+
* optional progress, error, and a remove control. It is part of the
|
|
12
|
+
* `UiFileUpload` pattern: pair it with `UiFileUpload` to list picked files,
|
|
13
|
+
* or use it stand-alone in any attachment list.
|
|
14
|
+
*/
|
|
15
|
+
const meta: Meta<typeof UiFileItem> = {
|
|
16
|
+
title: 'Patterns/UiFileUpload/UiFileItem',
|
|
17
|
+
component: UiFileItem,
|
|
18
|
+
tags: ['autodocs'],
|
|
19
|
+
args: {
|
|
20
|
+
filename: 'document.pdf',
|
|
21
|
+
typeLabel: 'PDF',
|
|
22
|
+
sizeLabel: '1.2 MB',
|
|
23
|
+
progress: null,
|
|
24
|
+
error: '',
|
|
25
|
+
disabled: false,
|
|
26
|
+
removable: true,
|
|
27
|
+
removeLabel: 'Remove file',
|
|
28
|
+
progressLabel: undefined,
|
|
29
|
+
size: 'default',
|
|
30
|
+
mediaTone: undefined,
|
|
31
|
+
mediaIcon: undefined,
|
|
32
|
+
},
|
|
33
|
+
argTypes: {
|
|
34
|
+
progress: { control: { type: 'number', min: 0, max: 100 } },
|
|
35
|
+
error: {
|
|
36
|
+
control: 'text',
|
|
37
|
+
description:
|
|
38
|
+
'Error text. When non-empty the row enters the error state and replaces the type/size meta.',
|
|
39
|
+
},
|
|
40
|
+
removable: {
|
|
41
|
+
control: 'boolean',
|
|
42
|
+
description:
|
|
43
|
+
'When false, the close icon is not rendered. Use for read-only previews.',
|
|
44
|
+
},
|
|
45
|
+
size: {
|
|
46
|
+
control: 'select',
|
|
47
|
+
options: ['default', 'small'],
|
|
48
|
+
description:
|
|
49
|
+
'`default` (12px padding, 14px title) for stand-alone uploader rows; `small` (8px padding, 12px title) for compact attachments next to a chat message.',
|
|
50
|
+
},
|
|
51
|
+
mediaTone: {
|
|
52
|
+
control: 'select',
|
|
53
|
+
options: [
|
|
54
|
+
undefined,
|
|
55
|
+
'default',
|
|
56
|
+
'accent-pink',
|
|
57
|
+
'accent-soft',
|
|
58
|
+
'accent-yellow',
|
|
59
|
+
'accent-orange',
|
|
60
|
+
],
|
|
61
|
+
description:
|
|
62
|
+
'Color tone of the round media badge. Leave undefined to auto-derive from the filename extension (pdf/docx/txt → pink, html/md → soft, csv/xls/tsv → yellow, mp4/mov/webm → orange); pass an explicit value to force a tone.',
|
|
63
|
+
},
|
|
64
|
+
mediaIcon: {
|
|
65
|
+
control: 'text',
|
|
66
|
+
description:
|
|
67
|
+
'Lucide icon name rendered inside the media badge. Leave empty to auto-derive from the filename extension. Ignored in the error state.',
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
decorators: [
|
|
71
|
+
() => ({
|
|
72
|
+
template: '<div class="max-w-md p-4"><story /></div>',
|
|
73
|
+
}),
|
|
74
|
+
],
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export default meta;
|
|
78
|
+
type Story = StoryObj<typeof UiFileItem>;
|
|
79
|
+
|
|
80
|
+
const renderArgs = (args: Story['args']) => ({
|
|
81
|
+
components: { UiFileItem },
|
|
82
|
+
setup() {
|
|
83
|
+
const normalized = {
|
|
84
|
+
...args,
|
|
85
|
+
mediaIcon: args?.mediaIcon || undefined,
|
|
86
|
+
mediaTone: args?.mediaTone || undefined,
|
|
87
|
+
};
|
|
88
|
+
return { args: normalized, onRemove };
|
|
89
|
+
},
|
|
90
|
+
template: '<UiFileItem v-bind="args" @remove="onRemove" />',
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const defaultTemplateSource = `<script setup lang="ts">
|
|
94
|
+
import { UiFileItem } from '@aleph-alpha/ui-library'
|
|
95
|
+
|
|
96
|
+
const onRemove = () => undefined;
|
|
97
|
+
</script>
|
|
98
|
+
|
|
99
|
+
<template>
|
|
100
|
+
<UiFileItem
|
|
101
|
+
filename="document.pdf"
|
|
102
|
+
type-label="PDF"
|
|
103
|
+
size-label="1.2 MB"
|
|
104
|
+
@remove="onRemove"
|
|
105
|
+
/>
|
|
106
|
+
</template>`;
|
|
107
|
+
|
|
108
|
+
/** Interactive playground; toggle controls to switch between states and sizes. */
|
|
109
|
+
export const Default: Story = {
|
|
110
|
+
render: renderArgs,
|
|
111
|
+
parameters: {
|
|
112
|
+
docs: { source: { code: defaultTemplateSource } },
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const defaultWithProgressTemplateSource = `<script setup lang="ts">
|
|
117
|
+
import { UiFileItem } from '@aleph-alpha/ui-library'
|
|
118
|
+
|
|
119
|
+
const onRemove = () => undefined;
|
|
120
|
+
</script>
|
|
121
|
+
|
|
122
|
+
<template>
|
|
123
|
+
<UiFileItem
|
|
124
|
+
filename="Filename.pdf"
|
|
125
|
+
:progress="30"
|
|
126
|
+
@remove="onRemove"
|
|
127
|
+
/>
|
|
128
|
+
</template>`;
|
|
129
|
+
|
|
130
|
+
/** Upload in progress (0–100). */
|
|
131
|
+
export const DefaultWithProgress: Story = {
|
|
132
|
+
args: {
|
|
133
|
+
filename: 'Filename.pdf',
|
|
134
|
+
typeLabel: undefined,
|
|
135
|
+
sizeLabel: undefined,
|
|
136
|
+
progress: 30,
|
|
137
|
+
error: '',
|
|
138
|
+
size: 'default',
|
|
139
|
+
},
|
|
140
|
+
render: renderArgs,
|
|
141
|
+
parameters: {
|
|
142
|
+
docs: { source: { code: defaultWithProgressTemplateSource } },
|
|
143
|
+
},
|
|
144
|
+
play: async ({ canvasElement, step }) => {
|
|
145
|
+
// Scenario (UiFileItem): an in-flight upload exposes a labelled progress bar
|
|
146
|
+
// so assistive tech can announce which file is transferring and how far it
|
|
147
|
+
// has got, instead of leaving the row silent.
|
|
148
|
+
const canvas = within(canvasElement);
|
|
149
|
+
|
|
150
|
+
await step(
|
|
151
|
+
'screen-reader: the progress bar is named after the file and reports its value (WCAG 4.1.2)',
|
|
152
|
+
async () => {
|
|
153
|
+
const bar = canvas.getByRole('progressbar', { name: 'Filename.pdf' });
|
|
154
|
+
await expect(bar).toHaveAttribute('aria-valuenow', '30');
|
|
155
|
+
await expect(bar).toHaveAttribute('aria-valuemax', '100');
|
|
156
|
+
},
|
|
157
|
+
);
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
const defaultSuccessTemplateSource = `<script setup lang="ts">
|
|
162
|
+
import { UiFileItem } from '@aleph-alpha/ui-library'
|
|
163
|
+
|
|
164
|
+
const onRemove = () => undefined;
|
|
165
|
+
</script>
|
|
166
|
+
|
|
167
|
+
<template>
|
|
168
|
+
<UiFileItem
|
|
169
|
+
filename="Filename.pdf"
|
|
170
|
+
type-label="PDF"
|
|
171
|
+
size-label="12 MB"
|
|
172
|
+
@remove="onRemove"
|
|
173
|
+
/>
|
|
174
|
+
</template>`;
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Default size · success. The pink media + `PDF | 12 MB` meta line are
|
|
178
|
+
* driven entirely by the `.pdf` extension auto-detection.
|
|
179
|
+
*/
|
|
180
|
+
export const DefaultSuccess: Story = {
|
|
181
|
+
args: {
|
|
182
|
+
filename: 'Filename.pdf',
|
|
183
|
+
typeLabel: 'PDF',
|
|
184
|
+
sizeLabel: '12 MB',
|
|
185
|
+
progress: null,
|
|
186
|
+
error: '',
|
|
187
|
+
size: 'default',
|
|
188
|
+
},
|
|
189
|
+
render: renderArgs,
|
|
190
|
+
parameters: {
|
|
191
|
+
docs: { source: { code: defaultSuccessTemplateSource } },
|
|
192
|
+
},
|
|
193
|
+
play: async ({ canvasElement, step }) => {
|
|
194
|
+
// Scenario (UiFileItem): a settled row shows the file's basename with the
|
|
195
|
+
// type and size beside it, and hands the file back to the parent when the
|
|
196
|
+
// user clicks remove.
|
|
197
|
+
onRemove.mockClear();
|
|
198
|
+
const canvas = within(canvasElement);
|
|
199
|
+
|
|
200
|
+
await step(
|
|
201
|
+
'interaction: shows the basename without its extension, plus the type and size',
|
|
202
|
+
async () => {
|
|
203
|
+
await expect(canvas.getByText('Filename')).toBeVisible();
|
|
204
|
+
await expect(canvas.getByText('PDF')).toBeVisible();
|
|
205
|
+
await expect(canvas.getByText('12 MB')).toBeVisible();
|
|
206
|
+
},
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
await step(
|
|
210
|
+
'interaction: clicking remove emits the remove event',
|
|
211
|
+
async () => {
|
|
212
|
+
await userEvent.click(
|
|
213
|
+
canvas.getByRole('button', { name: 'Remove file' }),
|
|
214
|
+
);
|
|
215
|
+
await expect(onRemove).toHaveBeenCalledTimes(1);
|
|
216
|
+
},
|
|
217
|
+
);
|
|
218
|
+
},
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
const defaultErrorTemplateSource = `<script setup lang="ts">
|
|
222
|
+
import { UiFileItem } from '@aleph-alpha/ui-library'
|
|
223
|
+
|
|
224
|
+
const onRemove = () => undefined;
|
|
225
|
+
</script>
|
|
226
|
+
|
|
227
|
+
<template>
|
|
228
|
+
<UiFileItem
|
|
229
|
+
filename="Filename.pdf"
|
|
230
|
+
error="Upload failed"
|
|
231
|
+
@remove="onRemove"
|
|
232
|
+
/>
|
|
233
|
+
</template>`;
|
|
234
|
+
|
|
235
|
+
/** Default size · error. CircleAlert media + destructive subtitle text. */
|
|
236
|
+
export const DefaultError: Story = {
|
|
237
|
+
args: {
|
|
238
|
+
filename: 'Filename.pdf',
|
|
239
|
+
typeLabel: undefined,
|
|
240
|
+
sizeLabel: undefined,
|
|
241
|
+
progress: null,
|
|
242
|
+
error: 'Upload failed',
|
|
243
|
+
size: 'default',
|
|
244
|
+
},
|
|
245
|
+
render: renderArgs,
|
|
246
|
+
parameters: {
|
|
247
|
+
docs: { source: { code: defaultErrorTemplateSource } },
|
|
248
|
+
},
|
|
249
|
+
play: async ({ canvasElement, step }) => {
|
|
250
|
+
// Scenario (UiFileItem): a rejected file announces why it failed through a
|
|
251
|
+
// live region, so the reason reaches screen-reader users without them having
|
|
252
|
+
// to hunt for the row.
|
|
253
|
+
const canvas = within(canvasElement);
|
|
254
|
+
|
|
255
|
+
await step(
|
|
256
|
+
'screen-reader: the failure reason is announced via an alert region (WCAG 4.1.3)',
|
|
257
|
+
async () => {
|
|
258
|
+
await expect(canvas.getByRole('alert')).toHaveTextContent(
|
|
259
|
+
'Upload failed',
|
|
260
|
+
);
|
|
261
|
+
},
|
|
262
|
+
);
|
|
263
|
+
},
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
const smallWithProgressTemplateSource = `<script setup lang="ts">
|
|
267
|
+
import { UiFileItem } from '@aleph-alpha/ui-library'
|
|
268
|
+
|
|
269
|
+
const onRemove = () => undefined;
|
|
270
|
+
</script>
|
|
271
|
+
|
|
272
|
+
<template>
|
|
273
|
+
<UiFileItem
|
|
274
|
+
size="small"
|
|
275
|
+
filename="Filename.pdf"
|
|
276
|
+
:progress="30"
|
|
277
|
+
@remove="onRemove"
|
|
278
|
+
/>
|
|
279
|
+
</template>`;
|
|
280
|
+
|
|
281
|
+
/** Small size · progress at 30%. */
|
|
282
|
+
export const SmallWithProgress: Story = {
|
|
283
|
+
args: {
|
|
284
|
+
filename: 'Filename.pdf',
|
|
285
|
+
typeLabel: undefined,
|
|
286
|
+
sizeLabel: undefined,
|
|
287
|
+
progress: 30,
|
|
288
|
+
error: '',
|
|
289
|
+
size: 'small',
|
|
290
|
+
},
|
|
291
|
+
render: renderArgs,
|
|
292
|
+
parameters: {
|
|
293
|
+
docs: { source: { code: smallWithProgressTemplateSource } },
|
|
294
|
+
},
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
const smallSuccessTemplateSource = `<script setup lang="ts">
|
|
298
|
+
import { UiFileItem } from '@aleph-alpha/ui-library'
|
|
299
|
+
|
|
300
|
+
const onRemove = () => undefined;
|
|
301
|
+
</script>
|
|
302
|
+
|
|
303
|
+
<template>
|
|
304
|
+
<UiFileItem
|
|
305
|
+
size="small"
|
|
306
|
+
filename="quarterly-report.csv"
|
|
307
|
+
type-label="CSV"
|
|
308
|
+
size-label="320 KB"
|
|
309
|
+
@remove="onRemove"
|
|
310
|
+
/>
|
|
311
|
+
</template>`;
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Small size · success. Yellow media + `table-2` icon are derived from the
|
|
315
|
+
* `.csv` filename
|
|
316
|
+
*/
|
|
317
|
+
export const SmallSuccess: Story = {
|
|
318
|
+
args: {
|
|
319
|
+
filename: 'quarterly-report.csv',
|
|
320
|
+
typeLabel: 'CSV',
|
|
321
|
+
sizeLabel: '320 KB',
|
|
322
|
+
progress: null,
|
|
323
|
+
error: '',
|
|
324
|
+
size: 'small',
|
|
325
|
+
},
|
|
326
|
+
render: renderArgs,
|
|
327
|
+
parameters: {
|
|
328
|
+
docs: { source: { code: smallSuccessTemplateSource } },
|
|
329
|
+
},
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
const smallErrorTemplateSource = `<script setup lang="ts">
|
|
333
|
+
import { UiFileItem } from '@aleph-alpha/ui-library'
|
|
334
|
+
|
|
335
|
+
const onRemove = () => undefined;
|
|
336
|
+
</script>
|
|
337
|
+
|
|
338
|
+
<template>
|
|
339
|
+
<UiFileItem
|
|
340
|
+
size="small"
|
|
341
|
+
filename="Filename.pdf"
|
|
342
|
+
error="Upload failed"
|
|
343
|
+
@remove="onRemove"
|
|
344
|
+
/>
|
|
345
|
+
</template>`;
|
|
346
|
+
|
|
347
|
+
/** Small size · error. CircleAlert media + destructive subtitle. */
|
|
348
|
+
export const SmallError: Story = {
|
|
349
|
+
args: {
|
|
350
|
+
filename: 'Filename.pdf',
|
|
351
|
+
typeLabel: undefined,
|
|
352
|
+
sizeLabel: undefined,
|
|
353
|
+
progress: null,
|
|
354
|
+
error: 'Upload failed',
|
|
355
|
+
size: 'small',
|
|
356
|
+
},
|
|
357
|
+
render: renderArgs,
|
|
358
|
+
parameters: {
|
|
359
|
+
docs: { source: { code: smallErrorTemplateSource } },
|
|
360
|
+
},
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
const nonRemovableTemplateSource = `<script setup lang="ts">
|
|
364
|
+
import { UiFileItem } from '@aleph-alpha/ui-library'
|
|
365
|
+
</script>
|
|
366
|
+
|
|
367
|
+
<template>
|
|
368
|
+
<UiFileItem
|
|
369
|
+
filename="release-notes.md"
|
|
370
|
+
type-label="MD"
|
|
371
|
+
size-label="14 KB"
|
|
372
|
+
:removable="false"
|
|
373
|
+
/>
|
|
374
|
+
</template>`;
|
|
375
|
+
|
|
376
|
+
/** Read-only preview: no close icon. */
|
|
377
|
+
export const NonRemovable: Story = {
|
|
378
|
+
args: {
|
|
379
|
+
filename: 'release-notes.md',
|
|
380
|
+
typeLabel: 'MD',
|
|
381
|
+
sizeLabel: '14 KB',
|
|
382
|
+
progress: null,
|
|
383
|
+
error: '',
|
|
384
|
+
disabled: false,
|
|
385
|
+
removable: false,
|
|
386
|
+
},
|
|
387
|
+
render: renderArgs,
|
|
388
|
+
parameters: {
|
|
389
|
+
docs: { source: { code: nonRemovableTemplateSource } },
|
|
390
|
+
},
|
|
391
|
+
play: async ({ canvasElement, step }) => {
|
|
392
|
+
// Scenario (UiFileItem): a read-only attachment list offers no way to detach
|
|
393
|
+
// the file, so the remove control must be absent from the accessibility tree
|
|
394
|
+
// rather than merely hidden.
|
|
395
|
+
const canvas = within(canvasElement);
|
|
396
|
+
|
|
397
|
+
await step(
|
|
398
|
+
'interaction: omits the remove control entirely when removable is false',
|
|
399
|
+
async () => {
|
|
400
|
+
await expect(
|
|
401
|
+
canvas.queryByRole('button', { name: 'Remove file' }),
|
|
402
|
+
).not.toBeInTheDocument();
|
|
403
|
+
},
|
|
404
|
+
);
|
|
405
|
+
},
|
|
406
|
+
};
|
|
407
|
+
|
|
408
|
+
const disabledTemplateSource = `<script setup lang="ts">
|
|
409
|
+
import { UiFileItem } from '@aleph-alpha/ui-library'
|
|
410
|
+
|
|
411
|
+
const onRemove = () => undefined;
|
|
412
|
+
</script>
|
|
413
|
+
|
|
414
|
+
<template>
|
|
415
|
+
<UiFileItem
|
|
416
|
+
filename="locked.pdf"
|
|
417
|
+
type-label="PDF"
|
|
418
|
+
size-label="2 MB"
|
|
419
|
+
disabled
|
|
420
|
+
@remove="onRemove"
|
|
421
|
+
/>
|
|
422
|
+
</template>`;
|
|
423
|
+
|
|
424
|
+
/** Disabled row: inert + 50% opacity, remove control disabled. */
|
|
425
|
+
export const Disabled: Story = {
|
|
426
|
+
args: {
|
|
427
|
+
filename: 'locked.pdf',
|
|
428
|
+
typeLabel: 'PDF',
|
|
429
|
+
sizeLabel: '2 MB',
|
|
430
|
+
progress: null,
|
|
431
|
+
error: '',
|
|
432
|
+
disabled: true,
|
|
433
|
+
},
|
|
434
|
+
render: renderArgs,
|
|
435
|
+
parameters: {
|
|
436
|
+
docs: { source: { code: disabledTemplateSource } },
|
|
437
|
+
},
|
|
438
|
+
play: async ({ canvasElement, step }) => {
|
|
439
|
+
// Scenario (UiFileItem): a locked row must refuse removal — the control reads
|
|
440
|
+
// as disabled and a click that bypasses `pointer-events: none` still emits
|
|
441
|
+
// nothing.
|
|
442
|
+
onRemove.mockClear();
|
|
443
|
+
const canvas = within(canvasElement);
|
|
444
|
+
|
|
445
|
+
await step(
|
|
446
|
+
'interaction: the remove control is disabled and swallows clicks (WCAG 4.1.2)',
|
|
447
|
+
async () => {
|
|
448
|
+
const remove = canvas.getByRole('button', { name: 'Remove file' });
|
|
449
|
+
await expect(remove).toBeDisabled();
|
|
450
|
+
// A disabled UiButton sets `pointer-events: none`, which makes
|
|
451
|
+
// `userEvent.click` throw instead of no-op; bypass the check so the
|
|
452
|
+
// guard itself is what gets asserted.
|
|
453
|
+
await userEvent.click(remove, { pointerEventsCheck: 0 });
|
|
454
|
+
await expect(onRemove).not.toHaveBeenCalled();
|
|
455
|
+
},
|
|
456
|
+
);
|
|
457
|
+
},
|
|
458
|
+
};
|
|
459
|
+
|
|
460
|
+
const allVariantsTemplateSource = `<script setup lang="ts">
|
|
461
|
+
import { UiFileItem } from '@aleph-alpha/ui-library'
|
|
462
|
+
|
|
463
|
+
const onRemove = () => undefined;
|
|
464
|
+
</script>
|
|
465
|
+
|
|
466
|
+
<template>
|
|
467
|
+
<div class="flex flex-wrap gap-8">
|
|
468
|
+
<div class="flex max-w-md flex-1 flex-col gap-3">
|
|
469
|
+
<p class="label-12-medium text-content-on-surface-muted">Default size</p>
|
|
470
|
+
<UiFileItem filename="Filename.pdf" :progress="30" @remove="onRemove" />
|
|
471
|
+
<UiFileItem
|
|
472
|
+
filename="Filename.pdf"
|
|
473
|
+
type-label="PDF"
|
|
474
|
+
size-label="12 MB"
|
|
475
|
+
@remove="onRemove"
|
|
476
|
+
/>
|
|
477
|
+
<UiFileItem filename="Filename.pdf" error="Upload failed" @remove="onRemove" />
|
|
478
|
+
</div>
|
|
479
|
+
<div class="flex max-w-64 flex-1 flex-col gap-3">
|
|
480
|
+
<p class="label-12-medium text-content-on-surface-muted">Small size</p>
|
|
481
|
+
<UiFileItem size="small" filename="Filename.pdf" :progress="30" @remove="onRemove" />
|
|
482
|
+
<UiFileItem
|
|
483
|
+
size="small"
|
|
484
|
+
filename="Filename.pdf"
|
|
485
|
+
type-label="PDF"
|
|
486
|
+
size-label="12 MB"
|
|
487
|
+
@remove="onRemove"
|
|
488
|
+
/>
|
|
489
|
+
<UiFileItem size="small" filename="Filename.pdf" error="Upload failed" @remove="onRemove" />
|
|
490
|
+
</div>
|
|
491
|
+
</div>
|
|
492
|
+
</template>`;
|
|
493
|
+
|
|
494
|
+
const allFileTypesTemplateSource = `<script setup lang="ts">
|
|
495
|
+
import { UiFileItem } from '@aleph-alpha/ui-library'
|
|
496
|
+
|
|
497
|
+
const onRemove = () => undefined;
|
|
498
|
+
</script>
|
|
499
|
+
|
|
500
|
+
<template>
|
|
501
|
+
<div class="flex max-w-md flex-col gap-3">
|
|
502
|
+
<UiFileItem filename="Filename.pdf" type-label="PDF" size-label="12 MB" @remove="onRemove" />
|
|
503
|
+
<UiFileItem filename="Filename.md" type-label="MD" size-label="12 MB" @remove="onRemove" />
|
|
504
|
+
<UiFileItem filename="Filename.csv" type-label="CSV" size-label="12 MB" @remove="onRemove" />
|
|
505
|
+
<UiFileItem filename="Filename.mp4" type-label="MP4" size-label="12 MB" @remove="onRemove" />
|
|
506
|
+
<UiFileItem filename="Filename.zip" type-label="ZIP" size-label="12 MB" @remove="onRemove" />
|
|
507
|
+
</div>
|
|
508
|
+
</template>`;
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* One row per `UiFileType` group, with the media badge and icon derived purely
|
|
512
|
+
* from the extension: `.pdf` → pink `file`, `.md` → soft `code-xml`,
|
|
513
|
+
* `.csv` → yellow `table-2`, `.mp4` → orange `image-play`, and any unmapped
|
|
514
|
+
* extension (`.zip`) → the neutral `default` fallback.
|
|
515
|
+
*/
|
|
516
|
+
export const AllFileTypes: Story = {
|
|
517
|
+
parameters: {
|
|
518
|
+
controls: { disable: true },
|
|
519
|
+
docs: { source: { code: allFileTypesTemplateSource } },
|
|
520
|
+
},
|
|
521
|
+
decorators: [
|
|
522
|
+
() => ({
|
|
523
|
+
template: '<div class="p-6"><story /></div>',
|
|
524
|
+
}),
|
|
525
|
+
],
|
|
526
|
+
render: () => ({
|
|
527
|
+
components: { UiFileItem },
|
|
528
|
+
setup() {
|
|
529
|
+
const files = [
|
|
530
|
+
{ filename: 'Filename.pdf', typeLabel: 'PDF' },
|
|
531
|
+
{ filename: 'Filename.md', typeLabel: 'MD' },
|
|
532
|
+
{ filename: 'Filename.csv', typeLabel: 'CSV' },
|
|
533
|
+
{ filename: 'Filename.mp4', typeLabel: 'MP4' },
|
|
534
|
+
{ filename: 'Filename.zip', typeLabel: 'ZIP' },
|
|
535
|
+
];
|
|
536
|
+
return { files, onRemove };
|
|
537
|
+
},
|
|
538
|
+
template: `
|
|
539
|
+
<div class="flex max-w-md flex-col gap-3">
|
|
540
|
+
<UiFileItem
|
|
541
|
+
v-for="file in files"
|
|
542
|
+
:key="file.filename"
|
|
543
|
+
:filename="file.filename"
|
|
544
|
+
:type-label="file.typeLabel"
|
|
545
|
+
size-label="12 MB"
|
|
546
|
+
@remove="onRemove"
|
|
547
|
+
/>
|
|
548
|
+
</div>
|
|
549
|
+
`,
|
|
550
|
+
}),
|
|
551
|
+
play: async ({ canvasElement, step }) => {
|
|
552
|
+
// Scenario (UiFileItem): the media badge's colour and icon are derived from
|
|
553
|
+
// the extension alone, so a caller gets the right treatment per file family
|
|
554
|
+
// without passing `mediaTone`/`mediaIcon` — and an unknown extension falls
|
|
555
|
+
// back to the neutral badge instead of rendering untreated.
|
|
556
|
+
const canvas = within(canvasElement);
|
|
557
|
+
|
|
558
|
+
await step(
|
|
559
|
+
'interaction: each extension resolves to its UiFileType tone, with a neutral fallback',
|
|
560
|
+
async () => {
|
|
561
|
+
const tones = Array.from(
|
|
562
|
+
canvasElement.querySelectorAll('[data-slot="file-type"]'),
|
|
563
|
+
).map((badge) => badge.getAttribute('data-tone'));
|
|
564
|
+
await expect(tones).toEqual([
|
|
565
|
+
'accent-pink',
|
|
566
|
+
'accent-soft',
|
|
567
|
+
'accent-yellow',
|
|
568
|
+
'accent-orange',
|
|
569
|
+
'default',
|
|
570
|
+
]);
|
|
571
|
+
},
|
|
572
|
+
);
|
|
573
|
+
|
|
574
|
+
await step(
|
|
575
|
+
'screen-reader: the badge is decorative, so the type label carries the meaning',
|
|
576
|
+
async () => {
|
|
577
|
+
// Colour alone must not encode the file family (WCAG 1.4.1): the badges
|
|
578
|
+
// are `aria-hidden`, and each row states its type as text.
|
|
579
|
+
for (const badge of canvasElement.querySelectorAll(
|
|
580
|
+
'[data-slot="file-type"]',
|
|
581
|
+
)) {
|
|
582
|
+
await expect(badge).toHaveAttribute('aria-hidden', 'true');
|
|
583
|
+
}
|
|
584
|
+
for (const label of ['PDF', 'MD', 'CSV', 'MP4', 'ZIP']) {
|
|
585
|
+
await expect(canvas.getByText(label)).toBeVisible();
|
|
586
|
+
}
|
|
587
|
+
},
|
|
588
|
+
);
|
|
589
|
+
},
|
|
590
|
+
};
|
|
591
|
+
|
|
592
|
+
/** All variants in one column for quick visual comparison. */
|
|
593
|
+
export const AllVariants: Story = {
|
|
594
|
+
parameters: {
|
|
595
|
+
controls: { disable: true },
|
|
596
|
+
docs: { source: { code: allVariantsTemplateSource } },
|
|
597
|
+
},
|
|
598
|
+
decorators: [
|
|
599
|
+
() => ({
|
|
600
|
+
template: '<div class="p-6"><story /></div>',
|
|
601
|
+
}),
|
|
602
|
+
],
|
|
603
|
+
render: () => ({
|
|
604
|
+
components: { UiFileItem },
|
|
605
|
+
setup() {
|
|
606
|
+
return { onRemove };
|
|
607
|
+
},
|
|
608
|
+
template: `
|
|
609
|
+
<div class="flex flex-wrap gap-8">
|
|
610
|
+
<div class="flex max-w-md flex-1 flex-col gap-3">
|
|
611
|
+
<p class="label-12-medium text-content-on-surface-muted">Default size</p>
|
|
612
|
+
<UiFileItem filename="Filename.pdf" :progress="30" @remove="onRemove" />
|
|
613
|
+
<UiFileItem
|
|
614
|
+
filename="Filename.pdf"
|
|
615
|
+
type-label="PDF"
|
|
616
|
+
size-label="12 MB"
|
|
617
|
+
@remove="onRemove"
|
|
618
|
+
/>
|
|
619
|
+
<UiFileItem filename="Filename.pdf" error="Upload failed" @remove="onRemove" />
|
|
620
|
+
</div>
|
|
621
|
+
<div class="flex max-w-64 flex-1 flex-col gap-3">
|
|
622
|
+
<p class="label-12-medium text-content-on-surface-muted">Small size</p>
|
|
623
|
+
<UiFileItem size="small" filename="Filename.pdf" :progress="30" @remove="onRemove" />
|
|
624
|
+
<UiFileItem
|
|
625
|
+
size="small"
|
|
626
|
+
filename="Filename.pdf"
|
|
627
|
+
type-label="PDF"
|
|
628
|
+
size-label="12 MB"
|
|
629
|
+
@remove="onRemove"
|
|
630
|
+
/>
|
|
631
|
+
<UiFileItem size="small" filename="Filename.pdf" error="Upload failed" @remove="onRemove" />
|
|
632
|
+
</div>
|
|
633
|
+
</div>
|
|
634
|
+
`,
|
|
635
|
+
}),
|
|
636
|
+
};
|
|
637
|
+
|
|
638
|
+
/**
|
|
639
|
+
* Accessibility guidance for file rows and accessible theme usage.
|
|
640
|
+
*/
|
|
641
|
+
export const Accessibility: Story = {
|
|
642
|
+
render: () => ({
|
|
643
|
+
components: { UiFileItem },
|
|
644
|
+
setup() {
|
|
645
|
+
return { onRemove };
|
|
646
|
+
},
|
|
647
|
+
template: `
|
|
648
|
+
<section class="flex flex-col gap-6 p-4">
|
|
649
|
+
<div>
|
|
650
|
+
<h2 class="heading-m font-bold text-content-on-surface-primary">
|
|
651
|
+
Accessibility
|
|
652
|
+
</h2>
|
|
653
|
+
</div>
|
|
654
|
+
|
|
655
|
+
<div class="flex flex-col gap-6">
|
|
656
|
+
<div class="flex flex-col gap-2">
|
|
657
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
658
|
+
Enable accessibility theme
|
|
659
|
+
</h3>
|
|
660
|
+
<p class="body-16-regular text-content-on-surface-primary">
|
|
661
|
+
When accessibility is required, enable our accessibility theme. This increases contrast and makes sure there are no color contrast issues.
|
|
662
|
+
</p>
|
|
663
|
+
</div>
|
|
664
|
+
|
|
665
|
+
<div class="flex flex-col gap-2">
|
|
666
|
+
<h3 class="body-16-medium text-content-on-surface-primary">
|
|
667
|
+
Never rely on the media badge alone
|
|
668
|
+
</h3>
|
|
669
|
+
<p class="body-16-regular text-content-on-surface-primary">
|
|
670
|
+
The round media badge is decorative and hidden from assistive tech, so the file family must also be stated in text. In the accessibility theme the media badge for video resolves to the same yellow as tabular files, which is why every row keeps its type label and its own icon.
|
|
671
|
+
</p>
|
|
672
|
+
</div>
|
|
673
|
+
</div>
|
|
674
|
+
|
|
675
|
+
<div class="flex flex-col gap-3">
|
|
676
|
+
<h3 class="label-16-medium text-content-on-surface-primary">
|
|
677
|
+
Default
|
|
678
|
+
</h3>
|
|
679
|
+
<div class="flex flex-col gap-3 border border-border-surface-default p-4">
|
|
680
|
+
<UiFileItem filename="Quarterly report.csv" type-label="CSV" size-label="320 KB" @remove="onRemove" />
|
|
681
|
+
<UiFileItem filename="Product tour.mp4" type-label="MP4" size-label="18 MB" @remove="onRemove" />
|
|
682
|
+
</div>
|
|
683
|
+
</div>
|
|
684
|
+
|
|
685
|
+
<div class="accessible-theme flex flex-col gap-3">
|
|
686
|
+
<h3 class="label-16-medium text-content-on-surface-primary">
|
|
687
|
+
Accessible
|
|
688
|
+
</h3>
|
|
689
|
+
<div class="flex flex-col gap-3 border border-border-surface-default p-4">
|
|
690
|
+
<UiFileItem filename="Quarterly report.csv" type-label="CSV" size-label="320 KB" @remove="onRemove" />
|
|
691
|
+
<UiFileItem filename="Product tour.mp4" type-label="MP4" size-label="18 MB" @remove="onRemove" />
|
|
692
|
+
</div>
|
|
693
|
+
</div>
|
|
694
|
+
</section>
|
|
695
|
+
`,
|
|
696
|
+
}),
|
|
697
|
+
tags: ['!autodocs'],
|
|
698
|
+
parameters: {
|
|
699
|
+
a11y: { test: 'off' },
|
|
700
|
+
chromatic: {
|
|
701
|
+
disableSnapshot: true,
|
|
702
|
+
},
|
|
703
|
+
docs: {
|
|
704
|
+
canvas: {
|
|
705
|
+
sourceState: 'none',
|
|
706
|
+
},
|
|
707
|
+
},
|
|
708
|
+
},
|
|
709
|
+
};
|
|
710
|
+
|
|
711
|
+
/*
|
|
712
|
+
* ─────────────────────────────────────────────────────────────────────────────
|
|
713
|
+
* Interaction & accessibility tests (play functions)
|
|
714
|
+
* ─────────────────────────────────────────────────────────────────────────────
|
|
715
|
+
* How these tests are built and reported:
|
|
716
|
+
*
|
|
717
|
+
* - Non-mutating checks are co-located on the visible stories that already
|
|
718
|
+
* render the state (`DefaultSuccess`, `DefaultWithProgress`, `DefaultError`,
|
|
719
|
+
* `NonRemovable`, `Disabled`, `AllFileTypes`), so their Chromatic snapshots
|
|
720
|
+
* stay valid. Flows that move focus or rescale the layout live in the hidden
|
|
721
|
+
* `test - …` stories below.
|
|
722
|
+
* - Assertions are grouped into category-labelled `step()` calls, which are
|
|
723
|
+
* parsed statically into the per-story CI summary. Between them these stories
|
|
724
|
+
* cover every report column:
|
|
725
|
+
* • `interaction:` state precedence, remove guards, emitted events
|
|
726
|
+
* • `keyboard:` Tab order, Enter / Space activation (WCAG 2.1.1)
|
|
727
|
+
* • `screen-reader:` names, alert region, progress value (WCAG 4.1.2/4.1.3)
|
|
728
|
+
* • `zoom:` usable at 200% page zoom (WCAG 1.4.4)
|
|
729
|
+
* • `mobile:` 320px reflow + touch-target size (WCAG 1.4.10, 2.5.8)
|
|
730
|
+
* The Accessibility column is filled automatically by the axe audit that runs
|
|
731
|
+
* on every story — never add an `a11y:` prefix.
|
|
732
|
+
* - Rendering and prop plumbing that needs no browser (surface classes, dotfile
|
|
733
|
+
* basenames) stays in Vitest under `src/components/UiFileItem/__tests__/`.
|
|
734
|
+
* ─────────────────────────────────────────────────────────────────────────────
|
|
735
|
+
*/
|
|
736
|
+
|
|
737
|
+
/**
|
|
738
|
+
* The row shows exactly one of progress, error, or the type/size meta — progress
|
|
739
|
+
* and error both take precedence over the meta line. Hidden test-only story.
|
|
740
|
+
*/
|
|
741
|
+
export const StatePrecedence: Story = {
|
|
742
|
+
name: 'test - State Precedence',
|
|
743
|
+
tags: ['!dev', '!autodocs'],
|
|
744
|
+
parameters: {
|
|
745
|
+
controls: { disable: true },
|
|
746
|
+
docs: {
|
|
747
|
+
description: {
|
|
748
|
+
story:
|
|
749
|
+
'Each row is given both `typeLabel` and `sizeLabel`; only the settled row shows them.',
|
|
750
|
+
},
|
|
751
|
+
},
|
|
752
|
+
},
|
|
753
|
+
render: () => ({
|
|
754
|
+
components: { UiFileItem },
|
|
755
|
+
setup() {
|
|
756
|
+
return { onRemove };
|
|
757
|
+
},
|
|
758
|
+
template: `
|
|
759
|
+
<div class="flex flex-col gap-3">
|
|
760
|
+
<UiFileItem
|
|
761
|
+
filename="Report.pdf"
|
|
762
|
+
type-label="PDF"
|
|
763
|
+
size-label="12 MB"
|
|
764
|
+
:progress="40"
|
|
765
|
+
remove-label="Remove Report.pdf"
|
|
766
|
+
@remove="onRemove"
|
|
767
|
+
/>
|
|
768
|
+
<UiFileItem
|
|
769
|
+
filename="Sheet.csv"
|
|
770
|
+
type-label="CSV"
|
|
771
|
+
size-label="8 MB"
|
|
772
|
+
error="Upload failed"
|
|
773
|
+
remove-label="Remove Sheet.csv"
|
|
774
|
+
@remove="onRemove"
|
|
775
|
+
/>
|
|
776
|
+
<UiFileItem
|
|
777
|
+
filename="Notes.md"
|
|
778
|
+
type-label="MD"
|
|
779
|
+
size-label="4 KB"
|
|
780
|
+
remove-label="Remove Notes.md"
|
|
781
|
+
@remove="onRemove"
|
|
782
|
+
/>
|
|
783
|
+
</div>
|
|
784
|
+
`,
|
|
785
|
+
}),
|
|
786
|
+
play: async ({ canvasElement, step }) => {
|
|
787
|
+
// Scenario (UiFileItem): a list mixes uploading, failed, and finished rows.
|
|
788
|
+
// Each row has a type and size available, but only the finished one may show
|
|
789
|
+
// them — otherwise stale meta would sit next to a progress bar or an error.
|
|
790
|
+
const canvas = within(canvasElement);
|
|
791
|
+
|
|
792
|
+
await step(
|
|
793
|
+
'interaction: an in-flight row replaces its meta with the progress bar',
|
|
794
|
+
async () => {
|
|
795
|
+
await expect(
|
|
796
|
+
canvas.getByRole('progressbar', { name: 'Report.pdf' }),
|
|
797
|
+
).toBeVisible();
|
|
798
|
+
await expect(canvas.queryByText('PDF')).not.toBeInTheDocument();
|
|
799
|
+
await expect(canvas.queryByText('12 MB')).not.toBeInTheDocument();
|
|
800
|
+
},
|
|
801
|
+
);
|
|
802
|
+
|
|
803
|
+
await step(
|
|
804
|
+
'interaction: a failed row replaces its meta with the error text',
|
|
805
|
+
async () => {
|
|
806
|
+
await expect(canvas.getByRole('alert')).toHaveTextContent(
|
|
807
|
+
'Upload failed',
|
|
808
|
+
);
|
|
809
|
+
await expect(canvas.queryByText('CSV')).not.toBeInTheDocument();
|
|
810
|
+
await expect(canvas.queryByText('8 MB')).not.toBeInTheDocument();
|
|
811
|
+
},
|
|
812
|
+
);
|
|
813
|
+
|
|
814
|
+
await step(
|
|
815
|
+
'interaction: a settled row keeps its type and size',
|
|
816
|
+
async () => {
|
|
817
|
+
await expect(canvas.getByText('MD')).toBeVisible();
|
|
818
|
+
await expect(canvas.getByText('4 KB')).toBeVisible();
|
|
819
|
+
},
|
|
820
|
+
);
|
|
821
|
+
},
|
|
822
|
+
};
|
|
823
|
+
|
|
824
|
+
/**
|
|
825
|
+
* The remove control is fully keyboard operable: `Tab` moves focus to it and
|
|
826
|
+
* `Enter` / `Space` activate it. Hidden test-only story.
|
|
827
|
+
*/
|
|
828
|
+
export const KeyboardNavigation: Story = {
|
|
829
|
+
name: 'test - Keyboard Navigation',
|
|
830
|
+
tags: ['!dev', '!autodocs'],
|
|
831
|
+
parameters: {
|
|
832
|
+
// Focus moves during the play function; skip the visual snapshot so the
|
|
833
|
+
// focus ring doesn't register as a Chromatic diff.
|
|
834
|
+
chromatic: { disableSnapshot: true },
|
|
835
|
+
controls: { disable: true },
|
|
836
|
+
docs: {
|
|
837
|
+
description: {
|
|
838
|
+
story:
|
|
839
|
+
'Press `Tab` to focus the remove control, then `Enter` or `Space` to activate it.',
|
|
840
|
+
},
|
|
841
|
+
},
|
|
842
|
+
},
|
|
843
|
+
render: () => ({
|
|
844
|
+
components: { UiFileItem },
|
|
845
|
+
setup() {
|
|
846
|
+
return { onRemove };
|
|
847
|
+
},
|
|
848
|
+
template: `
|
|
849
|
+
<UiFileItem
|
|
850
|
+
filename="Filename.pdf"
|
|
851
|
+
type-label="PDF"
|
|
852
|
+
size-label="12 MB"
|
|
853
|
+
@remove="onRemove"
|
|
854
|
+
/>
|
|
855
|
+
`,
|
|
856
|
+
}),
|
|
857
|
+
play: async ({ canvasElement, step }) => {
|
|
858
|
+
// Scenario (UiFileItem): a keyboard-only user detaches a file — the remove
|
|
859
|
+
// control is the row's single tab stop and responds to both activation keys.
|
|
860
|
+
onRemove.mockClear();
|
|
861
|
+
const canvas = within(canvasElement);
|
|
862
|
+
const remove = canvas.getByRole('button', { name: 'Remove file' });
|
|
863
|
+
|
|
864
|
+
await step(
|
|
865
|
+
'keyboard: the remove control is reachable via Tab (WCAG 2.1.1)',
|
|
866
|
+
async () => {
|
|
867
|
+
await userEvent.tab();
|
|
868
|
+
await expect(remove).toHaveFocus();
|
|
869
|
+
},
|
|
870
|
+
);
|
|
871
|
+
|
|
872
|
+
await step('keyboard: activates with Enter', async () => {
|
|
873
|
+
await userEvent.keyboard('{Enter}');
|
|
874
|
+
await expect(onRemove).toHaveBeenCalledTimes(1);
|
|
875
|
+
});
|
|
876
|
+
|
|
877
|
+
await step('keyboard: activates with Space', async () => {
|
|
878
|
+
await userEvent.keyboard(' ');
|
|
879
|
+
await expect(onRemove).toHaveBeenCalledTimes(2);
|
|
880
|
+
});
|
|
881
|
+
},
|
|
882
|
+
};
|
|
883
|
+
|
|
884
|
+
/**
|
|
885
|
+
* Screen-reader semantics: the truncated title still exposes the full filename,
|
|
886
|
+
* the meta divider is decorative, progress and failures are announced, and each
|
|
887
|
+
* remove control names its file. Hidden test-only story.
|
|
888
|
+
*/
|
|
889
|
+
export const ScreenReader: Story = {
|
|
890
|
+
name: 'test - Screen Reader',
|
|
891
|
+
tags: ['!dev', '!autodocs'],
|
|
892
|
+
parameters: {
|
|
893
|
+
controls: { disable: true },
|
|
894
|
+
docs: {
|
|
895
|
+
description: {
|
|
896
|
+
story:
|
|
897
|
+
'Verifies the names, roles, and state that assistive technology announces for a file row.',
|
|
898
|
+
},
|
|
899
|
+
},
|
|
900
|
+
},
|
|
901
|
+
render: () => ({
|
|
902
|
+
components: { UiFileItem },
|
|
903
|
+
setup() {
|
|
904
|
+
return { onRemove };
|
|
905
|
+
},
|
|
906
|
+
template: `
|
|
907
|
+
<div class="flex flex-col gap-3">
|
|
908
|
+
<UiFileItem
|
|
909
|
+
filename="Quarterly report.pdf"
|
|
910
|
+
type-label="PDF"
|
|
911
|
+
size-label="12 MB"
|
|
912
|
+
remove-label="Remove Quarterly report.pdf"
|
|
913
|
+
@remove="onRemove"
|
|
914
|
+
/>
|
|
915
|
+
<UiFileItem
|
|
916
|
+
filename="Product tour.mp4"
|
|
917
|
+
:progress="45"
|
|
918
|
+
progress-label="Uploading Product tour.mp4"
|
|
919
|
+
remove-label="Cancel Product tour.mp4 upload"
|
|
920
|
+
@remove="onRemove"
|
|
921
|
+
/>
|
|
922
|
+
<UiFileItem
|
|
923
|
+
filename="Archive.zip"
|
|
924
|
+
error="Unsupported file type"
|
|
925
|
+
remove-label="Dismiss Archive.zip"
|
|
926
|
+
@remove="onRemove"
|
|
927
|
+
/>
|
|
928
|
+
</div>
|
|
929
|
+
`,
|
|
930
|
+
}),
|
|
931
|
+
play: async ({ canvasElement, step }) => {
|
|
932
|
+
// Scenario (UiFileItem): assistive tech reads the whole filename even though
|
|
933
|
+
// the row displays only the basename, skips the decorative divider, hears the
|
|
934
|
+
// upload's progress and the failure reason, and can tell the three remove
|
|
935
|
+
// controls apart.
|
|
936
|
+
const canvas = within(canvasElement);
|
|
937
|
+
|
|
938
|
+
await step(
|
|
939
|
+
'screen-reader: the title exposes the full filename while displaying the basename',
|
|
940
|
+
async () => {
|
|
941
|
+
const title = canvas.getByLabelText('Quarterly report.pdf');
|
|
942
|
+
await expect(title).toHaveTextContent('Quarterly report');
|
|
943
|
+
},
|
|
944
|
+
);
|
|
945
|
+
|
|
946
|
+
await step(
|
|
947
|
+
'screen-reader: the type/size divider is hidden from assistive tech',
|
|
948
|
+
async () => {
|
|
949
|
+
const divider = canvasElement.querySelector(
|
|
950
|
+
'[data-slot="file-item-meta"] [aria-hidden="true"]',
|
|
951
|
+
);
|
|
952
|
+
await expect(divider).toHaveTextContent('|');
|
|
953
|
+
},
|
|
954
|
+
);
|
|
955
|
+
|
|
956
|
+
await step(
|
|
957
|
+
'screen-reader: each remove control names the file it detaches (WCAG 4.1.2)',
|
|
958
|
+
async () => {
|
|
959
|
+
for (const name of [
|
|
960
|
+
'Remove Quarterly report.pdf',
|
|
961
|
+
'Cancel Product tour.mp4 upload',
|
|
962
|
+
'Dismiss Archive.zip',
|
|
963
|
+
]) {
|
|
964
|
+
await expect(
|
|
965
|
+
canvas.getByRole('button', { name }),
|
|
966
|
+
).toHaveAccessibleName(name);
|
|
967
|
+
}
|
|
968
|
+
},
|
|
969
|
+
);
|
|
970
|
+
|
|
971
|
+
await step(
|
|
972
|
+
'screen-reader: progress is announced with a custom label and value',
|
|
973
|
+
async () => {
|
|
974
|
+
const bar = canvas.getByRole('progressbar', {
|
|
975
|
+
name: 'Uploading Product tour.mp4',
|
|
976
|
+
});
|
|
977
|
+
await expect(bar).toHaveAttribute('aria-valuenow', '45');
|
|
978
|
+
},
|
|
979
|
+
);
|
|
980
|
+
|
|
981
|
+
await step(
|
|
982
|
+
'screen-reader: the failure reason is announced via an alert region (WCAG 4.1.3)',
|
|
983
|
+
async () => {
|
|
984
|
+
await expect(canvas.getByRole('alert')).toHaveTextContent(
|
|
985
|
+
'Unsupported file type',
|
|
986
|
+
);
|
|
987
|
+
},
|
|
988
|
+
);
|
|
989
|
+
},
|
|
990
|
+
};
|
|
991
|
+
|
|
992
|
+
/**
|
|
993
|
+
* Rendered at 200% page zoom (WCAG 1.4.4 Resize Text). Use the Zoom toolbar to
|
|
994
|
+
* try 400% reflow (WCAG 1.4.10); the row must stay visible and operable.
|
|
995
|
+
* Hidden test-only story.
|
|
996
|
+
*/
|
|
997
|
+
export const ZoomMagnification: Story = {
|
|
998
|
+
name: 'test - Zoom Magnification',
|
|
999
|
+
tags: ['!dev', '!autodocs'],
|
|
1000
|
+
globals: { zoom: '200' },
|
|
1001
|
+
parameters: {
|
|
1002
|
+
// The accessible-reflow Chromatic mode already covers magnified snapshots.
|
|
1003
|
+
chromatic: { disableSnapshot: true },
|
|
1004
|
+
controls: { disable: true },
|
|
1005
|
+
docs: {
|
|
1006
|
+
description: {
|
|
1007
|
+
story:
|
|
1008
|
+
'Use the Zoom toolbar (200% resize text, 400% reflow) to magnify the preview.',
|
|
1009
|
+
},
|
|
1010
|
+
},
|
|
1011
|
+
},
|
|
1012
|
+
render: () => ({
|
|
1013
|
+
components: { UiFileItem },
|
|
1014
|
+
setup() {
|
|
1015
|
+
return { onRemove };
|
|
1016
|
+
},
|
|
1017
|
+
template: `
|
|
1018
|
+
<UiFileItem
|
|
1019
|
+
filename="Filename.pdf"
|
|
1020
|
+
type-label="PDF"
|
|
1021
|
+
size-label="12 MB"
|
|
1022
|
+
@remove="onRemove"
|
|
1023
|
+
/>
|
|
1024
|
+
`,
|
|
1025
|
+
}),
|
|
1026
|
+
play: async ({ canvasElement, step }) => {
|
|
1027
|
+
// Scenario (UiFileItem): at 200% page zoom the row keeps its filename and
|
|
1028
|
+
// meta readable and the remove control still works, so a low-vision user can
|
|
1029
|
+
// manage attachments without horizontal scrolling.
|
|
1030
|
+
onRemove.mockClear();
|
|
1031
|
+
const canvas = within(canvasElement);
|
|
1032
|
+
const remove = canvas.getByRole('button', { name: 'Remove file' });
|
|
1033
|
+
|
|
1034
|
+
await step(
|
|
1035
|
+
'zoom: preview is magnified to 200% (WCAG 1.4.4 Resize Text)',
|
|
1036
|
+
async () => {
|
|
1037
|
+
await expect(document.documentElement.style.zoom).toBe('200%');
|
|
1038
|
+
},
|
|
1039
|
+
);
|
|
1040
|
+
|
|
1041
|
+
await step('zoom: the row stays readable when magnified', async () => {
|
|
1042
|
+
await expect(canvas.getByText('Filename')).toBeVisible();
|
|
1043
|
+
await expect(canvas.getByText('PDF')).toBeVisible();
|
|
1044
|
+
await expect(remove).toHaveAccessibleName('Remove file');
|
|
1045
|
+
});
|
|
1046
|
+
|
|
1047
|
+
await step('zoom: the remove control remains operable', async () => {
|
|
1048
|
+
await userEvent.click(remove);
|
|
1049
|
+
await expect(onRemove).toHaveBeenCalledTimes(1);
|
|
1050
|
+
});
|
|
1051
|
+
},
|
|
1052
|
+
};
|
|
1053
|
+
|
|
1054
|
+
/**
|
|
1055
|
+
* Rendered at the mobile (320px reflow) breakpoint via the Media breakpoint
|
|
1056
|
+
* toolbar. The row fits without sideways scrolling and the remove control stays
|
|
1057
|
+
* tappable and keyboard operable. Hidden test-only story.
|
|
1058
|
+
*/
|
|
1059
|
+
export const MobileBreakpoint: Story = {
|
|
1060
|
+
name: 'test - Mobile Breakpoint',
|
|
1061
|
+
tags: ['!dev', '!autodocs'],
|
|
1062
|
+
globals: { mediaBreakpoint: 'reflow' },
|
|
1063
|
+
parameters: {
|
|
1064
|
+
// The play function focuses and activates the remove control; skip the
|
|
1065
|
+
// snapshot. Reflow snapshots are covered by the accessible-reflow mode.
|
|
1066
|
+
chromatic: { disableSnapshot: true },
|
|
1067
|
+
controls: { disable: true },
|
|
1068
|
+
docs: {
|
|
1069
|
+
description: {
|
|
1070
|
+
story:
|
|
1071
|
+
'Switch the Media breakpoint toolbar to Mobile to preview the 320px layout.',
|
|
1072
|
+
},
|
|
1073
|
+
},
|
|
1074
|
+
},
|
|
1075
|
+
render: () => ({
|
|
1076
|
+
components: { UiFileItem },
|
|
1077
|
+
setup() {
|
|
1078
|
+
return { onRemove };
|
|
1079
|
+
},
|
|
1080
|
+
template: `
|
|
1081
|
+
<UiFileItem
|
|
1082
|
+
filename="A rather long quarterly report filename.pdf"
|
|
1083
|
+
type-label="PDF"
|
|
1084
|
+
size-label="12 MB"
|
|
1085
|
+
@remove="onRemove"
|
|
1086
|
+
/>
|
|
1087
|
+
`,
|
|
1088
|
+
}),
|
|
1089
|
+
play: async ({ canvasElement, step }) => {
|
|
1090
|
+
// Scenario (UiFileItem): at 320px a long filename truncates instead of
|
|
1091
|
+
// pushing the row sideways, and the remove control stays big enough to tap
|
|
1092
|
+
// and reachable from the keyboard.
|
|
1093
|
+
onRemove.mockClear();
|
|
1094
|
+
const canvas = within(canvasElement);
|
|
1095
|
+
const remove = canvas.getByRole('button', { name: 'Remove file' });
|
|
1096
|
+
|
|
1097
|
+
await step(
|
|
1098
|
+
'mobile: a long filename truncates rather than overflowing the 320px viewport (WCAG 1.4.10 Reflow)',
|
|
1099
|
+
async () => {
|
|
1100
|
+
await expect(
|
|
1101
|
+
canvasElement.querySelector('[data-slot="file-item"]'),
|
|
1102
|
+
).toBeVisible();
|
|
1103
|
+
// The remove control is the row's right-most element, so its right edge
|
|
1104
|
+
// staying inside the viewport proves the filename truncated instead of
|
|
1105
|
+
// pushing the row sideways.
|
|
1106
|
+
await expect(remove.getBoundingClientRect().right).toBeLessThanOrEqual(
|
|
1107
|
+
window.innerWidth,
|
|
1108
|
+
);
|
|
1109
|
+
},
|
|
1110
|
+
);
|
|
1111
|
+
|
|
1112
|
+
await step(
|
|
1113
|
+
'mobile: the remove control meets the minimum touch-target size (WCAG 2.5.8)',
|
|
1114
|
+
async () => {
|
|
1115
|
+
const { width, height } = remove.getBoundingClientRect();
|
|
1116
|
+
await expect(width).toBeGreaterThanOrEqual(24);
|
|
1117
|
+
await expect(height).toBeGreaterThanOrEqual(24);
|
|
1118
|
+
},
|
|
1119
|
+
);
|
|
1120
|
+
|
|
1121
|
+
await step(
|
|
1122
|
+
'mobile: stays keyboard operable — Tab focuses and Enter activates (WCAG 2.1.1)',
|
|
1123
|
+
async () => {
|
|
1124
|
+
await userEvent.tab();
|
|
1125
|
+
await expect(remove).toHaveFocus();
|
|
1126
|
+
await userEvent.keyboard('{Enter}');
|
|
1127
|
+
await expect(onRemove).toHaveBeenCalledTimes(1);
|
|
1128
|
+
},
|
|
1129
|
+
);
|
|
1130
|
+
},
|
|
1131
|
+
};
|
|
1132
|
+
|
|
1133
|
+
const LONG_NAME =
|
|
1134
|
+
'Annual-Strategy-And-Operational-Review-Lessons-Learned-Digital-Transformation-Phase-1-FY2026-Final-APPROVED-v3.pdf';
|
|
1135
|
+
|
|
1136
|
+
/**
|
|
1137
|
+
* A name too long for the row is clipped. Hover it to reveal the full name in
|
|
1138
|
+
* a tooltip, including the extension the row itself drops. Names that fit get
|
|
1139
|
+
* no tooltip — see `ShortNameHasNoTooltip`.
|
|
1140
|
+
*/
|
|
1141
|
+
export const TruncatedName: Story = {
|
|
1142
|
+
args: {
|
|
1143
|
+
filename: LONG_NAME,
|
|
1144
|
+
typeLabel: 'PDF',
|
|
1145
|
+
sizeLabel: '4.1 MB',
|
|
1146
|
+
progress: null,
|
|
1147
|
+
error: '',
|
|
1148
|
+
},
|
|
1149
|
+
render: renderArgs,
|
|
1150
|
+
};
|
|
1151
|
+
|
|
1152
|
+
/** A name that fits needs no tooltip, so hovering it opens nothing. */
|
|
1153
|
+
export const ShortNameHasNoTooltip: Story = {
|
|
1154
|
+
args: {
|
|
1155
|
+
filename: 'notes.pdf',
|
|
1156
|
+
typeLabel: 'PDF',
|
|
1157
|
+
sizeLabel: '8 KB',
|
|
1158
|
+
progress: null,
|
|
1159
|
+
error: '',
|
|
1160
|
+
},
|
|
1161
|
+
render: renderArgs,
|
|
1162
|
+
};
|