@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.
Files changed (62) hide show
  1. package/dist/system/index.d.ts +1118 -488
  2. package/dist/system/lib.js +16219 -15367
  3. package/package.json +3 -3
  4. package/src/components/UiAlertDialog/UiAlertDialog.stories.ts +135 -13
  5. package/src/components/UiAlertDialog/UiAlertDialog.vue +8 -7
  6. package/src/components/UiAlertDialog/UiAlertDialogHeader.vue +1 -1
  7. package/src/components/UiAlertDialog/__tests__/UiAlertDialog.test.ts +16 -16
  8. package/src/components/UiAlertDialog/types.ts +18 -0
  9. package/src/components/UiDialog/UiDialog.stories.ts +717 -0
  10. package/src/components/UiDialog/UiDialog.vue +19 -0
  11. package/src/components/UiDialog/UiDialogClose.vue +16 -0
  12. package/src/components/UiDialog/UiDialogContent.vue +108 -0
  13. package/src/components/UiDialog/UiDialogDescription.vue +16 -0
  14. package/src/components/UiDialog/UiDialogFooter.vue +16 -0
  15. package/src/components/UiDialog/UiDialogHeader.vue +16 -0
  16. package/src/components/UiDialog/UiDialogTitle.vue +16 -0
  17. package/src/components/UiDialog/UiDialogTrigger.vue +16 -0
  18. package/src/components/UiDialog/__tests__/UiDialog.test.ts +328 -0
  19. package/src/components/UiDialog/index.ts +13 -0
  20. package/src/components/UiDialog/types.ts +136 -0
  21. package/src/components/UiFileItem/UiFileItem.stories.ts +268 -0
  22. package/src/components/UiFileItem/UiFileItem.vue +119 -0
  23. package/src/components/UiFileItem/__tests__/UiFileItem.test.ts +66 -0
  24. package/src/components/UiFileItem/index.ts +2 -0
  25. package/src/components/UiFileItem/types.ts +27 -0
  26. package/src/components/UiFileUploadBox/UiFileUploadBox.stories.ts +117 -0
  27. package/src/components/UiFileUploadBox/UiFileUploadBox.vue +230 -0
  28. package/src/components/UiFileUploadBox/__tests__/file-validation.test.ts +46 -0
  29. package/src/components/UiFileUploadBox/file-validation.ts +73 -0
  30. package/src/components/UiFileUploadBox/index.ts +7 -0
  31. package/src/components/UiFileUploadBox/types.ts +96 -0
  32. package/src/components/UiItem/UiItem.vue +7 -1
  33. package/src/components/UiItem/types.ts +7 -0
  34. package/src/components/core/alert-dialog/AlertDialog.vue +1 -1
  35. package/src/components/core/alert-dialog/AlertDialogAction.vue +2 -6
  36. package/src/components/core/alert-dialog/AlertDialogCancel.vue +3 -7
  37. package/src/components/core/alert-dialog/AlertDialogContent.vue +15 -7
  38. package/src/components/core/alert-dialog/AlertDialogDescription.vue +3 -7
  39. package/src/components/core/alert-dialog/AlertDialogFooter.vue +1 -6
  40. package/src/components/core/alert-dialog/AlertDialogHeader.vue +1 -9
  41. package/src/components/core/alert-dialog/AlertDialogTitle.vue +3 -7
  42. package/src/components/core/dialog/Dialog.vue +15 -0
  43. package/src/components/core/dialog/DialogClose.vue +12 -0
  44. package/src/components/core/dialog/DialogContent.vue +48 -0
  45. package/src/components/core/dialog/DialogDescription.vue +17 -0
  46. package/src/components/core/dialog/DialogFooter.vue +12 -0
  47. package/src/components/core/dialog/DialogHeader.vue +9 -0
  48. package/src/components/core/dialog/DialogOverlay.vue +23 -0
  49. package/src/components/core/dialog/DialogTitle.vue +17 -0
  50. package/src/components/core/dialog/DialogTrigger.vue +12 -0
  51. package/src/components/core/dialog/index.ts +9 -0
  52. package/src/components/core/drawer/DrawerContent.vue +1 -1
  53. package/src/components/core/item/Item.vue +7 -4
  54. package/src/components/core/progress/Progress.vue +7 -2
  55. package/src/components/core/sheet/SheetOverlay.vue +1 -1
  56. package/src/components/index.ts +3 -0
  57. package/src/patterns/UiFileUpload/UiFileUpload.stories.ts +768 -0
  58. package/src/patterns/UiFileUpload/UiFileUpload.vue +46 -0
  59. package/src/patterns/UiFileUpload/__tests__/UiFileUpload.test.ts +123 -0
  60. package/src/patterns/UiFileUpload/index.ts +8 -0
  61. package/src/patterns/UiFileUpload/types.ts +12 -0
  62. package/src/patterns/index.ts +1 -0
@@ -0,0 +1,46 @@
1
+ <script setup lang="ts">
2
+ import { UiFileUploadBox } from '@/components/UiFileUploadBox';
3
+ import type { UiFileUploadBoxEmits } from '@/components/UiFileUploadBox/types';
4
+ import type { UiFileUploadProps } from './types';
5
+
6
+ defineOptions({
7
+ name: 'UiFileUpload',
8
+ });
9
+
10
+ const props = withDefaults(defineProps<UiFileUploadProps>(), {
11
+ accept: undefined,
12
+ multiple: true,
13
+ maxFileSizeBytes: undefined,
14
+ disabled: false,
15
+ supportedTypesLabel: '',
16
+ maxSizeLabel: '',
17
+ dropLabel: 'Drop files here',
18
+ chooseLabel: 'Choose files',
19
+ ariaLabel: 'File upload',
20
+ });
21
+
22
+ const emit = defineEmits<UiFileUploadBoxEmits>();
23
+ </script>
24
+
25
+ <template>
26
+ <UiFileUploadBox
27
+ v-bind="props"
28
+ @update:files="emit('update:files', $event)"
29
+ @error="emit('error', $event)"
30
+ @dragenter="emit('dragenter', $event)"
31
+ @dragleave="emit('dragleave', $event)"
32
+ @dragover="emit('dragover', $event)"
33
+ @drop="emit('drop', $event)"
34
+ @click="emit('click', $event)"
35
+ @keydown="emit('keydown', $event)"
36
+ @focus="emit('focus', $event)"
37
+ @blur="emit('blur', $event)"
38
+ @change="emit('change', $event)"
39
+ @picker-open="emit('pickerOpen')"
40
+ >
41
+ <template #title><slot name="title" /></template>
42
+ <template #icon><slot name="icon" /></template>
43
+ <template #choose><slot name="choose" /></template>
44
+ <template #footer><slot name="footer" /></template>
45
+ </UiFileUploadBox>
46
+ </template>
@@ -0,0 +1,123 @@
1
+ import { render } from '@testing-library/vue';
2
+ import { describe, expect, test } from 'vitest';
3
+ import UiFileUpload from '../UiFileUpload.vue';
4
+
5
+ describe('UiFileUpload', () => {
6
+ test('renders drop label and choose button', () => {
7
+ const { getByRole, getByText } = render(UiFileUpload, {
8
+ props: {
9
+ dropLabel: 'Drop files here',
10
+ chooseLabel: 'Choose files',
11
+ },
12
+ });
13
+ expect(getByText('Drop files here')).toBeInTheDocument();
14
+ expect(getByRole('button', { name: 'Choose files' })).toBeInTheDocument();
15
+ });
16
+
17
+ test('emits dragenter and drop with DragEvent', async () => {
18
+ const { getByRole, emitted } = render(UiFileUpload);
19
+ const zone = getByRole('button', { name: 'File upload' });
20
+ const file = new File(['x'], 'a.txt', { type: 'text/plain' });
21
+ const files = {
22
+ length: 1,
23
+ item: (i: number) => (i === 0 ? file : null),
24
+ *[Symbol.iterator]() {
25
+ yield file;
26
+ },
27
+ } as unknown as FileList;
28
+ const dataTransfer = { files } as unknown as DataTransfer;
29
+
30
+ zone.dispatchEvent(new Event('dragenter', { bubbles: true, cancelable: true }));
31
+ expect(emitted('dragenter')).toHaveLength(1);
32
+
33
+ const dropEv = new Event('drop', { bubbles: true, cancelable: true });
34
+ Object.defineProperty(dropEv, 'dataTransfer', {
35
+ value: dataTransfer,
36
+ configurable: true,
37
+ });
38
+ zone.dispatchEvent(dropEv);
39
+ expect(emitted('drop')).toHaveLength(1);
40
+ expect(emitted('update:files')).toBeTruthy();
41
+ });
42
+
43
+ test('with multiple=false, drop emits only the first valid file', async () => {
44
+ const { getByRole, emitted } = render(UiFileUpload, {
45
+ props: {
46
+ multiple: false,
47
+ accept: '.txt,text/plain',
48
+ },
49
+ });
50
+ const zone = getByRole('button', { name: 'File upload' });
51
+ const first = new File(['a'], 'a.txt', { type: 'text/plain' });
52
+ const second = new File(['b'], 'b.txt', { type: 'text/plain' });
53
+ const list = [first, second];
54
+ const files = {
55
+ length: list.length,
56
+ item: (i: number) => list[i] ?? null,
57
+ *[Symbol.iterator]() {
58
+ yield* list;
59
+ },
60
+ } as unknown as FileList;
61
+ const dataTransfer = { files } as unknown as DataTransfer;
62
+ const dropEv = new Event('drop', { bubbles: true, cancelable: true });
63
+ Object.defineProperty(dropEv, 'dataTransfer', {
64
+ value: dataTransfer,
65
+ configurable: true,
66
+ });
67
+ zone.dispatchEvent(dropEv);
68
+ expect(emitted('update:files')).toHaveLength(1);
69
+ const payload = emitted('update:files')?.[0]?.[0] as File[];
70
+ expect(payload).toHaveLength(1);
71
+ expect(payload[0].name).toBe('a.txt');
72
+ });
73
+
74
+ test('footer shows custom maxSizeLabel when set', () => {
75
+ const { getByText } = render(UiFileUpload, {
76
+ props: {
77
+ maxSizeLabel: 'Per file: 2 MB maximum',
78
+ maxFileSizeBytes: 500 * 1024 * 1024,
79
+ },
80
+ });
81
+ expect(getByText('Per file: 2 MB maximum')).toBeInTheDocument();
82
+ });
83
+
84
+ test('footer shows auto max size when maxSizeLabel is blank', () => {
85
+ const { getByText } = render(UiFileUpload, {
86
+ props: {
87
+ maxSizeLabel: '',
88
+ maxFileSizeBytes: 1024 * 1024,
89
+ },
90
+ });
91
+ expect(getByText('Max size: 1.0 MB')).toBeInTheDocument();
92
+ });
93
+
94
+ test('when disabled, drop zone is not in tab order', () => {
95
+ const { container } = render(UiFileUpload, {
96
+ props: { disabled: true, ariaLabel: 'Attachment upload' },
97
+ });
98
+ const zone = container.querySelector('[aria-label="Attachment upload"]') as HTMLElement;
99
+ expect(zone).toBeTruthy();
100
+ expect(zone.getAttribute('tabindex')).toBe('-1');
101
+ });
102
+
103
+ test('emits error for file failing accept', async () => {
104
+ const { container, emitted } = render(UiFileUpload, {
105
+ props: {
106
+ accept: '.pdf',
107
+ },
108
+ });
109
+ const input = container.querySelector('input[type="file"]') as HTMLInputElement;
110
+ const bad = new File(['x'], 'x.exe', { type: 'application/octet-stream' });
111
+ const fileList = {
112
+ length: 1,
113
+ item: (i: number) => (i === 0 ? bad : null),
114
+ *[Symbol.iterator]() {
115
+ yield bad;
116
+ },
117
+ } as unknown as FileList;
118
+ Object.defineProperty(input, 'files', { value: fileList, configurable: true });
119
+ input.dispatchEvent(new Event('change', { bubbles: true }));
120
+ expect(emitted('error')).toBeTruthy();
121
+ expect(emitted('error')?.[0]?.[0]).toMatchObject({ message: 'Unsupported file type' });
122
+ });
123
+ });
@@ -0,0 +1,8 @@
1
+ export { default as UiFileUpload } from './UiFileUpload.vue';
2
+ export type { UiFileUploadProps } from './types';
3
+ export {
4
+ formatFileSize,
5
+ fileMatchesAccept,
6
+ validateFile,
7
+ validateFiles,
8
+ } from '@/components/UiFileUploadBox/file-validation';
@@ -0,0 +1,12 @@
1
+ import type { UiFileUploadBoxProps } from '@/components/UiFileUploadBox/types';
2
+
3
+ /**
4
+ * Composition-friendly file upload (same API as {@link UiFileUploadBoxProps}).
5
+ * Implementation delegates to {@link UiFileUploadBox}.
6
+ *
7
+ * @category Patterns
8
+ * @useCases file upload dialog, drag and drop attachments
9
+ * @keywords file, upload, drag, drop, attachment
10
+ * @related UiFileItem, UiDialog, UiFileUploadBox
11
+ */
12
+ export type UiFileUploadProps = UiFileUploadBoxProps;
@@ -4,4 +4,5 @@
4
4
  */
5
5
  export * from './UiDataTable';
6
6
  export * from './UiDatePicker';
7
+ export * from './UiFileUpload';
7
8
  export * from './UiPlaceholder';