@oaiz/app-kit 0.0.0-stage → 0.1.4128

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 (107) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +143 -2
  3. package/THIRD_PARTY_NOTICES.md +76 -0
  4. package/package.json +139 -4
  5. package/registry.json +1847 -0
  6. package/src/components/activity-timeline.tsx +227 -0
  7. package/src/components/app-shell.tsx +622 -0
  8. package/src/components/bar-list.tsx +47 -0
  9. package/src/components/board.tsx +700 -0
  10. package/src/components/calendar-view.tsx +1388 -0
  11. package/src/components/card-grid.tsx +462 -0
  12. package/src/components/charts.tsx +701 -0
  13. package/src/components/chat-markdown.tsx +230 -0
  14. package/src/components/chat-panel.tsx +760 -0
  15. package/src/components/code-editor.tsx +276 -0
  16. package/src/components/collection-controls.tsx +226 -0
  17. package/src/components/command-palette.tsx +403 -0
  18. package/src/components/confirm-action.tsx +123 -0
  19. package/src/components/data-table.tsx +821 -0
  20. package/src/components/date-input.tsx +429 -0
  21. package/src/components/empty-state.tsx +31 -0
  22. package/src/components/error-state.tsx +37 -0
  23. package/src/components/file-upload.tsx +595 -0
  24. package/src/components/filter-bar.tsx +415 -0
  25. package/src/components/grouped-picker.tsx +250 -0
  26. package/src/components/line-items.tsx +601 -0
  27. package/src/components/list-view.tsx +491 -0
  28. package/src/components/metrics.tsx +53 -0
  29. package/src/components/page-header.tsx +33 -0
  30. package/src/components/property-picker.tsx +546 -0
  31. package/src/components/record-detail.tsx +416 -0
  32. package/src/components/record-form.tsx +295 -0
  33. package/src/components/record-name.tsx +85 -0
  34. package/src/components/save-bar.tsx +142 -0
  35. package/src/components/sign-in.tsx +179 -0
  36. package/src/components/split-view.tsx +128 -0
  37. package/src/components/status-dot.tsx +56 -0
  38. package/src/components/stepper.tsx +153 -0
  39. package/src/components/text-diff-model.ts +111 -0
  40. package/src/components/text-diff.tsx +98 -0
  41. package/src/components/time-zone-picker.tsx +69 -0
  42. package/src/components/ui/accordion.tsx +138 -0
  43. package/src/components/ui/alert-dialog.tsx +67 -0
  44. package/src/components/ui/alert.tsx +65 -0
  45. package/src/components/ui/avatar-group.tsx +119 -0
  46. package/src/components/ui/avatar.tsx +55 -0
  47. package/src/components/ui/badge.tsx +59 -0
  48. package/src/components/ui/bottom-navigation.tsx +102 -0
  49. package/src/components/ui/breadcrumb.tsx +117 -0
  50. package/src/components/ui/button.tsx +71 -0
  51. package/src/components/ui/card.tsx +95 -0
  52. package/src/components/ui/checkbox.tsx +31 -0
  53. package/src/components/ui/collapsible.tsx +27 -0
  54. package/src/components/ui/context-menu.tsx +270 -0
  55. package/src/components/ui/count-up.tsx +136 -0
  56. package/src/components/ui/detail-disclosure-section.tsx +109 -0
  57. package/src/components/ui/dialog.tsx +157 -0
  58. package/src/components/ui/dropdown-menu.tsx +273 -0
  59. package/src/components/ui/form-field.tsx +155 -0
  60. package/src/components/ui/heading.tsx +126 -0
  61. package/src/components/ui/hover-card.tsx +45 -0
  62. package/src/components/ui/input.tsx +50 -0
  63. package/src/components/ui/label.tsx +30 -0
  64. package/src/components/ui/orb-spinner.tsx +238 -0
  65. package/src/components/ui/popover.tsx +59 -0
  66. package/src/components/ui/progress-ring.tsx +125 -0
  67. package/src/components/ui/progress.tsx +38 -0
  68. package/src/components/ui/radio-group.tsx +124 -0
  69. package/src/components/ui/resizable.tsx +48 -0
  70. package/src/components/ui/scroll-fade.tsx +98 -0
  71. package/src/components/ui/segmented-control.tsx +70 -0
  72. package/src/components/ui/select.tsx +230 -0
  73. package/src/components/ui/separator.tsx +29 -0
  74. package/src/components/ui/sheet.tsx +170 -0
  75. package/src/components/ui/shimmer-text.tsx +87 -0
  76. package/src/components/ui/shortcut.tsx +39 -0
  77. package/src/components/ui/skeleton.tsx +15 -0
  78. package/src/components/ui/slider.tsx +48 -0
  79. package/src/components/ui/switch.tsx +44 -0
  80. package/src/components/ui/table.tsx +119 -0
  81. package/src/components/ui/tabs.tsx +80 -0
  82. package/src/components/ui/text.tsx +93 -0
  83. package/src/components/ui/textarea.tsx +51 -0
  84. package/src/components/ui/toast.tsx +141 -0
  85. package/src/components/ui/toaster.tsx +40 -0
  86. package/src/components/ui/tooltip.tsx +38 -0
  87. package/src/components/ui/top-banner.tsx +108 -0
  88. package/src/components/ui/tree-view.tsx +215 -0
  89. package/src/components/ui/use-toast.tsx +184 -0
  90. package/src/components/ui/voice-orb.tsx +252 -0
  91. package/src/hooks/oaiz-chat.tsx +530 -0
  92. package/src/hooks/oaiz-data.tsx +617 -0
  93. package/src/hooks/oaiz-session.tsx +63 -0
  94. package/src/hooks/use-arrivals.ts +19 -0
  95. package/src/hooks/use-breakpoint.ts +100 -0
  96. package/src/hooks/use-media-query.ts +36 -0
  97. package/src/hooks/use-theme.ts +67 -0
  98. package/src/hooks/use-url-state.ts +77 -0
  99. package/src/lib/breakpoints.ts +81 -0
  100. package/src/lib/csp-nonce.ts +15 -0
  101. package/src/lib/format.ts +291 -0
  102. package/src/lib/speech-level.ts +118 -0
  103. package/src/lib/utils.ts +109 -0
  104. package/src/styles/oaiz/app.css +21 -0
  105. package/src/styles/oaiz/scrollbars.css +20 -0
  106. package/src/styles/oaiz/tokens.css +952 -0
  107. package/src/styles/oaiz/voice-orb.css +39 -0
@@ -0,0 +1,595 @@
1
+ import { useId, useRef, useState, type ReactNode } from 'react';
2
+ import {
3
+ File,
4
+ FileImage,
5
+ FileText,
6
+ FileVideo,
7
+ Music,
8
+ Download,
9
+ } from 'lucide-react';
10
+ import { cn } from '../lib/utils';
11
+ import { Button } from './ui/button';
12
+ import { Input } from './ui/input';
13
+ import { Progress } from './ui/progress';
14
+ import { Skeleton } from './ui/skeleton';
15
+ import { Dialog, DialogContent, DialogTitle, DialogTrigger } from './ui/dialog';
16
+ import { Text } from './ui/text';
17
+
18
+ export type FileUploadLabels = {
19
+ choose: string;
20
+ drop: string;
21
+ rejected: string;
22
+ typeError: (name: string) => string;
23
+ sizeError: (name: string, bytes: number) => string;
24
+ countError: string;
25
+ acceptedTypes: (accept: string) => string;
26
+ maximumSize: (bytes: number) => string;
27
+ };
28
+ const uploadDefaults: FileUploadLabels = {
29
+ choose: 'Choose files',
30
+ drop: 'or drop files here',
31
+ rejected: 'Some files were not added',
32
+ typeError: (name) => `${name}: this file type is not accepted.`,
33
+ sizeError: (name, bytes) =>
34
+ `${name}: the maximum size is ${bytes.toLocaleString()} bytes.`,
35
+ countError: 'Choose one file at a time.',
36
+ acceptedTypes: (accept) => `Accepted types: ${accept}.`,
37
+ maximumSize: (bytes) =>
38
+ `Maximum size: ${bytes.toLocaleString()} bytes per file.`,
39
+ };
40
+ export type FileRejection = { file: File; message: string };
41
+ export type FileUploadProps = {
42
+ label: ReactNode;
43
+ description?: ReactNode;
44
+ /** Native accept syntax: extensions, MIME types, or MIME wildcards, separated by commas. */
45
+ accept?: string;
46
+ maxSize?: number;
47
+ multiple?: boolean;
48
+ disabled?: boolean;
49
+ dropZone?: boolean;
50
+ onFiles: (files: File[]) => void;
51
+ onReject?: (files: FileRejection[]) => void;
52
+ labels?: Partial<FileUploadLabels>;
53
+ className?: string;
54
+ };
55
+ function accepts(file: File, accept: string) {
56
+ return accept
57
+ .split(',')
58
+ .map((entry) => entry.trim().toLowerCase())
59
+ .filter(Boolean)
60
+ .some((entry) =>
61
+ entry.startsWith('.')
62
+ ? file.name.toLowerCase().endsWith(entry)
63
+ : entry.endsWith('/*')
64
+ ? file.type.toLowerCase().startsWith(entry.slice(0, -1))
65
+ : file.type.toLowerCase() === entry,
66
+ );
67
+ }
68
+
69
+ /** Selection validation gives feedback; the upload endpoint still owns content and permission checks. */
70
+ export function FileUpload({
71
+ label,
72
+ description,
73
+ accept,
74
+ maxSize,
75
+ multiple = true,
76
+ disabled = false,
77
+ dropZone = true,
78
+ onFiles,
79
+ onReject,
80
+ labels: suppliedLabels,
81
+ className,
82
+ }: FileUploadProps) {
83
+ const labels = { ...uploadDefaults, ...suppliedLabels };
84
+ const id = useId();
85
+ const input = useRef<HTMLInputElement>(null);
86
+ const [rejected, setRejected] = useState<FileRejection[]>([]);
87
+ const [dragging, setDragging] = useState(false);
88
+ const guidance =
89
+ description ??
90
+ [
91
+ accept ? labels.acceptedTypes(accept) : '',
92
+ maxSize !== undefined ? labels.maximumSize(maxSize) : '',
93
+ ]
94
+ .filter(Boolean)
95
+ .join(' ');
96
+ function select(files: File[]) {
97
+ if (disabled) return;
98
+ const failures: FileRejection[] = [];
99
+ const accepted: File[] = [];
100
+ for (const file of files) {
101
+ const message =
102
+ !multiple && files.length > 1
103
+ ? labels.countError
104
+ : accept && !accepts(file, accept)
105
+ ? labels.typeError(file.name)
106
+ : maxSize !== undefined && file.size > maxSize
107
+ ? labels.sizeError(file.name, maxSize)
108
+ : undefined;
109
+ if (message) failures.push({ file, message });
110
+ else accepted.push(file);
111
+ }
112
+ setRejected(failures);
113
+ if (failures.length > 0) onReject?.(failures);
114
+ if (accepted.length > 0) onFiles(accepted);
115
+ }
116
+ return (
117
+ <section
118
+ aria-labelledby={`${id}-label`}
119
+ className={cn('flex flex-col gap-inline', className)}
120
+ >
121
+ <p id={`${id}-label`} className="text-sm font-medium">
122
+ {label}
123
+ </p>
124
+ {guidance && (
125
+ <Text id={`${id}-hint`} size="sm" variant="muted">
126
+ {guidance}
127
+ </Text>
128
+ )}
129
+ <div
130
+ className={cn(
131
+ 'flex flex-wrap items-center gap-inline rounded-md',
132
+ dropZone && 'border border-dashed border-input p-inset',
133
+ dragging && 'bg-accent',
134
+ )}
135
+ onDragOver={(event) => {
136
+ if (dropZone) {
137
+ event.preventDefault();
138
+ event.dataTransfer.dropEffect = disabled ? 'none' : 'copy';
139
+ if (!disabled) setDragging(true);
140
+ }
141
+ }}
142
+ onDragLeave={() => setDragging(false)}
143
+ onDrop={(event) => {
144
+ if (!dropZone) return;
145
+ event.preventDefault();
146
+ setDragging(false);
147
+ select(Array.from(event.dataTransfer.files));
148
+ }}
149
+ >
150
+ <Input
151
+ ref={input}
152
+ id={id}
153
+ type="file"
154
+ className="sr-only h-px w-px border-0 p-0"
155
+ tabIndex={-1}
156
+ accept={accept}
157
+ multiple={multiple}
158
+ disabled={disabled}
159
+ aria-labelledby={`${id}-label`}
160
+ aria-describedby={guidance ? `${id}-hint` : undefined}
161
+ onChange={(event) => {
162
+ select(Array.from(event.target.files ?? []));
163
+ event.target.value = '';
164
+ }}
165
+ />
166
+ <Button
167
+ type="button"
168
+ variant="outline"
169
+ disabled={disabled}
170
+ aria-describedby={guidance ? `${id}-hint` : undefined}
171
+ onClick={() => input.current?.click()}
172
+ >
173
+ {labels.choose}
174
+ </Button>
175
+ {dropZone && (
176
+ <Text as="span" size="sm" variant="muted">
177
+ {labels.drop}
178
+ </Text>
179
+ )}
180
+ </div>
181
+ {rejected.length > 0 && (
182
+ <div role="alert" className="text-sm text-destructive-text">
183
+ <p>{labels.rejected}</p>
184
+ <ul className="list-inside list-disc">
185
+ {rejected.map((item, index) => (
186
+ <li key={`${item.file.name}-${index}`}>{item.message}</li>
187
+ ))}
188
+ </ul>
189
+ </div>
190
+ )}
191
+ </section>
192
+ );
193
+ }
194
+
195
+ export type Attachment = {
196
+ id: string;
197
+ name: string;
198
+ size?: number;
199
+ href?: string;
200
+ previewUrl?: string;
201
+ mimeType?: string;
202
+ status?: 'ready' | 'uploading' | 'error';
203
+ /** 0–100; omit for an indeterminate upload. */
204
+ progress?: number;
205
+ error?: string;
206
+ };
207
+ export type AttachmentLabels = {
208
+ list: string;
209
+ uploading: string;
210
+ failed: string;
211
+ empty: string;
212
+ cancelText: string;
213
+ removeText: string;
214
+ retryText: string;
215
+ remove: (name: string) => string;
216
+ cancel: (name: string) => string;
217
+ retry: (name: string) => string;
218
+ progress: (name: string) => string;
219
+ preview: (name: string) => string;
220
+ previewLoading: string;
221
+ previewFailed: string;
222
+ close: string;
223
+ download: (name: string) => string;
224
+ downloadText: string;
225
+ downloading: string;
226
+ downloadFailed: string;
227
+ };
228
+ const attachmentDefaults: AttachmentLabels = {
229
+ list: 'Attachments',
230
+ uploading: 'Uploading…',
231
+ failed: 'Upload failed',
232
+ empty: 'No attachments.',
233
+ cancelText: 'Cancel',
234
+ removeText: 'Remove',
235
+ retryText: 'Retry',
236
+ remove: (name) => `Remove ${name}`,
237
+ cancel: (name) => `Cancel upload of ${name}`,
238
+ retry: (name) => `Retry ${name}`,
239
+ progress: (name) => `Upload progress for ${name}`,
240
+ preview: (name) => `Preview ${name}`,
241
+ previewLoading: 'Loading preview…',
242
+ previewFailed: 'Preview unavailable.',
243
+ close: 'Close',
244
+ download: (name) => `Download ${name}`,
245
+ downloadText: 'Download',
246
+ downloading: 'Downloading…',
247
+ downloadFailed: 'Download failed. Try again.',
248
+ };
249
+ export type AttachmentListProps = {
250
+ attachments: readonly Attachment[];
251
+ onRemove?: (id: string) => void;
252
+ onCancel?: (id: string) => void;
253
+ onRetry?: (id: string) => void;
254
+ /** The caller retrieves the content and starts its download. Reject to show a retryable error. */
255
+ onDownload?: (id: string) => Promise<void>;
256
+ /** Gallery previews contain the complete image; list previews are small thumbnails. */
257
+ variant?: 'list' | 'gallery';
258
+ labels?: Partial<AttachmentLabels>;
259
+ locale?: string;
260
+ className?: string;
261
+ };
262
+ function attachmentUrl(value: string | undefined) {
263
+ if (!value) return undefined;
264
+ try {
265
+ const url = new URL(value, 'https://relative.invalid');
266
+ return ['https:', 'http:', 'blob:'].includes(url.protocol)
267
+ ? value
268
+ : undefined;
269
+ } catch {
270
+ return undefined;
271
+ }
272
+ }
273
+ export function AttachmentList({
274
+ attachments,
275
+ onRemove,
276
+ onCancel,
277
+ onRetry,
278
+ onDownload,
279
+ variant = 'list',
280
+ labels: suppliedLabels,
281
+ locale,
282
+ className,
283
+ }: AttachmentListProps) {
284
+ const labels = { ...attachmentDefaults, ...suppliedLabels };
285
+ if (!attachments.length)
286
+ return (
287
+ <Text size="sm" variant="muted">
288
+ {labels.empty}
289
+ </Text>
290
+ );
291
+ return (
292
+ <ul
293
+ aria-label={labels.list}
294
+ className={cn(
295
+ variant === 'gallery'
296
+ ? 'grid grid-cols-[repeat(auto-fill,minmax(min(100%,15rem),1fr))] gap-stack'
297
+ : 'flex flex-col gap-inline',
298
+ className,
299
+ )}
300
+ >
301
+ {attachments.map((file) => (
302
+ <AttachmentItem
303
+ key={file.id}
304
+ file={file}
305
+ labels={labels}
306
+ locale={locale}
307
+ variant={variant}
308
+ onDownload={onDownload}
309
+ onRemove={onRemove}
310
+ onRetry={onRetry}
311
+ onCancel={onCancel}
312
+ />
313
+ ))}
314
+ </ul>
315
+ );
316
+ }
317
+
318
+ function PreviewImage({
319
+ src,
320
+ name,
321
+ labels,
322
+ thumbnail = false,
323
+ }: {
324
+ src: string;
325
+ name: string;
326
+ labels: AttachmentLabels;
327
+ thumbnail?: boolean;
328
+ }) {
329
+ const [state, setState] = useState<'loading' | 'ready' | 'error'>('loading');
330
+ const [attempt, setAttempt] = useState(0);
331
+ return (
332
+ <div
333
+ className={cn(
334
+ 'relative flex min-w-0 items-center justify-center',
335
+ thumbnail ? 'size-12 shrink-0' : 'aspect-video w-full',
336
+ )}
337
+ >
338
+ {state === 'loading' && (
339
+ <Skeleton
340
+ aria-label={labels.previewLoading}
341
+ className="absolute inset-0"
342
+ />
343
+ )}
344
+ {state === 'error' && thumbnail ? (
345
+ <FileImage
346
+ aria-label={labels.previewFailed}
347
+ className="size-6 text-muted-foreground"
348
+ />
349
+ ) : state === 'error' ? (
350
+ <div className="flex flex-col items-center gap-inline p-inline">
351
+ <Text size="sm" variant="muted" role="status">
352
+ {labels.previewFailed}
353
+ </Text>
354
+ <Button
355
+ type="button"
356
+ size="sm"
357
+ variant="outline"
358
+ onClick={() => {
359
+ setState('loading');
360
+ setAttempt((value) => value + 1);
361
+ }}
362
+ >
363
+ {labels.retryText}
364
+ </Button>
365
+ </div>
366
+ ) : (
367
+ <img
368
+ key={attempt}
369
+ src={src}
370
+ alt={name}
371
+ onLoad={() => setState('ready')}
372
+ onError={() => setState('error')}
373
+ className={cn(
374
+ 'h-full w-full object-contain',
375
+ state === 'loading' && 'invisible',
376
+ )}
377
+ />
378
+ )}
379
+ </div>
380
+ );
381
+ }
382
+
383
+ function AttachmentItem({
384
+ file,
385
+ labels,
386
+ locale,
387
+ variant,
388
+ onDownload,
389
+ onRemove,
390
+ onRetry,
391
+ onCancel,
392
+ }: {
393
+ file: Attachment;
394
+ labels: AttachmentLabels;
395
+ locale?: string;
396
+ variant: 'list' | 'gallery';
397
+ } & Pick<
398
+ AttachmentListProps,
399
+ 'onDownload' | 'onRemove' | 'onRetry' | 'onCancel'
400
+ >) {
401
+ const href = attachmentUrl(file.href);
402
+ const preview = attachmentUrl(file.previewUrl);
403
+ const [downloadState, setDownloadState] = useState<
404
+ 'ready' | 'pending' | 'error'
405
+ >('ready');
406
+ const downloading = useRef(false);
407
+ const gallery = variant === 'gallery';
408
+ const Icon = file.mimeType?.startsWith('image/')
409
+ ? FileImage
410
+ : file.mimeType?.startsWith('video/')
411
+ ? FileVideo
412
+ : file.mimeType?.startsWith('audio/')
413
+ ? Music
414
+ : file.mimeType === 'application/pdf' ||
415
+ file.mimeType?.startsWith('text/')
416
+ ? FileText
417
+ : File;
418
+ async function download() {
419
+ if (!onDownload || downloading.current) return;
420
+ downloading.current = true;
421
+ setDownloadState('pending');
422
+ try {
423
+ await onDownload(file.id);
424
+ setDownloadState('ready');
425
+ } catch {
426
+ setDownloadState('error');
427
+ } finally {
428
+ downloading.current = false;
429
+ }
430
+ }
431
+ return (
432
+ <li
433
+ className={cn(
434
+ 'flex min-w-0 gap-inline rounded-md border p-inset',
435
+ gallery ? 'flex-col' : 'flex-wrap items-center',
436
+ )}
437
+ >
438
+ {preview ? (
439
+ <div className={cn(gallery ? 'w-full' : 'shrink-0')}>
440
+ <PreviewImage
441
+ key={preview}
442
+ src={preview}
443
+ name={file.name}
444
+ labels={labels}
445
+ thumbnail={!gallery}
446
+ />
447
+ <Dialog>
448
+ <DialogTrigger asChild>
449
+ <Button
450
+ type="button"
451
+ variant="ghost"
452
+ size="sm"
453
+ aria-label={labels.preview(file.name)}
454
+ className="mt-1 h-auto min-h-9 max-w-full whitespace-normal break-words text-left"
455
+ >
456
+ {labels.preview(file.name)}
457
+ </Button>
458
+ </DialogTrigger>
459
+ <DialogContent
460
+ closeLabel={labels.close}
461
+ aria-describedby={undefined}
462
+ className="max-w-4xl"
463
+ >
464
+ <DialogTitle className="break-words pr-stack">
465
+ {file.name}
466
+ </DialogTitle>
467
+ <PreviewImage src={preview} name={file.name} labels={labels} />
468
+ </DialogContent>
469
+ </Dialog>
470
+ </div>
471
+ ) : (
472
+ <Icon
473
+ aria-hidden="true"
474
+ className={cn(
475
+ 'shrink-0 text-muted-foreground',
476
+ gallery ? 'my-stack size-12 self-center' : 'size-6',
477
+ )}
478
+ />
479
+ )}
480
+ <div className="flex min-w-0 flex-1 flex-col gap-1">
481
+ {href ? (
482
+ <a
483
+ href={href}
484
+ className="break-words text-sm underline underline-offset-2"
485
+ >
486
+ {file.name}
487
+ </a>
488
+ ) : (
489
+ <span className="break-words text-sm">{file.name}</span>
490
+ )}
491
+ {file.size !== undefined && (
492
+ <Text as="span" size="xs" variant="muted">
493
+ {new Intl.NumberFormat(locale, {
494
+ style: 'unit',
495
+ unit: 'byte',
496
+ unitDisplay: 'short',
497
+ }).format(file.size)}
498
+ </Text>
499
+ )}
500
+ {file.status === 'uploading' && (
501
+ <>
502
+ <Text size="sm" role="status">
503
+ {labels.uploading}
504
+ </Text>
505
+ <Progress
506
+ aria-label={labels.progress(file.name)}
507
+ max={100}
508
+ value={
509
+ file.progress === undefined || !Number.isFinite(file.progress)
510
+ ? undefined
511
+ : Math.min(100, Math.max(0, file.progress))
512
+ }
513
+ className="h-2 w-full"
514
+ />
515
+ </>
516
+ )}
517
+ {file.status === 'error' && (
518
+ <Text size="sm" variant="destructive" role="alert">
519
+ {file.error ?? labels.failed}
520
+ </Text>
521
+ )}
522
+ {downloadState === 'error' && (
523
+ <Text size="sm" variant="destructive" role="alert">
524
+ {labels.downloadFailed}
525
+ </Text>
526
+ )}
527
+ {downloadState === 'pending' && (
528
+ <Text size="sm" role="status">
529
+ {labels.downloading}
530
+ </Text>
531
+ )}
532
+ </div>
533
+ <div className="flex shrink-0 flex-wrap gap-1">
534
+ {file.status !== 'uploading' && onDownload && (
535
+ <Button
536
+ type="button"
537
+ variant="outline"
538
+ size="sm"
539
+ disabled={downloadState === 'pending'}
540
+ aria-label={labels.download(file.name)}
541
+ onClick={() => void download()}
542
+ >
543
+ <Download aria-hidden="true" />
544
+ {downloadState === 'error' ? labels.retryText : labels.downloadText}
545
+ </Button>
546
+ )}
547
+ {file.status !== 'uploading' && !onDownload && href && (
548
+ <Button asChild variant="outline" size="sm">
549
+ <a
550
+ href={href}
551
+ download={file.name}
552
+ aria-label={labels.download(file.name)}
553
+ >
554
+ <Download aria-hidden="true" />
555
+ {labels.downloadText}
556
+ </a>
557
+ </Button>
558
+ )}
559
+ {file.status === 'uploading' && onCancel && (
560
+ <Button
561
+ type="button"
562
+ variant="ghost"
563
+ size="sm"
564
+ aria-label={labels.cancel(file.name)}
565
+ onClick={() => onCancel(file.id)}
566
+ >
567
+ {labels.cancelText}
568
+ </Button>
569
+ )}
570
+ {file.status === 'error' && onRetry && (
571
+ <Button
572
+ type="button"
573
+ variant="ghost"
574
+ size="sm"
575
+ aria-label={labels.retry(file.name)}
576
+ onClick={() => onRetry(file.id)}
577
+ >
578
+ {labels.retryText}
579
+ </Button>
580
+ )}
581
+ {file.status !== 'uploading' && onRemove && (
582
+ <Button
583
+ type="button"
584
+ variant="ghost"
585
+ size="sm"
586
+ aria-label={labels.remove(file.name)}
587
+ onClick={() => onRemove(file.id)}
588
+ >
589
+ {labels.removeText}
590
+ </Button>
591
+ )}
592
+ </div>
593
+ </li>
594
+ );
595
+ }