@aleph-alpha/ui-library 1.21.0 → 1.22.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 +1118 -488
- package/dist/system/lib.js +16219 -15367
- package/package.json +3 -3
- package/src/components/UiAlertDialog/UiAlertDialog.stories.ts +135 -13
- package/src/components/UiAlertDialog/UiAlertDialog.vue +8 -7
- package/src/components/UiAlertDialog/UiAlertDialogHeader.vue +1 -1
- package/src/components/UiAlertDialog/__tests__/UiAlertDialog.test.ts +16 -16
- package/src/components/UiAlertDialog/types.ts +18 -0
- package/src/components/UiDialog/UiDialog.stories.ts +717 -0
- package/src/components/UiDialog/UiDialog.vue +19 -0
- package/src/components/UiDialog/UiDialogClose.vue +16 -0
- package/src/components/UiDialog/UiDialogContent.vue +108 -0
- package/src/components/UiDialog/UiDialogDescription.vue +16 -0
- package/src/components/UiDialog/UiDialogFooter.vue +16 -0
- package/src/components/UiDialog/UiDialogHeader.vue +16 -0
- package/src/components/UiDialog/UiDialogTitle.vue +16 -0
- package/src/components/UiDialog/UiDialogTrigger.vue +16 -0
- package/src/components/UiDialog/__tests__/UiDialog.test.ts +328 -0
- package/src/components/UiDialog/index.ts +13 -0
- package/src/components/UiDialog/types.ts +136 -0
- package/src/components/UiFileItem/UiFileItem.stories.ts +268 -0
- package/src/components/UiFileItem/UiFileItem.vue +119 -0
- package/src/components/UiFileItem/__tests__/UiFileItem.test.ts +66 -0
- package/src/components/UiFileItem/index.ts +2 -0
- package/src/components/UiFileItem/types.ts +27 -0
- package/src/components/UiFileUploadBox/UiFileUploadBox.stories.ts +117 -0
- package/src/components/UiFileUploadBox/UiFileUploadBox.vue +230 -0
- package/src/components/UiFileUploadBox/__tests__/file-validation.test.ts +46 -0
- package/src/components/UiFileUploadBox/file-validation.ts +73 -0
- package/src/components/UiFileUploadBox/index.ts +7 -0
- package/src/components/UiFileUploadBox/types.ts +96 -0
- package/src/components/UiItem/UiItem.vue +7 -1
- package/src/components/UiItem/types.ts +7 -0
- package/src/components/core/alert-dialog/AlertDialog.vue +1 -1
- package/src/components/core/alert-dialog/AlertDialogAction.vue +2 -6
- package/src/components/core/alert-dialog/AlertDialogCancel.vue +3 -7
- package/src/components/core/alert-dialog/AlertDialogContent.vue +15 -7
- package/src/components/core/alert-dialog/AlertDialogDescription.vue +3 -7
- package/src/components/core/alert-dialog/AlertDialogFooter.vue +1 -6
- package/src/components/core/alert-dialog/AlertDialogHeader.vue +1 -9
- package/src/components/core/alert-dialog/AlertDialogTitle.vue +3 -7
- package/src/components/core/dialog/Dialog.vue +15 -0
- package/src/components/core/dialog/DialogClose.vue +12 -0
- package/src/components/core/dialog/DialogContent.vue +48 -0
- package/src/components/core/dialog/DialogDescription.vue +17 -0
- package/src/components/core/dialog/DialogFooter.vue +12 -0
- package/src/components/core/dialog/DialogHeader.vue +9 -0
- package/src/components/core/dialog/DialogOverlay.vue +23 -0
- package/src/components/core/dialog/DialogTitle.vue +17 -0
- package/src/components/core/dialog/DialogTrigger.vue +12 -0
- package/src/components/core/dialog/index.ts +9 -0
- package/src/components/core/drawer/DrawerContent.vue +1 -1
- package/src/components/core/item/Item.vue +7 -4
- package/src/components/core/progress/Progress.vue +7 -2
- package/src/components/core/sheet/SheetOverlay.vue +1 -1
- package/src/components/index.ts +3 -0
- package/src/patterns/UiFileUpload/UiFileUpload.stories.ts +768 -0
- package/src/patterns/UiFileUpload/UiFileUpload.vue +46 -0
- package/src/patterns/UiFileUpload/__tests__/UiFileUpload.test.ts +123 -0
- package/src/patterns/UiFileUpload/index.ts +8 -0
- package/src/patterns/UiFileUpload/types.ts +12 -0
- package/src/patterns/index.ts +1 -0
|
@@ -0,0 +1,768 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/vue3-vite';
|
|
2
|
+
import type { Ref } from 'vue';
|
|
3
|
+
import { onBeforeUnmount, ref } from 'vue';
|
|
4
|
+
import { UiButton } from '@/components/UiButton';
|
|
5
|
+
import {
|
|
6
|
+
UiDialog,
|
|
7
|
+
UiDialogClose,
|
|
8
|
+
UiDialogContent,
|
|
9
|
+
UiDialogTitle,
|
|
10
|
+
UiDialogTrigger,
|
|
11
|
+
} from '@/components/UiDialog';
|
|
12
|
+
import { UiFileItem } from '@/components/UiFileItem';
|
|
13
|
+
import { UiIcon } from '@/components/UiIcon';
|
|
14
|
+
import { formatFileSize } from '@/components/UiFileUploadBox/file-validation';
|
|
15
|
+
import UiFileUpload from './UiFileUpload.vue';
|
|
16
|
+
|
|
17
|
+
const meta: Meta<typeof UiFileUpload> = {
|
|
18
|
+
title: 'Patterns/UiFileUpload',
|
|
19
|
+
component: UiFileUpload,
|
|
20
|
+
tags: ['autodocs'],
|
|
21
|
+
decorators: [
|
|
22
|
+
() => ({
|
|
23
|
+
template: '<div class="w-full max-w-lg p-4"><story /></div>',
|
|
24
|
+
}),
|
|
25
|
+
],
|
|
26
|
+
args: {
|
|
27
|
+
accept: '.pdf,.docx,.txt,application/pdf',
|
|
28
|
+
multiple: true,
|
|
29
|
+
maxFileSizeBytes: 500 * 1024 * 1024,
|
|
30
|
+
disabled: false,
|
|
31
|
+
supportedTypesLabel: 'Supported file types: PDF, DOCX, TXT',
|
|
32
|
+
maxSizeLabel: '',
|
|
33
|
+
dropLabel: 'Drop files here',
|
|
34
|
+
chooseLabel: 'Choose files',
|
|
35
|
+
ariaLabel: 'File upload',
|
|
36
|
+
},
|
|
37
|
+
argTypes: {
|
|
38
|
+
accept: { control: 'text' },
|
|
39
|
+
multiple: { control: 'boolean' },
|
|
40
|
+
maxFileSizeBytes: {
|
|
41
|
+
control: 'number',
|
|
42
|
+
description:
|
|
43
|
+
'Max file size in bytes (validation). When **maxSizeLabel** is blank, the footer shows `Max size: …` from this value.',
|
|
44
|
+
},
|
|
45
|
+
disabled: { control: 'boolean' },
|
|
46
|
+
supportedTypesLabel: {
|
|
47
|
+
control: 'text',
|
|
48
|
+
description: 'Footer left: supported-types hint. Clear to hide. Edit in Controls.',
|
|
49
|
+
},
|
|
50
|
+
maxSizeLabel: {
|
|
51
|
+
control: 'text',
|
|
52
|
+
description:
|
|
53
|
+
'Footer right: max-size line. Leave blank for auto `Max size: …` from **maxFileSizeBytes**; type any text to override (e.g. custom copy or units).',
|
|
54
|
+
},
|
|
55
|
+
dropLabel: { control: 'text' },
|
|
56
|
+
chooseLabel: { control: 'text' },
|
|
57
|
+
ariaLabel: { control: 'text' },
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export default meta;
|
|
62
|
+
type Story = StoryObj<typeof UiFileUpload>;
|
|
63
|
+
|
|
64
|
+
type DialogFileRow = {
|
|
65
|
+
id: string;
|
|
66
|
+
name: string;
|
|
67
|
+
typeLabel: string;
|
|
68
|
+
sizeLabel: string;
|
|
69
|
+
progress: number | null;
|
|
70
|
+
error: string | null;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
type IdCounter = { current: number };
|
|
74
|
+
|
|
75
|
+
function pushValidationErrorRow(
|
|
76
|
+
rows: Ref<DialogFileRow[]>,
|
|
77
|
+
id: IdCounter,
|
|
78
|
+
e: { message: string; file?: File },
|
|
79
|
+
) {
|
|
80
|
+
id.current += 1;
|
|
81
|
+
rows.value.push({
|
|
82
|
+
id: `err-${id.current}`,
|
|
83
|
+
name: e.file?.name ?? 'File',
|
|
84
|
+
typeLabel: '',
|
|
85
|
+
sizeLabel: e.file ? formatFileSize(e.file.size) : '',
|
|
86
|
+
progress: null,
|
|
87
|
+
error: e.message,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const MOCK_INTERVAL_MS = 280;
|
|
92
|
+
const MOCK_CLEAR_DELAY_MS = 450;
|
|
93
|
+
/** Deterministic step sizes for mock upload (Storybook only; avoids `Math.random`). */
|
|
94
|
+
const MOCK_PROGRESS_STEPS = [8, 12, 9, 11, 10, 14, 7, 13] as const;
|
|
95
|
+
|
|
96
|
+
type MockUploadCtx = {
|
|
97
|
+
rows: Ref<DialogFileRow[]>;
|
|
98
|
+
intervals: Set<ReturnType<typeof setInterval>>;
|
|
99
|
+
timeouts: Set<ReturnType<typeof setTimeout>>;
|
|
100
|
+
stepIndices: Map<string, number>;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
function nextMockProgressValue(current: number, stepIndex: number): number {
|
|
104
|
+
const inc = MOCK_PROGRESS_STEPS[stepIndex % MOCK_PROGRESS_STEPS.length];
|
|
105
|
+
return Math.min(100, current + inc);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function stopMockInterval(
|
|
109
|
+
handle: ReturnType<typeof setInterval>,
|
|
110
|
+
intervals: Set<ReturnType<typeof setInterval>>,
|
|
111
|
+
) {
|
|
112
|
+
clearInterval(handle);
|
|
113
|
+
intervals.delete(handle);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function finalizeMockUploadRow(
|
|
117
|
+
rowId: string,
|
|
118
|
+
timeoutHandle: ReturnType<typeof setTimeout>,
|
|
119
|
+
rows: Ref<DialogFileRow[]>,
|
|
120
|
+
timeouts: Set<ReturnType<typeof setTimeout>>,
|
|
121
|
+
) {
|
|
122
|
+
const row = rows.value.find((r) => r.id === rowId);
|
|
123
|
+
if (row) row.progress = null;
|
|
124
|
+
timeouts.delete(timeoutHandle);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function scheduleMockUploadComplete(rowId: string, ctx: MockUploadCtx) {
|
|
128
|
+
const timeoutHandle = setTimeout(() => {
|
|
129
|
+
finalizeMockUploadRow(rowId, timeoutHandle, ctx.rows, ctx.timeouts);
|
|
130
|
+
}, MOCK_CLEAR_DELAY_MS);
|
|
131
|
+
ctx.timeouts.add(timeoutHandle);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function runMockUploadTick(
|
|
135
|
+
rowId: string,
|
|
136
|
+
intervalHandle: ReturnType<typeof setInterval>,
|
|
137
|
+
ctx: MockUploadCtx,
|
|
138
|
+
) {
|
|
139
|
+
const currentRow = ctx.rows.value.find((r) => r.id === rowId);
|
|
140
|
+
if (!currentRow || currentRow.progress == null) {
|
|
141
|
+
stopMockInterval(intervalHandle, ctx.intervals);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
const stepIndex = ctx.stepIndices.get(rowId) ?? 0;
|
|
145
|
+
const next = nextMockProgressValue(currentRow.progress, stepIndex);
|
|
146
|
+
ctx.stepIndices.set(rowId, stepIndex + 1);
|
|
147
|
+
currentRow.progress = next;
|
|
148
|
+
if (next >= 100) {
|
|
149
|
+
stopMockInterval(intervalHandle, ctx.intervals);
|
|
150
|
+
ctx.stepIndices.delete(rowId);
|
|
151
|
+
scheduleMockUploadComplete(rowId, ctx);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function startMockUploadInterval(rowId: string, ctx: MockUploadCtx) {
|
|
156
|
+
ctx.stepIndices.set(rowId, 0);
|
|
157
|
+
const intervalHandle = setInterval(() => {
|
|
158
|
+
runMockUploadTick(rowId, intervalHandle, ctx);
|
|
159
|
+
}, MOCK_INTERVAL_MS);
|
|
160
|
+
ctx.intervals.add(intervalHandle);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function docsSource(code: string) {
|
|
164
|
+
return {
|
|
165
|
+
docs: {
|
|
166
|
+
source: {
|
|
167
|
+
code,
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** Full SFC for dialog + file list pattern (shared body; `UiFileUpload` props vary per story). */
|
|
174
|
+
const DIALOG_PATTERN_TEMPLATE = `<script setup lang="ts">
|
|
175
|
+
import { ref } from 'vue'
|
|
176
|
+
import {
|
|
177
|
+
UiButton,
|
|
178
|
+
UiDialog,
|
|
179
|
+
UiDialogClose,
|
|
180
|
+
UiDialogContent,
|
|
181
|
+
UiDialogTitle,
|
|
182
|
+
UiDialogTrigger,
|
|
183
|
+
UiFileItem,
|
|
184
|
+
UiFileUpload,
|
|
185
|
+
UiIcon,
|
|
186
|
+
} from '@aleph-alpha/ui-library'
|
|
187
|
+
|
|
188
|
+
const dialogOpen = ref(false)
|
|
189
|
+
|
|
190
|
+
type Row = {
|
|
191
|
+
id: string
|
|
192
|
+
name: string
|
|
193
|
+
typeLabel: string
|
|
194
|
+
sizeLabel: string
|
|
195
|
+
progress: number | null
|
|
196
|
+
error: string | null
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const rows = ref<Row[]>([])
|
|
200
|
+
let id = 0
|
|
201
|
+
|
|
202
|
+
function addFiles(files: File[]) {
|
|
203
|
+
for (const f of files) {
|
|
204
|
+
id += 1
|
|
205
|
+
const ext = f.name.split('.').pop()?.toUpperCase() ?? 'FILE'
|
|
206
|
+
rows.value.push({
|
|
207
|
+
id: \`f-\${id}\`,
|
|
208
|
+
name: f.name,
|
|
209
|
+
typeLabel: ext,
|
|
210
|
+
sizeLabel: \`\${f.size} B\`,
|
|
211
|
+
progress: null,
|
|
212
|
+
error: null,
|
|
213
|
+
})
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function onError(e: { message: string; file?: File }) {
|
|
218
|
+
id += 1
|
|
219
|
+
rows.value.push({
|
|
220
|
+
id: \`err-\${id}\`,
|
|
221
|
+
name: e.file?.name ?? 'File',
|
|
222
|
+
typeLabel: '',
|
|
223
|
+
sizeLabel: e.file?.size != null ? \`\${e.file.size} B\` : '',
|
|
224
|
+
progress: null,
|
|
225
|
+
error: e.message,
|
|
226
|
+
})
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function remove(r: Row) {
|
|
230
|
+
rows.value = rows.value.filter((x) => x.id !== r.id)
|
|
231
|
+
}
|
|
232
|
+
</script>
|
|
233
|
+
|
|
234
|
+
<template>
|
|
235
|
+
<UiDialog v-model:open="dialogOpen">
|
|
236
|
+
<UiDialogTrigger as-child>
|
|
237
|
+
<UiButton variant="outline">Open file upload</UiButton>
|
|
238
|
+
</UiDialogTrigger>
|
|
239
|
+
<UiDialogContent max-width="max-w-lg" class="gap-4">
|
|
240
|
+
<template #header>
|
|
241
|
+
<div class="flex items-start justify-between gap-4">
|
|
242
|
+
<UiDialogTitle class="text-lg font-semibold">File upload</UiDialogTitle>
|
|
243
|
+
<UiDialogClose as-child>
|
|
244
|
+
<UiButton variant="ghost" class="size-9 shrink-0 p-0" aria-label="Close dialog">
|
|
245
|
+
<UiIcon name="x" :size="20" />
|
|
246
|
+
</UiButton>
|
|
247
|
+
</UiDialogClose>
|
|
248
|
+
</div>
|
|
249
|
+
</template>
|
|
250
|
+
|
|
251
|
+
<div class="flex flex-col gap-4">
|
|
252
|
+
<UiFileUpload
|
|
253
|
+
__FILE_UPLOAD_PROPS__
|
|
254
|
+
@update:files="addFiles"
|
|
255
|
+
@error="onError"
|
|
256
|
+
/>
|
|
257
|
+
<ul v-if="rows.length" class="flex flex-col gap-2" aria-label="Selected files">
|
|
258
|
+
<li v-for="r in rows" :key="r.id">
|
|
259
|
+
<UiFileItem
|
|
260
|
+
:filename="r.name"
|
|
261
|
+
:type-label="r.typeLabel || undefined"
|
|
262
|
+
:size-label="r.sizeLabel || undefined"
|
|
263
|
+
:progress="r.progress"
|
|
264
|
+
:error="r.error"
|
|
265
|
+
@remove="remove(r)"
|
|
266
|
+
/>
|
|
267
|
+
</li>
|
|
268
|
+
</ul>
|
|
269
|
+
</div>
|
|
270
|
+
|
|
271
|
+
<template #actions>
|
|
272
|
+
<UiDialogClose as-child>
|
|
273
|
+
<UiButton type="button" variant="ghost">Cancel</UiButton>
|
|
274
|
+
</UiDialogClose>
|
|
275
|
+
<UiDialogClose as-child>
|
|
276
|
+
<UiButton type="button">Save changes</UiButton>
|
|
277
|
+
</UiDialogClose>
|
|
278
|
+
</template>
|
|
279
|
+
</UiDialogContent>
|
|
280
|
+
</UiDialog>
|
|
281
|
+
</template>`;
|
|
282
|
+
|
|
283
|
+
function dialogDocsCode(fileUploadPropsLines: string): string {
|
|
284
|
+
const trimmed = fileUploadPropsLines.trim();
|
|
285
|
+
const indented = trimmed
|
|
286
|
+
? `${trimmed
|
|
287
|
+
.split('\n')
|
|
288
|
+
.map((line) => ` ${line.trim()}`)
|
|
289
|
+
.join('\n')}\n`
|
|
290
|
+
: '';
|
|
291
|
+
return DIALOG_PATTERN_TEMPLATE.replace('__FILE_UPLOAD_PROPS__', indented);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/** Docs snippet for **Default**: dialog + trigger + `UiFileUpload` + file list (matches `meta.args`). */
|
|
295
|
+
const defaultDialogTemplateSource = `<script setup lang="ts">
|
|
296
|
+
import { ref } from 'vue'
|
|
297
|
+
import {
|
|
298
|
+
UiButton,
|
|
299
|
+
UiDialog,
|
|
300
|
+
UiDialogClose,
|
|
301
|
+
UiDialogContent,
|
|
302
|
+
UiDialogTitle,
|
|
303
|
+
UiDialogTrigger,
|
|
304
|
+
UiFileItem,
|
|
305
|
+
UiFileUpload,
|
|
306
|
+
UiIcon,
|
|
307
|
+
} from '@aleph-alpha/ui-library'
|
|
308
|
+
|
|
309
|
+
const dialogOpen = ref(false)
|
|
310
|
+
|
|
311
|
+
type Row = {
|
|
312
|
+
id: string
|
|
313
|
+
name: string
|
|
314
|
+
typeLabel: string
|
|
315
|
+
sizeLabel: string
|
|
316
|
+
progress: number | null
|
|
317
|
+
error: string | null
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
const rows = ref<Row[]>([])
|
|
321
|
+
let id = 0
|
|
322
|
+
|
|
323
|
+
function addFiles(files: File[]) {
|
|
324
|
+
for (const f of files) {
|
|
325
|
+
id += 1
|
|
326
|
+
const ext = f.name.split('.').pop()?.toUpperCase() ?? 'FILE'
|
|
327
|
+
rows.value.push({
|
|
328
|
+
id: \`f-\${id}\`,
|
|
329
|
+
name: f.name,
|
|
330
|
+
typeLabel: ext,
|
|
331
|
+
sizeLabel: \`\${f.size} B\`,
|
|
332
|
+
progress: null,
|
|
333
|
+
error: null,
|
|
334
|
+
})
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
function onError(e: { message: string; file?: File }) {
|
|
339
|
+
id += 1
|
|
340
|
+
rows.value.push({
|
|
341
|
+
id: \`err-\${id}\`,
|
|
342
|
+
name: e.file?.name ?? 'File',
|
|
343
|
+
typeLabel: '',
|
|
344
|
+
sizeLabel: e.file?.size != null ? \`\${e.file.size} B\` : '',
|
|
345
|
+
progress: null,
|
|
346
|
+
error: e.message,
|
|
347
|
+
})
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
function remove(r: Row) {
|
|
351
|
+
rows.value = rows.value.filter((x) => x.id !== r.id)
|
|
352
|
+
}
|
|
353
|
+
</script>
|
|
354
|
+
|
|
355
|
+
<template>
|
|
356
|
+
<UiDialog v-model:open="dialogOpen">
|
|
357
|
+
<UiDialogTrigger as-child>
|
|
358
|
+
<UiButton variant="outline">Open file upload</UiButton>
|
|
359
|
+
</UiDialogTrigger>
|
|
360
|
+
<UiDialogContent max-width="max-w-lg" class="gap-4">
|
|
361
|
+
<template #header>
|
|
362
|
+
<div class="flex items-start justify-between gap-4">
|
|
363
|
+
<UiDialogTitle class="text-lg font-semibold">File upload</UiDialogTitle>
|
|
364
|
+
<UiDialogClose as-child>
|
|
365
|
+
<UiButton variant="ghost" class="size-9 shrink-0 p-0" aria-label="Close dialog">
|
|
366
|
+
<UiIcon name="x" :size="20" />
|
|
367
|
+
</UiButton>
|
|
368
|
+
</UiDialogClose>
|
|
369
|
+
</div>
|
|
370
|
+
</template>
|
|
371
|
+
|
|
372
|
+
<div class="flex flex-col gap-4">
|
|
373
|
+
<UiFileUpload
|
|
374
|
+
accept=".pdf,.docx,.txt,application/pdf"
|
|
375
|
+
:multiple="true"
|
|
376
|
+
:max-file-size-bytes="524288000"
|
|
377
|
+
supported-types-label="Supported file types: PDF, DOCX, TXT"
|
|
378
|
+
@update:files="addFiles"
|
|
379
|
+
@error="onError"
|
|
380
|
+
/>
|
|
381
|
+
<ul v-if="rows.length" class="flex flex-col gap-2" aria-label="Selected files">
|
|
382
|
+
<li v-for="r in rows" :key="r.id">
|
|
383
|
+
<UiFileItem
|
|
384
|
+
:filename="r.name"
|
|
385
|
+
:type-label="r.typeLabel || undefined"
|
|
386
|
+
:size-label="r.sizeLabel || undefined"
|
|
387
|
+
:progress="r.progress"
|
|
388
|
+
:error="r.error"
|
|
389
|
+
@remove="remove(r)"
|
|
390
|
+
/>
|
|
391
|
+
</li>
|
|
392
|
+
</ul>
|
|
393
|
+
</div>
|
|
394
|
+
|
|
395
|
+
<template #actions>
|
|
396
|
+
<UiDialogClose as-child>
|
|
397
|
+
<UiButton type="button" variant="ghost">Cancel</UiButton>
|
|
398
|
+
</UiDialogClose>
|
|
399
|
+
<UiDialogClose as-child>
|
|
400
|
+
<UiButton type="button">Save changes</UiButton>
|
|
401
|
+
</UiDialogClose>
|
|
402
|
+
</template>
|
|
403
|
+
</UiDialogContent>
|
|
404
|
+
</UiDialog>
|
|
405
|
+
</template>`;
|
|
406
|
+
|
|
407
|
+
function renderInDialog(args: Story['args']) {
|
|
408
|
+
return {
|
|
409
|
+
components: {
|
|
410
|
+
UiDialog,
|
|
411
|
+
UiDialogTrigger,
|
|
412
|
+
UiDialogContent,
|
|
413
|
+
UiDialogTitle,
|
|
414
|
+
UiDialogClose,
|
|
415
|
+
UiButton,
|
|
416
|
+
UiIcon,
|
|
417
|
+
UiFileUpload,
|
|
418
|
+
UiFileItem,
|
|
419
|
+
},
|
|
420
|
+
setup() {
|
|
421
|
+
const dialogOpen = ref(false);
|
|
422
|
+
const rows = ref<DialogFileRow[]>([]);
|
|
423
|
+
const id = { current: 0 };
|
|
424
|
+
|
|
425
|
+
function addFiles(files: File[]) {
|
|
426
|
+
for (const f of files) {
|
|
427
|
+
id.current += 1;
|
|
428
|
+
const ext = f.name.split('.').pop()?.toUpperCase() ?? 'FILE';
|
|
429
|
+
rows.value.push({
|
|
430
|
+
id: `f-${id.current}`,
|
|
431
|
+
name: f.name,
|
|
432
|
+
typeLabel: ext,
|
|
433
|
+
sizeLabel: formatFileSize(f.size),
|
|
434
|
+
progress: null,
|
|
435
|
+
error: null,
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
function onError(e: { message: string; file?: File }) {
|
|
441
|
+
pushValidationErrorRow(rows, id, e);
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
function remove(r: DialogFileRow) {
|
|
445
|
+
rows.value = rows.value.filter((x) => x.id !== r.id);
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
return { rows, addFiles, onError, remove, dialogOpen, args };
|
|
449
|
+
},
|
|
450
|
+
template: `
|
|
451
|
+
<UiDialog v-model:open="dialogOpen">
|
|
452
|
+
<UiDialogTrigger as-child>
|
|
453
|
+
<UiButton variant="outline">Open file upload</UiButton>
|
|
454
|
+
</UiDialogTrigger>
|
|
455
|
+
<UiDialogContent max-width="max-w-lg" class="gap-4">
|
|
456
|
+
<template #header>
|
|
457
|
+
<div class="flex items-start justify-between gap-4">
|
|
458
|
+
<UiDialogTitle class="text-lg font-semibold">File upload</UiDialogTitle>
|
|
459
|
+
<UiDialogClose as-child>
|
|
460
|
+
<UiButton variant="ghost" class="size-9 shrink-0 p-0" aria-label="Close dialog">
|
|
461
|
+
<UiIcon name="x" :size="20" />
|
|
462
|
+
</UiButton>
|
|
463
|
+
</UiDialogClose>
|
|
464
|
+
</div>
|
|
465
|
+
</template>
|
|
466
|
+
|
|
467
|
+
<div class="flex flex-col gap-4">
|
|
468
|
+
<UiFileUpload v-bind="args" @update:files="addFiles" @error="onError" />
|
|
469
|
+
<ul v-if="rows.length" class="flex flex-col gap-2" aria-label="Selected files">
|
|
470
|
+
<li v-for="r in rows" :key="r.id">
|
|
471
|
+
<UiFileItem
|
|
472
|
+
:filename="r.name"
|
|
473
|
+
:type-label="r.typeLabel || undefined"
|
|
474
|
+
:size-label="r.sizeLabel || undefined"
|
|
475
|
+
:progress="r.progress"
|
|
476
|
+
:error="r.error"
|
|
477
|
+
@remove="remove(r)"
|
|
478
|
+
/>
|
|
479
|
+
</li>
|
|
480
|
+
</ul>
|
|
481
|
+
</div>
|
|
482
|
+
|
|
483
|
+
<template #actions>
|
|
484
|
+
<UiDialogClose as-child>
|
|
485
|
+
<UiButton type="button" variant="ghost">Cancel</UiButton>
|
|
486
|
+
</UiDialogClose>
|
|
487
|
+
<UiDialogClose as-child>
|
|
488
|
+
<UiButton type="button">Save changes</UiButton>
|
|
489
|
+
</UiDialogClose>
|
|
490
|
+
</template>
|
|
491
|
+
</UiDialogContent>
|
|
492
|
+
</UiDialog>
|
|
493
|
+
`,
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
/**
|
|
498
|
+
* Same dialog shell as `renderInDialog`, but each accepted file mock-uploads (progress 0→100) then the progress bar clears (`progress` → `null`) so the row shows as finished without the loading UI.
|
|
499
|
+
* @param args - Story args passed through to `UiFileUpload`.
|
|
500
|
+
*/
|
|
501
|
+
function renderInDialogWithMockUpload(args: Story['args']) {
|
|
502
|
+
return {
|
|
503
|
+
components: {
|
|
504
|
+
UiDialog,
|
|
505
|
+
UiDialogTrigger,
|
|
506
|
+
UiDialogContent,
|
|
507
|
+
UiDialogTitle,
|
|
508
|
+
UiDialogClose,
|
|
509
|
+
UiButton,
|
|
510
|
+
UiIcon,
|
|
511
|
+
UiFileUpload,
|
|
512
|
+
UiFileItem,
|
|
513
|
+
},
|
|
514
|
+
setup() {
|
|
515
|
+
const dialogOpen = ref(false);
|
|
516
|
+
const rows = ref<DialogFileRow[]>([]);
|
|
517
|
+
const id = { current: 0 };
|
|
518
|
+
const intervals = new Set<ReturnType<typeof setInterval>>();
|
|
519
|
+
const timeouts = new Set<ReturnType<typeof setTimeout>>();
|
|
520
|
+
const stepIndices = new Map<string, number>();
|
|
521
|
+
const mockCtx: MockUploadCtx = { rows, intervals, timeouts, stepIndices };
|
|
522
|
+
|
|
523
|
+
onBeforeUnmount(() => {
|
|
524
|
+
intervals.forEach((h) => clearInterval(h));
|
|
525
|
+
timeouts.forEach((h) => clearTimeout(h));
|
|
526
|
+
intervals.clear();
|
|
527
|
+
timeouts.clear();
|
|
528
|
+
stepIndices.clear();
|
|
529
|
+
});
|
|
530
|
+
|
|
531
|
+
function addFiles(files: File[]) {
|
|
532
|
+
for (const f of files) {
|
|
533
|
+
id.current += 1;
|
|
534
|
+
const ext = f.name.split('.').pop()?.toUpperCase() ?? 'FILE';
|
|
535
|
+
const rowId = `f-${id.current}`;
|
|
536
|
+
rows.value.push({
|
|
537
|
+
id: rowId,
|
|
538
|
+
name: f.name,
|
|
539
|
+
typeLabel: ext,
|
|
540
|
+
sizeLabel: formatFileSize(f.size),
|
|
541
|
+
progress: 0,
|
|
542
|
+
error: null,
|
|
543
|
+
});
|
|
544
|
+
startMockUploadInterval(rowId, mockCtx);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
function onError(e: { message: string; file?: File }) {
|
|
549
|
+
pushValidationErrorRow(rows, id, e);
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
function remove(r: DialogFileRow) {
|
|
553
|
+
rows.value = rows.value.filter((x) => x.id !== r.id);
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
return { rows, addFiles, onError, remove, dialogOpen, args };
|
|
557
|
+
},
|
|
558
|
+
template: `
|
|
559
|
+
<UiDialog v-model:open="dialogOpen">
|
|
560
|
+
<UiDialogTrigger as-child>
|
|
561
|
+
<UiButton variant="outline">Open file upload</UiButton>
|
|
562
|
+
</UiDialogTrigger>
|
|
563
|
+
<UiDialogContent max-width="max-w-lg" class="gap-4">
|
|
564
|
+
<template #header>
|
|
565
|
+
<div class="flex items-start justify-between gap-4">
|
|
566
|
+
<UiDialogTitle class="text-lg font-semibold">File upload</UiDialogTitle>
|
|
567
|
+
<UiDialogClose as-child>
|
|
568
|
+
<UiButton variant="ghost" class="size-9 shrink-0 p-0" aria-label="Close dialog">
|
|
569
|
+
<UiIcon name="x" :size="20" />
|
|
570
|
+
</UiButton>
|
|
571
|
+
</UiDialogClose>
|
|
572
|
+
</div>
|
|
573
|
+
</template>
|
|
574
|
+
|
|
575
|
+
<div class="flex flex-col gap-4">
|
|
576
|
+
<UiFileUpload v-bind="args" @update:files="addFiles" @error="onError" />
|
|
577
|
+
<ul v-if="rows.length" class="flex flex-col gap-2" aria-label="Selected files">
|
|
578
|
+
<li v-for="r in rows" :key="r.id">
|
|
579
|
+
<UiFileItem
|
|
580
|
+
:filename="r.name"
|
|
581
|
+
:type-label="r.typeLabel || undefined"
|
|
582
|
+
:size-label="r.sizeLabel || undefined"
|
|
583
|
+
:progress="r.progress"
|
|
584
|
+
:error="r.error"
|
|
585
|
+
@remove="remove(r)"
|
|
586
|
+
/>
|
|
587
|
+
</li>
|
|
588
|
+
</ul>
|
|
589
|
+
</div>
|
|
590
|
+
|
|
591
|
+
<template #actions>
|
|
592
|
+
<UiDialogClose as-child>
|
|
593
|
+
<UiButton type="button" variant="ghost">Cancel</UiButton>
|
|
594
|
+
</UiDialogClose>
|
|
595
|
+
<UiDialogClose as-child>
|
|
596
|
+
<UiButton type="button">Save changes</UiButton>
|
|
597
|
+
</UiDialogClose>
|
|
598
|
+
</template>
|
|
599
|
+
</UiDialogContent>
|
|
600
|
+
</UiDialog>
|
|
601
|
+
`,
|
|
602
|
+
};
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
/**
|
|
606
|
+
* Default integration: **Open file upload** opens a dialog with the drop zone, optional file list, and footer actions.
|
|
607
|
+
* Use **Controls** for `accept`, `multiple`, limits, and labels. Footer: **supportedTypesLabel** (left), **maxSizeLabel** (right; blank = auto from **maxFileSizeBytes**).
|
|
608
|
+
*/
|
|
609
|
+
export const Default: Story = {
|
|
610
|
+
render: (args) => renderInDialog(args),
|
|
611
|
+
parameters: {
|
|
612
|
+
docs: {
|
|
613
|
+
source: {
|
|
614
|
+
code: defaultDialogTemplateSource,
|
|
615
|
+
},
|
|
616
|
+
},
|
|
617
|
+
},
|
|
618
|
+
};
|
|
619
|
+
|
|
620
|
+
/**
|
|
621
|
+
* Mock upload flow: each valid file shows a **progress** bar until 100%, then the bar **hides** (`progress` cleared) so the row reads as uploaded. Open the dialog and add files to watch it.
|
|
622
|
+
*/
|
|
623
|
+
export const WithMockUploadProgress: Story = {
|
|
624
|
+
render: (args) => renderInDialogWithMockUpload(args),
|
|
625
|
+
parameters: {
|
|
626
|
+
docs: {
|
|
627
|
+
description: {
|
|
628
|
+
story:
|
|
629
|
+
'Demonstrates loading on **UiFileItem** during a fake upload, then removal of the progress UI after completion.',
|
|
630
|
+
},
|
|
631
|
+
},
|
|
632
|
+
},
|
|
633
|
+
};
|
|
634
|
+
|
|
635
|
+
/** PDF, DOCX, TXT + explicit max size footer. */
|
|
636
|
+
export const AcceptPdfDocxTxt: Story = {
|
|
637
|
+
args: {
|
|
638
|
+
accept: '.pdf,.docx,.txt,application/pdf',
|
|
639
|
+
maxFileSizeBytes: 500 * 1024 * 1024,
|
|
640
|
+
supportedTypesLabel: 'Supported: PDF, DOCX, TXT',
|
|
641
|
+
},
|
|
642
|
+
render: (args) => renderInDialog(args),
|
|
643
|
+
parameters: docsSource(
|
|
644
|
+
dialogDocsCode(`accept=".pdf,.docx,.txt,application/pdf"
|
|
645
|
+
:max-file-size-bytes="524288000"
|
|
646
|
+
supported-types-label="Supported: PDF, DOCX, TXT"`),
|
|
647
|
+
),
|
|
648
|
+
};
|
|
649
|
+
|
|
650
|
+
/** MIME wildcard — any image type the browser reports. */
|
|
651
|
+
export const AcceptImages: Story = {
|
|
652
|
+
args: {
|
|
653
|
+
accept: 'image/*',
|
|
654
|
+
supportedTypesLabel: 'Supported: images (PNG, JPEG, GIF, WebP, ...)',
|
|
655
|
+
},
|
|
656
|
+
render: (args) => renderInDialog(args),
|
|
657
|
+
parameters: docsSource(
|
|
658
|
+
dialogDocsCode(`accept="image/*"
|
|
659
|
+
supported-types-label="Supported: images (PNG, JPEG, GIF, WebP, ...)"`),
|
|
660
|
+
),
|
|
661
|
+
};
|
|
662
|
+
|
|
663
|
+
/** Single MIME, e.g. spreadsheets. */
|
|
664
|
+
export const AcceptSpreadsheet: Story = {
|
|
665
|
+
args: {
|
|
666
|
+
accept:
|
|
667
|
+
'.csv,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,text/csv',
|
|
668
|
+
supportedTypesLabel: 'Supported: CSV, XLS, XLSX',
|
|
669
|
+
},
|
|
670
|
+
render: (args) => renderInDialog(args),
|
|
671
|
+
parameters: docsSource(
|
|
672
|
+
dialogDocsCode(`accept=".csv,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,text/csv"
|
|
673
|
+
supported-types-label="Supported: CSV, XLS, XLSX"`),
|
|
674
|
+
),
|
|
675
|
+
};
|
|
676
|
+
|
|
677
|
+
/** Only one file from picker and drop (first valid file wins per interaction). */
|
|
678
|
+
export const SingleFile: Story = {
|
|
679
|
+
args: {
|
|
680
|
+
multiple: false,
|
|
681
|
+
accept: '.pdf',
|
|
682
|
+
supportedTypesLabel: 'Single PDF only',
|
|
683
|
+
},
|
|
684
|
+
render: (args) => renderInDialog(args),
|
|
685
|
+
parameters: docsSource(
|
|
686
|
+
dialogDocsCode(`:multiple="false"
|
|
687
|
+
accept=".pdf"
|
|
688
|
+
supported-types-label="Single PDF only"`),
|
|
689
|
+
),
|
|
690
|
+
};
|
|
691
|
+
|
|
692
|
+
/** Strict max size (1 MB). */
|
|
693
|
+
export const MaxSize1Mb: Story = {
|
|
694
|
+
args: {
|
|
695
|
+
accept: '.pdf,.txt,text/plain,application/pdf',
|
|
696
|
+
maxFileSizeBytes: 1024 * 1024,
|
|
697
|
+
supportedTypesLabel: 'PDF or plain text',
|
|
698
|
+
},
|
|
699
|
+
render: (args) => renderInDialog(args),
|
|
700
|
+
parameters: docsSource(
|
|
701
|
+
dialogDocsCode(`accept=".pdf,.txt,text/plain,application/pdf"
|
|
702
|
+
:max-file-size-bytes="1048576"
|
|
703
|
+
supported-types-label="PDF or plain text"`),
|
|
704
|
+
),
|
|
705
|
+
};
|
|
706
|
+
|
|
707
|
+
/** Custom max size line copy. */
|
|
708
|
+
export const CustomMaxSizeLabel: Story = {
|
|
709
|
+
args: {
|
|
710
|
+
accept: undefined,
|
|
711
|
+
maxFileSizeBytes: 10 * 1024 * 1024,
|
|
712
|
+
maxSizeLabel: 'Attachments must be under 10 MB each',
|
|
713
|
+
supportedTypesLabel: 'Any file type',
|
|
714
|
+
},
|
|
715
|
+
render: (args) => renderInDialog(args),
|
|
716
|
+
parameters: docsSource(
|
|
717
|
+
dialogDocsCode(`:max-file-size-bytes="10485760"
|
|
718
|
+
max-size-label="Attachments must be under 10 MB each"
|
|
719
|
+
supported-types-label="Any file type"`),
|
|
720
|
+
),
|
|
721
|
+
};
|
|
722
|
+
|
|
723
|
+
/** No `accept` — any type; footer hidden when no hints are set. */
|
|
724
|
+
export const AnyTypeNoFooter: Story = {
|
|
725
|
+
render: (args) =>
|
|
726
|
+
renderInDialog({
|
|
727
|
+
...args,
|
|
728
|
+
accept: undefined,
|
|
729
|
+
maxFileSizeBytes: undefined,
|
|
730
|
+
supportedTypesLabel: '',
|
|
731
|
+
maxSizeLabel: '',
|
|
732
|
+
}),
|
|
733
|
+
parameters: docsSource(dialogDocsCode('')),
|
|
734
|
+
};
|
|
735
|
+
|
|
736
|
+
/** Drop zone and picker disabled; the zone is not keyboard-focusable. */
|
|
737
|
+
export const Disabled: Story = {
|
|
738
|
+
args: {
|
|
739
|
+
disabled: true,
|
|
740
|
+
accept: '.pdf',
|
|
741
|
+
supportedTypesLabel: 'PDF (disabled)',
|
|
742
|
+
},
|
|
743
|
+
render: (args) => renderInDialog(args),
|
|
744
|
+
parameters: docsSource(
|
|
745
|
+
dialogDocsCode(`disabled
|
|
746
|
+
accept=".pdf"
|
|
747
|
+
supported-types-label="PDF (disabled)"`),
|
|
748
|
+
),
|
|
749
|
+
};
|
|
750
|
+
|
|
751
|
+
/** Custom title, button, and accessible name. */
|
|
752
|
+
export const CustomLabels: Story = {
|
|
753
|
+
args: {
|
|
754
|
+
dropLabel: 'Add attachments',
|
|
755
|
+
chooseLabel: 'Browse...',
|
|
756
|
+
ariaLabel: 'Attachment upload',
|
|
757
|
+
accept: '.zip,.tar,.gz',
|
|
758
|
+
supportedTypesLabel: 'Archives: ZIP, TAR, GZ',
|
|
759
|
+
},
|
|
760
|
+
render: (args) => renderInDialog(args),
|
|
761
|
+
parameters: docsSource(
|
|
762
|
+
dialogDocsCode(`drop-label="Add attachments"
|
|
763
|
+
choose-label="Browse..."
|
|
764
|
+
aria-label="Attachment upload"
|
|
765
|
+
accept=".zip,.tar,.gz"
|
|
766
|
+
supported-types-label="Archives: ZIP, TAR, GZ"`),
|
|
767
|
+
),
|
|
768
|
+
};
|