@aleph-alpha/ui-library 1.21.0 → 1.23.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 (128) hide show
  1. package/dist/system/index.d.ts +1520 -674
  2. package/dist/system/lib.js +21142 -19505
  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/UiIconButton/UiIconButton.vue +5 -1
  33. package/src/components/UiIconButton/types.ts +1 -1
  34. package/src/components/UiItem/UiItem.vue +7 -1
  35. package/src/components/UiItem/types.ts +7 -0
  36. package/src/components/core/alert-dialog/AlertDialog.vue +1 -1
  37. package/src/components/core/alert-dialog/AlertDialogAction.vue +2 -6
  38. package/src/components/core/alert-dialog/AlertDialogCancel.vue +3 -7
  39. package/src/components/core/alert-dialog/AlertDialogContent.vue +15 -7
  40. package/src/components/core/alert-dialog/AlertDialogDescription.vue +3 -7
  41. package/src/components/core/alert-dialog/AlertDialogFooter.vue +1 -6
  42. package/src/components/core/alert-dialog/AlertDialogHeader.vue +1 -9
  43. package/src/components/core/alert-dialog/AlertDialogTitle.vue +3 -7
  44. package/src/components/core/button/index.ts +6 -4
  45. package/src/components/core/dialog/Dialog.vue +15 -0
  46. package/src/components/core/dialog/DialogClose.vue +12 -0
  47. package/src/components/core/dialog/DialogContent.vue +48 -0
  48. package/src/components/core/dialog/DialogDescription.vue +17 -0
  49. package/src/components/core/dialog/DialogFooter.vue +12 -0
  50. package/src/components/core/dialog/DialogHeader.vue +9 -0
  51. package/src/components/core/dialog/DialogOverlay.vue +23 -0
  52. package/src/components/core/dialog/DialogTitle.vue +17 -0
  53. package/src/components/core/dialog/DialogTrigger.vue +12 -0
  54. package/src/components/core/dialog/index.ts +9 -0
  55. package/src/components/core/drawer/DrawerContent.vue +1 -1
  56. package/src/components/core/item/Item.vue +7 -4
  57. package/src/components/core/progress/Progress.vue +7 -2
  58. package/src/components/core/sheet/SheetOverlay.vue +1 -1
  59. package/src/components/core/sidebar/SidebarContent.vue +11 -3
  60. package/src/components/core/sidebar/SidebarFooter.vue +10 -2
  61. package/src/components/core/sidebar/SidebarGroup.vue +10 -2
  62. package/src/components/core/sidebar/SidebarGroupLabel.vue +1 -1
  63. package/src/components/core/sidebar/SidebarHeader.vue +10 -2
  64. package/src/components/core/sidebar/SidebarMenu.vue +12 -2
  65. package/src/components/core/sidebar/SidebarMenuButton.vue +2 -2
  66. package/src/components/core/sidebar/SidebarSeparator.vue +10 -2
  67. package/src/components/core/sidebar/SidebarTrigger.vue +2 -2
  68. package/src/components/core/sidebar/index.ts +1 -1
  69. package/src/components/core/sidebar/utils.ts +11 -2
  70. package/src/components/index.ts +3 -1
  71. package/src/directives/index.ts +1 -0
  72. package/src/directives/vOverlay.ts +94 -0
  73. package/src/patterns/UiFileUpload/UiFileUpload.stories.ts +768 -0
  74. package/src/patterns/UiFileUpload/UiFileUpload.vue +46 -0
  75. package/src/patterns/UiFileUpload/__tests__/UiFileUpload.test.ts +123 -0
  76. package/src/patterns/UiFileUpload/index.ts +8 -0
  77. package/src/patterns/UiFileUpload/types.ts +12 -0
  78. package/src/patterns/UiSidebar/UiSidebar.stories.ts +346 -0
  79. package/src/{components → patterns}/UiSidebar/UiSidebar.vue +9 -3
  80. package/src/patterns/UiSidebar/UiSidebarChatHistory.stories.ts +77 -0
  81. package/src/patterns/UiSidebar/UiSidebarChatHistory.vue +35 -0
  82. package/src/patterns/UiSidebar/UiSidebarChatHistoryItem.stories.ts +85 -0
  83. package/src/patterns/UiSidebar/UiSidebarChatHistoryItem.vue +139 -0
  84. package/src/patterns/UiSidebar/UiSidebarContent.vue +11 -0
  85. package/src/patterns/UiSidebar/UiSidebarFooter.vue +11 -0
  86. package/src/patterns/UiSidebar/UiSidebarGroup.stories.ts +91 -0
  87. package/src/patterns/UiSidebar/UiSidebarGroup.vue +42 -0
  88. package/src/patterns/UiSidebar/UiSidebarGroupContent.vue +15 -0
  89. package/src/patterns/UiSidebar/UiSidebarGroupLabel.stories.ts +163 -0
  90. package/src/patterns/UiSidebar/UiSidebarGroupLabel.vue +131 -0
  91. package/src/patterns/UiSidebar/UiSidebarHeader.vue +48 -0
  92. package/src/patterns/UiSidebar/UiSidebarInset.vue +11 -0
  93. package/src/patterns/UiSidebar/UiSidebarMenu.vue +11 -0
  94. package/src/patterns/UiSidebar/UiSidebarMenuButton.stories.ts +205 -0
  95. package/src/patterns/UiSidebar/UiSidebarMenuButton.vue +121 -0
  96. package/src/patterns/UiSidebar/UiSidebarMenuItem.stories.ts +67 -0
  97. package/src/patterns/UiSidebar/UiSidebarMenuItem.vue +11 -0
  98. package/src/patterns/UiSidebar/UiSidebarMenuSub.vue +38 -0
  99. package/src/patterns/UiSidebar/UiSidebarMenuSubItem.stories.ts +66 -0
  100. package/src/patterns/UiSidebar/UiSidebarMenuSubItem.vue +67 -0
  101. package/src/patterns/UiSidebar/UiSidebarPopover.vue +43 -0
  102. package/src/patterns/UiSidebar/UiSidebarPopoverMenu.stories.ts +56 -0
  103. package/src/patterns/UiSidebar/UiSidebarPopoverMenu.vue +56 -0
  104. package/src/patterns/UiSidebar/UiSidebarPopoverMenuItem.stories.ts +42 -0
  105. package/src/patterns/UiSidebar/UiSidebarPopoverMenuItem.vue +79 -0
  106. package/src/patterns/UiSidebar/UiSidebarPopoverTrigger.stories.ts +61 -0
  107. package/src/patterns/UiSidebar/UiSidebarPopoverTrigger.vue +81 -0
  108. package/src/patterns/UiSidebar/UiSidebarProvider.vue +11 -0
  109. package/src/patterns/UiSidebar/UiSidebarRail.vue +9 -0
  110. package/src/patterns/UiSidebar/UiSidebarTrigger.vue +35 -0
  111. package/src/patterns/UiSidebar/groupContext.ts +9 -0
  112. package/src/patterns/UiSidebar/index.ts +42 -0
  113. package/src/patterns/UiSidebar/types.ts +375 -0
  114. package/src/patterns/index.ts +2 -0
  115. package/src/components/UiSidebar/UiSidebar.stories.ts +0 -1188
  116. package/src/components/UiSidebar/UiSidebarGroupAction.vue +0 -18
  117. package/src/components/UiSidebar/UiSidebarGroupLabel.vue +0 -18
  118. package/src/components/UiSidebar/UiSidebarHeaderTrigger.vue +0 -53
  119. package/src/components/UiSidebar/UiSidebarInput.vue +0 -14
  120. package/src/components/UiSidebar/UiSidebarMenuAction.vue +0 -19
  121. package/src/components/UiSidebar/UiSidebarMenuButton.vue +0 -27
  122. package/src/components/UiSidebar/UiSidebarMenuSkeleton.vue +0 -16
  123. package/src/components/UiSidebar/UiSidebarMenuSubButton.vue +0 -24
  124. package/src/components/UiSidebar/UiSidebarProvider.vue +0 -16
  125. package/src/components/UiSidebar/UiSidebarSeparator.vue +0 -13
  126. package/src/components/UiSidebar/__tests__/UiSidebar.test.ts +0 -221
  127. package/src/components/UiSidebar/index.ts +0 -34
  128. package/src/components/UiSidebar/types.ts +0 -165
@@ -0,0 +1,136 @@
1
+ import type { DialogContentEmits, DialogContentProps } from 'reka-ui';
2
+
3
+ /**
4
+ * Shared props for UiDialog subcomponents.
5
+ */
6
+ export type UiDialogSubComponentCommonProps = {
7
+ /** Render as a child element instead of wrapping. */
8
+ asChild?: boolean;
9
+ };
10
+
11
+ /**
12
+ * Allowed Tailwind `max-w-*` utilities for {@link UiDialogContentProps.maxWidth}.
13
+ * Prefer these over arbitrary class strings so MCP and consumers get a closed set.
14
+ */
15
+ export type UiDialogContentMaxWidth =
16
+ | 'max-w-sm'
17
+ | 'max-w-md'
18
+ | 'max-w-lg'
19
+ | 'max-w-xl'
20
+ | 'max-w-2xl'
21
+ | 'max-w-3xl'
22
+ | 'max-w-4xl'
23
+ | 'max-w-5xl'
24
+ | 'max-w-6xl'
25
+ | 'max-w-7xl'
26
+ | 'max-w-full'
27
+ | 'max-w-none'
28
+ | 'max-w-[50vw]';
29
+
30
+ /**
31
+ * A modal dialog for focused tasks and content. Description and `#actions` are optional.
32
+ * @category Overlays
33
+ * @useCases forms, details, multi-step flows, rich content
34
+ * @keywords dialog, modal, overlay, popup
35
+ * @related UiAlertDialog, UiSheet, UiDrawer
36
+ */
37
+ export type UiDialogProps = {
38
+ /**
39
+ * The controlled open state of the dialog.
40
+ * Use `v-model:open` for controlled mode.
41
+ */
42
+ open?: boolean;
43
+
44
+ /**
45
+ * When set to `true`, interaction with outside elements is disabled and focus is trapped.
46
+ * @default true
47
+ */
48
+ modal?: boolean;
49
+ };
50
+
51
+ /**
52
+ * Props for UiDialogTrigger.
53
+ * @category Overlays
54
+ * @useCases opening a dialog from buttons, links, or custom controls
55
+ */
56
+ export type UiDialogTriggerProps = UiDialogSubComponentCommonProps & {};
57
+
58
+ /**
59
+ * Props for UiDialogClose.
60
+ * @category Overlays
61
+ * @useCases closing a dialog from footer actions or icon buttons
62
+ */
63
+ export type UiDialogCloseProps = UiDialogSubComponentCommonProps & {};
64
+
65
+ /**
66
+ * Props for UiDialogContent (optional `title` / `description`, slots: `header`, default body, `actions`).
67
+ * @category Overlays
68
+ * @useCases confirmations, forms, file pickers, settings panels
69
+ */
70
+ export type UiDialogContentProps = UiDialogSubComponentCommonProps &
71
+ DialogContentProps & {
72
+ /**
73
+ * Optional dialog title (maps to `DialogTitle`).
74
+ */
75
+ title?: string;
76
+
77
+ /**
78
+ * Optional supporting text below the title (maps to `DialogDescription`).
79
+ */
80
+ description?: string;
81
+
82
+ /**
83
+ * Screen-reader-only label when no `title` is provided (accessibility).
84
+ * @default 'Dialog'
85
+ */
86
+ ariaTitle?: string;
87
+
88
+ /**
89
+ * Accessible name for the built-in header close button (when `showCloseButton` is true).
90
+ * @default 'Close dialog'
91
+ */
92
+ ariaLabelCloseDialog?: string;
93
+
94
+ /**
95
+ * Tailwind max-width utility for the panel. Defaults to **`max-w-[50vw]`** (half the viewport).
96
+ */
97
+ maxWidth?: UiDialogContentMaxWidth;
98
+
99
+ /**
100
+ * When `true` and you are **not** using the `#header` slot, shows a header **Close** control (icon button).
101
+ * Set to `false` if the dialog is closed only via `#actions` or programmatically.
102
+ * @default true
103
+ */
104
+ showCloseButton?: boolean;
105
+ };
106
+
107
+ /** Emits forwarded from `DialogContent` (reka-ui). */
108
+ export type UiDialogContentEmits = DialogContentEmits;
109
+
110
+ /**
111
+ * Props for UiDialogHeader.
112
+ * @category Overlays
113
+ * @useCases grouping title and description in a custom `#header` slot
114
+ */
115
+ export type UiDialogHeaderProps = {};
116
+
117
+ /**
118
+ * Props for UiDialogFooter.
119
+ * @category Overlays
120
+ * @useCases action button rows in `#actions` or manual footer composition
121
+ */
122
+ export type UiDialogFooterProps = {};
123
+
124
+ /**
125
+ * Props for UiDialogTitle.
126
+ * @category Overlays
127
+ * @useCases accessible dialog titles in custom headers
128
+ */
129
+ export type UiDialogTitleProps = UiDialogSubComponentCommonProps & {};
130
+
131
+ /**
132
+ * Props for UiDialogDescription.
133
+ * @category Overlays
134
+ * @useCases supplementary copy under the title
135
+ */
136
+ export type UiDialogDescriptionProps = UiDialogSubComponentCommonProps & {};
@@ -0,0 +1,268 @@
1
+ import type { Meta, StoryObj } from '@storybook/vue3-vite';
2
+ import UiFileItem from './UiFileItem.vue';
3
+
4
+ const meta: Meta<typeof UiFileItem> = {
5
+ title: 'Components/UiFileItem',
6
+ component: UiFileItem,
7
+ tags: ['autodocs'],
8
+ args: {
9
+ filename: 'document.pdf',
10
+ typeLabel: 'PDF',
11
+ sizeLabel: '1.2 MB',
12
+ progress: null,
13
+ error: '',
14
+ disabled: false,
15
+ removeLabel: 'Remove file',
16
+ },
17
+ argTypes: {
18
+ filename: { control: 'text' },
19
+ typeLabel: { control: 'text' },
20
+ sizeLabel: { control: 'text' },
21
+ progress: { control: { type: 'number', min: 0, max: 100 } },
22
+ error: {
23
+ control: 'text',
24
+ description:
25
+ 'Error text under the row (destructive alert). Leave empty to hide; edit to try different messages.',
26
+ },
27
+ disabled: { control: 'boolean' },
28
+ removeLabel: { control: 'text' },
29
+ },
30
+ };
31
+
32
+ export default meta;
33
+ type Story = StoryObj<typeof UiFileItem>;
34
+
35
+ /**
36
+ * Interactive row; use **Controls** to toggle `progress`, `disabled`, and edit **`error`** (text field — clear to hide the alert).
37
+ */
38
+ export const Default: Story = {
39
+ render: (args) => ({
40
+ components: { UiFileItem },
41
+ setup() {
42
+ function onRemove() {}
43
+ return { args, onRemove };
44
+ },
45
+ template: '<div class="max-w-md"><UiFileItem v-bind="args" @remove="onRemove" /></div>',
46
+ }),
47
+ };
48
+
49
+ /** Upload in progress (0–100). */
50
+ export const WithProgress: Story = {
51
+ args: {
52
+ filename: 'uploading.bin',
53
+ typeLabel: 'BIN',
54
+ sizeLabel: '12 MB',
55
+ progress: 30,
56
+ error: '',
57
+ disabled: false,
58
+ },
59
+ render: (args) => ({
60
+ components: { UiFileItem },
61
+ setup() {
62
+ function onRemove() {}
63
+ return { args, onRemove };
64
+ },
65
+ template: '<div class="max-w-md"><UiFileItem v-bind="args" @remove="onRemove" /></div>',
66
+ }),
67
+ };
68
+
69
+ /** Progress at 100%. */
70
+ export const Complete: Story = {
71
+ args: {
72
+ filename: 'done.zip',
73
+ typeLabel: 'ZIP',
74
+ sizeLabel: '4 MB',
75
+ progress: 100,
76
+ error: '',
77
+ disabled: false,
78
+ },
79
+ render: (args) => ({
80
+ components: { UiFileItem },
81
+ setup() {
82
+ function onRemove() {}
83
+ return { args, onRemove };
84
+ },
85
+ template: '<div class="max-w-md"><UiFileItem v-bind="args" @remove="onRemove" /></div>',
86
+ }),
87
+ };
88
+
89
+ /** Validation or upload failure; message appears under the row (same band as the progress bar). */
90
+ export const WithError: Story = {
91
+ args: {
92
+ filename: 'bad.exe',
93
+ typeLabel: 'EXE',
94
+ sizeLabel: '1 MB',
95
+ progress: null,
96
+ error: 'Unsupported file type',
97
+ disabled: false,
98
+ },
99
+ render: (args) => ({
100
+ components: { UiFileItem },
101
+ setup() {
102
+ function onRemove() {}
103
+ return { args, onRemove };
104
+ },
105
+ template: '<div class="max-w-md"><UiFileItem v-bind="args" @remove="onRemove" /></div>',
106
+ }),
107
+ };
108
+
109
+ /** Row is inert, remove is disabled, and the header row is de-emphasized. */
110
+ export const Disabled: Story = {
111
+ args: {
112
+ filename: 'locked.pdf',
113
+ typeLabel: 'PDF',
114
+ sizeLabel: '2 MB',
115
+ progress: null,
116
+ error: '',
117
+ disabled: true,
118
+ },
119
+ render: (args) => ({
120
+ components: { UiFileItem },
121
+ setup() {
122
+ function onRemove() {}
123
+ return { args, onRemove };
124
+ },
125
+ template: '<div class="max-w-md"><UiFileItem v-bind="args" @remove="onRemove" /></div>',
126
+ }),
127
+ };
128
+
129
+ /** Disabled row that still shows an error (e.g. cannot remove until resolved). */
130
+ export const DisabledWithError: Story = {
131
+ args: {
132
+ filename: 'stuck.tmp',
133
+ typeLabel: 'TMP',
134
+ sizeLabel: '512 KB',
135
+ progress: null,
136
+ error: 'Upload failed — try again later',
137
+ disabled: true,
138
+ },
139
+ render: (args) => ({
140
+ components: { UiFileItem },
141
+ setup() {
142
+ function onRemove() {}
143
+ return { args, onRemove };
144
+ },
145
+ template: '<div class="max-w-md"><UiFileItem v-bind="args" @remove="onRemove" /></div>',
146
+ }),
147
+ };
148
+
149
+ /** Progress and error together (e.g. late failure during upload). */
150
+ export const ProgressAndError: Story = {
151
+ args: {
152
+ filename: 'partial.dat',
153
+ typeLabel: 'DAT',
154
+ sizeLabel: '8 MB',
155
+ progress: 45,
156
+ error: 'Connection lost',
157
+ disabled: false,
158
+ },
159
+ render: (args) => ({
160
+ components: { UiFileItem },
161
+ setup() {
162
+ function onRemove() {}
163
+ return { args, onRemove };
164
+ },
165
+ template: '<div class="max-w-md"><UiFileItem v-bind="args" @remove="onRemove" /></div>',
166
+ }),
167
+ };
168
+
169
+ /** Title only (no type/size line). */
170
+ export const FilenameOnly: Story = {
171
+ args: {
172
+ filename: 'notes.txt',
173
+ typeLabel: undefined,
174
+ sizeLabel: undefined,
175
+ progress: null,
176
+ error: '',
177
+ disabled: false,
178
+ },
179
+ render: (args) => ({
180
+ components: { UiFileItem },
181
+ setup() {
182
+ function onRemove() {}
183
+ return { args, onRemove };
184
+ },
185
+ template: '<div class="max-w-md"><UiFileItem v-bind="args" @remove="onRemove" /></div>',
186
+ }),
187
+ };
188
+
189
+ /**
190
+ * All variants in one column for quick visual comparison.
191
+ */
192
+ export const AllStates: Story = {
193
+ render: () => ({
194
+ components: { UiFileItem },
195
+ setup() {
196
+ function onRemove() {}
197
+ return { onRemove };
198
+ },
199
+ template: `
200
+ <div class="flex max-w-md flex-col gap-4">
201
+ <div class="flex flex-col gap-1">
202
+ <p class="text-content-on-surface-muted text-xs font-medium">Default</p>
203
+ <UiFileItem
204
+ filename="filename.pdf"
205
+ type-label="PDF"
206
+ size-label="1.2 MB"
207
+ @remove="onRemove"
208
+ />
209
+ </div>
210
+ <div class="flex flex-col gap-1">
211
+ <p class="text-content-on-surface-muted text-xs font-medium">Uploading</p>
212
+ <UiFileItem
213
+ filename="uploading.bin"
214
+ type-label="BIN"
215
+ size-label="12 MB"
216
+ :progress="30"
217
+ @remove="onRemove"
218
+ />
219
+ </div>
220
+ <div class="flex flex-col gap-1">
221
+ <p class="text-content-on-surface-muted text-xs font-medium">Complete</p>
222
+ <UiFileItem
223
+ filename="archive.zip"
224
+ type-label="ZIP"
225
+ size-label="4 MB"
226
+ :progress="100"
227
+ @remove="onRemove"
228
+ />
229
+ </div>
230
+ <div class="flex flex-col gap-1">
231
+ <p class="text-content-on-surface-muted text-xs font-medium">Error</p>
232
+ <UiFileItem
233
+ filename="bad.exe"
234
+ type-label="EXE"
235
+ size-label="1 MB"
236
+ error="Unsupported file type"
237
+ @remove="onRemove"
238
+ />
239
+ </div>
240
+ <div class="flex flex-col gap-1">
241
+ <p class="text-content-on-surface-muted text-xs font-medium">Disabled</p>
242
+ <UiFileItem
243
+ filename="locked.pdf"
244
+ type-label="PDF"
245
+ size-label="2 MB"
246
+ disabled
247
+ @remove="onRemove"
248
+ />
249
+ </div>
250
+ <div class="flex flex-col gap-1">
251
+ <p class="text-content-on-surface-muted text-xs font-medium">Disabled + error</p>
252
+ <UiFileItem
253
+ filename="stuck.tmp"
254
+ type-label="TMP"
255
+ size-label="512 KB"
256
+ error="Upload failed — try again later"
257
+ disabled
258
+ @remove="onRemove"
259
+ />
260
+ </div>
261
+ <div class="flex flex-col gap-1">
262
+ <p class="text-content-on-surface-muted text-xs font-medium">Filename only</p>
263
+ <UiFileItem filename="readme.md" @remove="onRemove" />
264
+ </div>
265
+ </div>
266
+ `,
267
+ }),
268
+ };
@@ -0,0 +1,119 @@
1
+ <script setup lang="ts">
2
+ import { UiButton } from '@/components/UiButton';
3
+ import { UiIcon } from '@/components/UiIcon';
4
+ import {
5
+ UiItem,
6
+ UiItemActions,
7
+ UiItemContent,
8
+ UiItemDescription,
9
+ UiItemFooter,
10
+ UiItemMedia,
11
+ UiItemTitle,
12
+ } from '@/components/UiItem';
13
+ import { UiProgress } from '@/components/UiProgress';
14
+ import { cn } from '@/lib/utils';
15
+ import { computed } from 'vue';
16
+ import type { UiFileItemProps } from './types';
17
+
18
+ defineOptions({
19
+ name: 'UiFileItem',
20
+ });
21
+
22
+ /** @see {@link UiFileItemProps} */
23
+ const props = withDefaults(defineProps<UiFileItemProps>(), {
24
+ typeLabel: undefined,
25
+ sizeLabel: undefined,
26
+ progress: null,
27
+ error: null,
28
+ removeLabel: 'Remove file',
29
+ disabled: false,
30
+ });
31
+
32
+ /* eslint-disable jsdoc/require-jsdoc -- emit payload is empty tuple */
33
+ const emit = defineEmits<{
34
+ remove: [];
35
+ }>();
36
+ /* eslint-enable jsdoc/require-jsdoc */
37
+
38
+ /**
39
+ * Drops the last `.ext` segment; leaves `.gitignore`-style names unchanged.
40
+ * @param name - Full file name
41
+ */
42
+ function filenameWithoutExtension(name: string): string {
43
+ const i = name.lastIndexOf('.');
44
+ if (i <= 0) return name;
45
+ return name.slice(0, i);
46
+ }
47
+
48
+ const displayFilename = computed(() => filenameWithoutExtension(props.filename));
49
+
50
+ const showProgress = computed(
51
+ () => props.progress != null && props.progress >= 0 && props.progress <= 100,
52
+ );
53
+ </script>
54
+
55
+ <template>
56
+ <UiItem
57
+ variant="outline"
58
+ size="sm"
59
+ :with-list-semantics="false"
60
+ :inert="disabled ? true : undefined"
61
+ :class="
62
+ cn(
63
+ 'border-border-surface-default bg-background-surface-muted rounded-lg border shadow-none',
64
+ disabled && 'opacity-50',
65
+ )
66
+ "
67
+ >
68
+ <UiItemMedia variant="icon">
69
+ <UiIcon
70
+ name="file"
71
+ class="text-content-on-surface-primary shrink-0"
72
+ :size="16"
73
+ aria-hidden="true"
74
+ />
75
+ </UiItemMedia>
76
+ <UiItemContent class="min-w-0 gap-0">
77
+ <UiItemTitle
78
+ class="body-14-medium text-content-on-surface-primary !line-clamp-none min-w-0 w-full truncate"
79
+ :aria-label="filename"
80
+ >
81
+ {{ displayFilename }}
82
+ </UiItemTitle>
83
+ <UiItemDescription
84
+ v-if="typeLabel || sizeLabel"
85
+ class="label-12-medium text-content-on-surface-muted !line-clamp-none flex flex-wrap items-center"
86
+ >
87
+ <template v-if="typeLabel && sizeLabel">
88
+ <span>{{ typeLabel }}</span>
89
+ <span class="text-content-on-surface-muted px-2" aria-hidden="true">|</span>
90
+ <span>{{ sizeLabel }}</span>
91
+ </template>
92
+ <template v-else>
93
+ {{ typeLabel ?? sizeLabel }}
94
+ </template>
95
+ </UiItemDescription>
96
+ </UiItemContent>
97
+ <UiItemActions>
98
+ <UiButton
99
+ type="button"
100
+ variant="ghost"
101
+ class="size-8 shrink-0 p-0"
102
+ :disabled="disabled"
103
+ :aria-label="removeLabel"
104
+ @click="emit('remove')"
105
+ >
106
+ <UiIcon name="x" :size="16" aria-hidden="true" />
107
+ </UiButton>
108
+ </UiItemActions>
109
+ <UiItemFooter
110
+ v-if="showProgress || error"
111
+ class="flex w-full min-w-0 flex-col items-stretch gap-1"
112
+ >
113
+ <UiProgress v-if="showProgress" :model-value="progress!" class="w-full" />
114
+ <p v-if="error" class="label-12-medium text-destructive" role="alert">
115
+ {{ error }}
116
+ </p>
117
+ </UiItemFooter>
118
+ </UiItem>
119
+ </template>
@@ -0,0 +1,66 @@
1
+ import { render } from '@testing-library/vue';
2
+ import userEvent from '@testing-library/user-event';
3
+ import { describe, expect, test } from 'vitest';
4
+ import UiFileItem from '../UiFileItem.vue';
5
+
6
+ describe('UiFileItem', () => {
7
+ test('renders basename without extension and meta', () => {
8
+ const { getByText, getByLabelText } = render(UiFileItem, {
9
+ props: {
10
+ filename: 'doc.pdf',
11
+ typeLabel: 'PDF',
12
+ sizeLabel: '1 MB',
13
+ },
14
+ });
15
+ expect(getByText('doc')).toBeInTheDocument();
16
+ expect(getByLabelText('doc.pdf')).toBeInTheDocument();
17
+ expect(getByText('PDF')).toBeInTheDocument();
18
+ expect(getByText('|')).toBeInTheDocument();
19
+ expect(getByText('1 MB')).toBeInTheDocument();
20
+ });
21
+
22
+ test('leaves dotfile names without extension segment unchanged', () => {
23
+ const { getByText } = render(UiFileItem, {
24
+ props: { filename: '.gitignore' },
25
+ });
26
+ expect(getByText('.gitignore')).toBeInTheDocument();
27
+ });
28
+
29
+ test('emits remove when remove control is activated', async () => {
30
+ const user = userEvent.setup();
31
+ const { getByRole, emitted } = render(UiFileItem, {
32
+ props: {
33
+ filename: 'x.txt',
34
+ removeLabel: 'Remove file',
35
+ },
36
+ });
37
+ await user.click(getByRole('button', { name: 'Remove file' }));
38
+ expect(emitted('remove')).toHaveLength(1);
39
+ });
40
+
41
+ test('shows error text below the row like progress', () => {
42
+ const { getByText, getByRole } = render(UiFileItem, {
43
+ props: {
44
+ filename: 'bad.exe',
45
+ error: 'Unsupported file type',
46
+ },
47
+ });
48
+ expect(getByText('Unsupported file type')).toBeInTheDocument();
49
+ expect(getByRole('alert')).toHaveTextContent('Unsupported file type');
50
+ });
51
+
52
+ test('does not emit remove when disabled', async () => {
53
+ const user = userEvent.setup();
54
+ const { getByRole, emitted } = render(UiFileItem, {
55
+ props: {
56
+ filename: 'x.txt',
57
+ removeLabel: 'Remove file',
58
+ disabled: true,
59
+ },
60
+ });
61
+ const btn = getByRole('button', { name: 'Remove file' });
62
+ expect(btn).toBeDisabled();
63
+ await user.click(btn);
64
+ expect(emitted('remove')).toBeFalsy();
65
+ });
66
+ });
@@ -0,0 +1,2 @@
1
+ export { default as UiFileItem } from './UiFileItem.vue';
2
+ export type { UiFileItemProps } from './types';
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Row showing a selected or uploading file with optional progress and errors.
3
+ * @category Form Inputs
4
+ * @useCases file upload list, attachment row
5
+ * @keywords file, upload, attachment, progress
6
+ * @related UiFileUploadBox, UiItem, UiButton
7
+ */
8
+ export interface UiFileItemProps {
9
+ /**
10
+ * Full file name (`file.name`). The title omits the final extension; the full name is still exposed to assistive tech.
11
+ */
12
+ filename: string;
13
+ /** Short type label, e.g. `PDF`. */
14
+ typeLabel?: string;
15
+ /** Size label, e.g. `1.2 MB`. */
16
+ sizeLabel?: string;
17
+ /** Upload progress 0–100; omit or `null` to hide the bar. */
18
+ progress?: number | null;
19
+ /** Validation or upload error message. */
20
+ error?: string | null;
21
+ /** Accessible label for the remove control. */
22
+ removeLabel?: string;
23
+ /**
24
+ * When true, the row is non-interactive (`inert`), visually de-emphasized, and remove is disabled.
25
+ */
26
+ disabled?: boolean;
27
+ }