@freightos/freightwind 2.1.3 → 2.1.4
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/cjs/components/upload.js +321 -0
- package/dist/cjs/index.js +5 -1
- package/dist/cjs/lib/file-extensions.js +678 -0
- package/dist/esm/components/upload.js +318 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/lib/file-extensions.js +671 -0
- package/dist/types/components/chip.d.ts +1 -1
- package/dist/types/components/upload.d.ts +66 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/lib/file-extensions.d.ts +52 -0
- package/package.json +3 -1
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { forwardRef, useState, } from 'react';
|
|
4
|
+
import { cva } from 'class-variance-authority';
|
|
5
|
+
import { useDirection } from '@radix-ui/react-direction';
|
|
6
|
+
import { cn } from '../lib/utils';
|
|
7
|
+
import { iconMap } from '../lib/icon-utils';
|
|
8
|
+
import { useStableId } from '../lib/use-stable-id';
|
|
9
|
+
import { hasValidExtension } from '../lib/file-extensions';
|
|
10
|
+
const uploadVariants = cva('fw-base group relative flex select-none rounded-fds-md outline-none transition-colors has-[:focus-visible]:ring-2 has-[:focus-visible]:ring-fds-blue-30 has-[:focus-visible]:ring-offset-2', {
|
|
11
|
+
variants: {
|
|
12
|
+
variant: {
|
|
13
|
+
rectangle: 'items-center gap-fds-sm p-fds-lg',
|
|
14
|
+
square: 'h-[99px] w-[100px] flex-col items-center justify-center gap-[10px] px-[26px] py-[23px]',
|
|
15
|
+
},
|
|
16
|
+
state: {
|
|
17
|
+
default: 'cursor-pointer justify-center bg-fds-gray-10 dark:bg-fds-gray-90',
|
|
18
|
+
forbidden: 'cursor-not-allowed justify-center bg-fds-gray-10 dark:bg-fds-gray-90',
|
|
19
|
+
uploading: 'cursor-uploading justify-center border border-solid border-fds-gray-30 bg-fds-gray-10 dark:border-fds-gray-70 dark:bg-fds-gray-90',
|
|
20
|
+
'uploading-spinner': 'cursor-uploading justify-center border border-solid border-fds-gray-30 bg-fds-gray-10 dark:border-fds-gray-70 dark:bg-fds-gray-90',
|
|
21
|
+
success: 'cursor-pointer border border-solid border-fds-blue-30 bg-fds-gray-10 hover:border-fds-blue-40 dark:border-fds-blue-30 dark:bg-fds-gray-90',
|
|
22
|
+
error: 'cursor-not-allowed border border-solid border-fds-red-30 bg-fds-gray-10 dark:border-fds-red-30 dark:bg-fds-gray-90',
|
|
23
|
+
disabled: 'cursor-not-allowed-gray border border-solid border-fds-gray-30 bg-fds-gray-10 text-fds-gray-50 [&_*]:pointer-events-none dark:border-fds-gray-70 dark:bg-fds-gray-90 dark:text-fds-gray-50',
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
defaultVariants: { variant: 'rectangle', state: 'default' },
|
|
27
|
+
});
|
|
28
|
+
const DEFAULT_LABELS = {
|
|
29
|
+
idleTitle: 'Upload your document',
|
|
30
|
+
idleSubtitle: 'Click or drag your file here',
|
|
31
|
+
idleCompact: 'Upload',
|
|
32
|
+
uploading: 'Uploading…',
|
|
33
|
+
forbidden: {
|
|
34
|
+
multiple: { title: 'Oops!', subtitle: 'You can only drag one file', compact: 'Oops!' },
|
|
35
|
+
type: { title: 'Oops!', subtitle: 'Unsupported file format', compact: 'Oops!' },
|
|
36
|
+
size: { title: 'Oops!', subtitle: 'File is too large', compact: 'Oops!' },
|
|
37
|
+
extension: { title: 'Oops!', subtitle: 'Invalid file extension', compact: 'Oops!' },
|
|
38
|
+
custom: { title: 'Oops!', subtitle: 'This file is not allowed', compact: 'Oops!' },
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
const DEFAULT_ICONS = {
|
|
42
|
+
idleRectangle: 'document',
|
|
43
|
+
idleSquare: 'plus',
|
|
44
|
+
forbidden: 'block',
|
|
45
|
+
success: 'check-circled',
|
|
46
|
+
error: 'clear-circled',
|
|
47
|
+
uploading: 'loading',
|
|
48
|
+
remove: 'trash',
|
|
49
|
+
};
|
|
50
|
+
const identity = (k) => k;
|
|
51
|
+
function truncateMiddle(name, max) {
|
|
52
|
+
if (name.length <= max)
|
|
53
|
+
return name;
|
|
54
|
+
const dot = name.lastIndexOf('.');
|
|
55
|
+
const ext = dot > 0 ? name.slice(dot) : '';
|
|
56
|
+
const head = name.slice(0, Math.max(2, Math.floor((max - ext.length - 1) / 2)));
|
|
57
|
+
return `${head}…${ext || name.slice(-Math.max(2, Math.floor(max / 2)))}`;
|
|
58
|
+
}
|
|
59
|
+
function buildFileLabel(allFiles, isSquare) {
|
|
60
|
+
const names = allFiles.map((f) => f.name);
|
|
61
|
+
const tooltip = names.join('\n');
|
|
62
|
+
if (names.length === 1) {
|
|
63
|
+
return { display: isSquare ? truncateMiddle(names[0], 12) : names[0], tooltip };
|
|
64
|
+
}
|
|
65
|
+
const shown = names.slice(0, 2).map((n) => truncateMiddle(n, 12));
|
|
66
|
+
const extra = names.length - 2;
|
|
67
|
+
const display = shown.join(', ') + (extra > 0 ? `, +${extra}` : '');
|
|
68
|
+
return { display, tooltip };
|
|
69
|
+
}
|
|
70
|
+
const EXT_TO_MIME = {
|
|
71
|
+
'.pdf': ['application/pdf'],
|
|
72
|
+
'.png': ['image/png'],
|
|
73
|
+
'.jpg': ['image/jpeg'],
|
|
74
|
+
'.jpeg': ['image/jpeg'],
|
|
75
|
+
'.gif': ['image/gif'],
|
|
76
|
+
'.webp': ['image/webp'],
|
|
77
|
+
'.svg': ['image/svg+xml'],
|
|
78
|
+
'.xlsx': ['application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'],
|
|
79
|
+
'.xls': ['application/vnd.ms-excel'],
|
|
80
|
+
'.csv': ['text/csv', 'application/csv', 'text/plain'],
|
|
81
|
+
'.doc': ['application/msword'],
|
|
82
|
+
'.docx': ['application/vnd.openxmlformats-officedocument.wordprocessingml.document'],
|
|
83
|
+
'.txt': ['text/plain'],
|
|
84
|
+
'.zip': ['application/zip', 'application/x-zip-compressed'],
|
|
85
|
+
};
|
|
86
|
+
function mimeMatchesAccept(mime, accept) {
|
|
87
|
+
return accept.some((rule) => {
|
|
88
|
+
if (rule.endsWith('/*'))
|
|
89
|
+
return mime.startsWith(rule.slice(0, -1));
|
|
90
|
+
if (rule.startsWith('.'))
|
|
91
|
+
return (EXT_TO_MIME[rule.toLowerCase()] ?? []).includes(mime);
|
|
92
|
+
return mime === rule;
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
function extMatchesAccept(filename, accept) {
|
|
96
|
+
const dot = filename.lastIndexOf('.');
|
|
97
|
+
if (dot < 0)
|
|
98
|
+
return false;
|
|
99
|
+
const ext = filename.slice(dot).toLowerCase();
|
|
100
|
+
return accept.some((rule) => rule.toLowerCase() === ext);
|
|
101
|
+
}
|
|
102
|
+
function fileMatchesAccept(file, accept) {
|
|
103
|
+
return mimeMatchesAccept(file.type, accept) || extMatchesAccept(file.name, accept);
|
|
104
|
+
}
|
|
105
|
+
function validateDragItems(items, { maxFiles, accept, alreadyHeld = 0 }) {
|
|
106
|
+
const limit = maxFiles ?? 1;
|
|
107
|
+
if (items.length + alreadyHeld > limit)
|
|
108
|
+
return { ok: false, reason: 'multiple' };
|
|
109
|
+
if (accept && accept.length > 0) {
|
|
110
|
+
for (let i = 0; i < items.length; i++) {
|
|
111
|
+
const item = items[i];
|
|
112
|
+
if (!item || item.kind !== 'file')
|
|
113
|
+
continue;
|
|
114
|
+
if (!mimeMatchesAccept(item.type, accept))
|
|
115
|
+
return { ok: false, reason: 'type' };
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return { ok: true };
|
|
119
|
+
}
|
|
120
|
+
function validatePickedFile(file, { accept, maxSize }) {
|
|
121
|
+
if (!hasValidExtension(file.name))
|
|
122
|
+
return { ok: false, reason: 'extension' };
|
|
123
|
+
if (accept && accept.length > 0 && !fileMatchesAccept(file, accept)) {
|
|
124
|
+
return { ok: false, reason: 'type' };
|
|
125
|
+
}
|
|
126
|
+
if (maxSize != null && file.size > maxSize)
|
|
127
|
+
return { ok: false, reason: 'size' };
|
|
128
|
+
return { ok: true };
|
|
129
|
+
}
|
|
130
|
+
export const Upload = forwardRef(function Upload({ dataTestId, variant = 'rectangle', value, files: filesProp, maxFiles, accept, maxSize, isError = false, isDisabled = false, isFillContainer = false, labels, t = identity, onUpload, onRemove, onForbidden, ariaLabel, defaultUploading = false, defaultUploadProgress, defaultForbidden, uploadingStyle = 'progress', className, ...rest }, ref) {
|
|
131
|
+
const inputId = useStableId('upload');
|
|
132
|
+
const dir = useDirection();
|
|
133
|
+
const [forbiddenReason, setForbiddenReason] = useState(defaultForbidden ?? null);
|
|
134
|
+
const [isUploading, setIsUploading] = useState(defaultUploading);
|
|
135
|
+
const [uploadProgress, setUploadProgress] = useState(defaultUploadProgress ?? null);
|
|
136
|
+
const mergedLabels = { ...DEFAULT_LABELS, ...labels };
|
|
137
|
+
const mergedForbidden = {
|
|
138
|
+
...DEFAULT_LABELS.forbidden,
|
|
139
|
+
...(labels?.forbidden ?? {}),
|
|
140
|
+
};
|
|
141
|
+
const fbCopy = mergedForbidden[forbiddenReason ?? 'multiple'];
|
|
142
|
+
const allFiles = filesProp ?? (value ? [value] : []);
|
|
143
|
+
const hasFiles = allFiles.length > 0;
|
|
144
|
+
const effectiveState = isDisabled
|
|
145
|
+
? 'disabled'
|
|
146
|
+
: forbiddenReason
|
|
147
|
+
? 'forbidden'
|
|
148
|
+
: isUploading
|
|
149
|
+
? uploadingStyle === 'spinner' ? 'uploading-spinner' : 'uploading'
|
|
150
|
+
: isError
|
|
151
|
+
? 'error'
|
|
152
|
+
: hasFiles
|
|
153
|
+
? 'success'
|
|
154
|
+
: 'default';
|
|
155
|
+
const isSquare = variant === 'square';
|
|
156
|
+
const isMultiple = maxFiles == null || maxFiles > 1;
|
|
157
|
+
const acceptAttr = accept?.join(',');
|
|
158
|
+
const triggerUpload = (selected) => {
|
|
159
|
+
if (selected.length === 0)
|
|
160
|
+
return;
|
|
161
|
+
onUpload?.(selected, (v, progress) => {
|
|
162
|
+
setIsUploading(v);
|
|
163
|
+
setUploadProgress(v && progress !== undefined ? progress : null);
|
|
164
|
+
});
|
|
165
|
+
};
|
|
166
|
+
const handleDragEnter = (e) => {
|
|
167
|
+
if (isDisabled)
|
|
168
|
+
return;
|
|
169
|
+
e.preventDefault();
|
|
170
|
+
const result = validateDragItems(e.dataTransfer.items, { maxFiles, accept: accept, alreadyHeld: allFiles.length });
|
|
171
|
+
if (!result.ok) {
|
|
172
|
+
setForbiddenReason(result.reason);
|
|
173
|
+
onForbidden?.(result.reason);
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
const handleDragLeave = (e) => {
|
|
177
|
+
if (e.currentTarget.contains(e.relatedTarget))
|
|
178
|
+
return;
|
|
179
|
+
setForbiddenReason(null);
|
|
180
|
+
};
|
|
181
|
+
const handleDrop = (e) => {
|
|
182
|
+
if (isDisabled)
|
|
183
|
+
return;
|
|
184
|
+
e.preventDefault();
|
|
185
|
+
setForbiddenReason(null);
|
|
186
|
+
const dropped = Array.from(e.dataTransfer.files);
|
|
187
|
+
const limit = maxFiles ?? 1;
|
|
188
|
+
if (dropped.length + allFiles.length > limit) {
|
|
189
|
+
setForbiddenReason('multiple');
|
|
190
|
+
onForbidden?.('multiple');
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
for (const f of dropped) {
|
|
194
|
+
const result = validatePickedFile(f, { accept: accept, maxSize });
|
|
195
|
+
if (!result.ok) {
|
|
196
|
+
setForbiddenReason(result.reason);
|
|
197
|
+
onForbidden?.(result.reason);
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
triggerUpload(dropped);
|
|
202
|
+
};
|
|
203
|
+
const handleNativeChange = (e) => {
|
|
204
|
+
const selected = Array.from(e.target.files ?? []);
|
|
205
|
+
e.target.value = '';
|
|
206
|
+
const limit = maxFiles ?? 1;
|
|
207
|
+
if (selected.length + allFiles.length > limit) {
|
|
208
|
+
setForbiddenReason('multiple');
|
|
209
|
+
onForbidden?.('multiple');
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
for (const f of selected) {
|
|
213
|
+
const result = validatePickedFile(f, { accept: accept, maxSize });
|
|
214
|
+
if (!result.ok) {
|
|
215
|
+
setForbiddenReason(result.reason);
|
|
216
|
+
onForbidden?.(result.reason);
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
setForbiddenReason(null);
|
|
221
|
+
triggerUpload(selected);
|
|
222
|
+
};
|
|
223
|
+
const handleRemoveClick = (e) => {
|
|
224
|
+
e.preventDefault();
|
|
225
|
+
e.stopPropagation();
|
|
226
|
+
onRemove?.();
|
|
227
|
+
};
|
|
228
|
+
const renderIdle = () => {
|
|
229
|
+
const idleIconName = isSquare ? DEFAULT_ICONS.idleSquare : DEFAULT_ICONS.idleRectangle;
|
|
230
|
+
const IconCmp = iconMap[idleIconName];
|
|
231
|
+
const tone = effectiveState === 'disabled'
|
|
232
|
+
? 'text-fds-gray-50 dark:text-fds-gray-50'
|
|
233
|
+
: 'text-fds-gray-80 dark:text-fds-gray-20';
|
|
234
|
+
if (!isSquare) {
|
|
235
|
+
return (_jsxs(_Fragment, { children: [_jsx(IconCmp, { size: "md", className: cn('shrink-0 rtl:scale-x-[-1]', tone), "aria-hidden": true, "data-test-id": `${dataTestId}-idle-icon` }), _jsxs("div", { className: "flex min-w-0 flex-col gap-fds-xs text-start", children: [_jsx("span", { className: cn('w-[130px] text-fds-sm font-fds-regular leading-fds-body', tone), "data-test-id": `${dataTestId}-idle-title`, children: t(mergedLabels.idleTitle) }), _jsx("span", { className: cn('w-[132px] text-fds-xs font-fds-bold leading-fds-body', tone), "data-test-id": `${dataTestId}-idle-subtitle`, children: t(mergedLabels.idleSubtitle) })] })] }));
|
|
236
|
+
}
|
|
237
|
+
return (_jsxs(_Fragment, { children: [_jsx(IconCmp, { className: cn('w-[18.67px] h-[18.67px]', tone), "aria-hidden": true, "data-test-id": `${dataTestId}-idle-icon` }), _jsx("span", { className: cn('w-12 text-fds-base font-fds-regular leading-fds-body', tone), "data-test-id": `${dataTestId}-idle-compact`, children: t(mergedLabels.idleCompact) })] }));
|
|
238
|
+
};
|
|
239
|
+
const renderForbidden = () => {
|
|
240
|
+
const IconCmp = iconMap[DEFAULT_ICONS.forbidden];
|
|
241
|
+
if (!isSquare) {
|
|
242
|
+
return (_jsxs(_Fragment, { children: [_jsx(IconCmp, { size: "md", className: "shrink-0 text-fds-red-30", "aria-hidden": true, "data-test-id": `${dataTestId}-forbidden-icon` }), _jsxs("div", { className: "flex min-w-0 flex-col gap-fds-xs text-start", "aria-live": "polite", children: [_jsx("span", { className: "w-[130px] text-fds-sm font-fds-regular leading-fds-body text-fds-red-30", "data-test-id": `${dataTestId}-forbidden-title`, children: t(fbCopy?.title ?? '') }), _jsx("span", { className: "w-[132px] text-fds-xs font-fds-bold leading-fds-body text-fds-red-30", "data-test-id": `${dataTestId}-forbidden-subtitle`, children: t(fbCopy?.subtitle ?? '') })] })] }));
|
|
243
|
+
}
|
|
244
|
+
return (_jsxs(_Fragment, { children: [_jsx(IconCmp, { size: "lg", className: "text-fds-red-30", "aria-hidden": true, "data-test-id": `${dataTestId}-forbidden-icon` }), _jsx("span", { className: "text-fds-base font-fds-regular leading-fds-body text-fds-red-30", "data-test-id": `${dataTestId}-forbidden-compact`, children: t(mergedLabels.idleCompact) })] }));
|
|
245
|
+
};
|
|
246
|
+
const renderUploading = () => {
|
|
247
|
+
const SpinnerIcon = iconMap[DEFAULT_ICONS.uploading];
|
|
248
|
+
if (uploadingStyle === 'spinner') {
|
|
249
|
+
return (_jsx(SpinnerIcon, { size: "lg", role: "status", "aria-label": t(mergedLabels.uploading), className: "animate-spin text-fds-blue-30 rtl:direction-[reverse]", "data-test-id": `${dataTestId}-uploading-indicator` }));
|
|
250
|
+
}
|
|
251
|
+
return (_jsxs("div", { className: "flex w-full flex-col gap-fds-sm", "data-test-id": `${dataTestId}-uploading-indicator`, children: [_jsx("span", { className: cn('font-fds-regular leading-fds-body text-fds-gray-80 dark:text-fds-gray-20', isSquare ? 'w-full text-fds-base' : 'w-[67px] text-fds-sm'), children: t(mergedLabels.uploading) }), _jsx("div", { className: cn('relative h-0.5 overflow-hidden rounded-[6px] bg-fds-gray-20 dark:bg-fds-gray-70', isSquare ? 'w-full' : 'w-[165px]'), role: "progressbar", "aria-valuenow": uploadProgress !== null ? Math.round(uploadProgress * 100) : undefined, "aria-valuemin": uploadProgress !== null ? 0 : undefined, "aria-valuemax": uploadProgress !== null ? 100 : undefined, "aria-label": t(mergedLabels.uploading), children: _jsx("div", { className: cn('absolute inset-y-0 start-0 rounded-[6px] bg-fds-green-30 upload-progress-bar', uploadProgress === null
|
|
252
|
+
? 'w-1/2 animate-[uploading-progress_1.4s_ease-in-out_infinite]'
|
|
253
|
+
: 'transition-[width] duration-200 ease-in-out'), style: uploadProgress !== null ? { width: `${uploadProgress * 100}%` } : undefined }) })] }));
|
|
254
|
+
};
|
|
255
|
+
const renderFilled = (tone) => {
|
|
256
|
+
const tokenColor = tone === 'success'
|
|
257
|
+
? 'text-fds-blue-30'
|
|
258
|
+
: tone === 'error'
|
|
259
|
+
? 'text-fds-red-30'
|
|
260
|
+
: 'text-fds-gray-30 dark:text-fds-gray-50';
|
|
261
|
+
const accent = tone === 'success'
|
|
262
|
+
? 'text-fds-green-30'
|
|
263
|
+
: tone === 'error'
|
|
264
|
+
? 'text-fds-red-30'
|
|
265
|
+
: 'text-fds-gray-30 dark:text-fds-gray-50';
|
|
266
|
+
const StatusIcon = iconMap[tone === 'error' ? DEFAULT_ICONS.error : DEFAULT_ICONS.success];
|
|
267
|
+
const RemoveIcon = iconMap[DEFAULT_ICONS.remove];
|
|
268
|
+
const { display, tooltip } = buildFileLabel(allFiles, isSquare);
|
|
269
|
+
const statusIconNode = tone === 'success' ? (isSquare
|
|
270
|
+
? _jsx(StatusIcon, { size: "lg", className: cn('shrink-0', accent), "aria-hidden": true, "data-test-id": `${dataTestId}-status-icon` })
|
|
271
|
+
: _jsx(StatusIcon, { className: cn('shrink-0 w-[13.33px] h-[13.33px]', accent), "aria-hidden": true, "data-test-id": `${dataTestId}-status-icon` })) : tone === 'error' ? (isSquare
|
|
272
|
+
? _jsx(StatusIcon, { size: "lg", className: cn('shrink-0', accent), "aria-hidden": true, "data-test-id": `${dataTestId}-status-icon` })
|
|
273
|
+
: _jsx(StatusIcon, { size: "sm", className: cn('shrink-0', accent), "aria-hidden": true, "data-test-id": `${dataTestId}-status-icon` })) : tone === 'disabled' ? (isSquare
|
|
274
|
+
? _jsx(StatusIcon, { size: "lg", className: cn('shrink-0', accent), "aria-hidden": true, "data-test-id": `${dataTestId}-status-icon` })
|
|
275
|
+
: _jsx(StatusIcon, { size: "sm", className: cn('shrink-0', accent), "aria-hidden": true, "data-test-id": `${dataTestId}-status-icon` })) : (_jsx(StatusIcon, { size: isSquare ? 'md' : 'xs', className: cn('shrink-0', accent), "aria-hidden": true, "data-test-id": `${dataTestId}-status-icon` }));
|
|
276
|
+
return (_jsxs(_Fragment, { children: [statusIconNode, _jsx("span", { className: cn('truncate font-fds-regular leading-fds-body', isSquare && (tone === 'error' || tone === 'disabled') ? 'text-fds-base' : 'text-fds-sm', !isSquare && !isFillContainer && 'min-w-0 flex-1', !isSquare && isFillContainer && 'min-w-0', tokenColor, isSquare && 'w-full text-center'), title: tooltip, "data-test-id": `${dataTestId}-filename`, children: display }), !isSquare && hasFiles && tone !== 'disabled' && (_jsx("button", { type: "button", onClick: handleRemoveClick, "aria-label": t('Remove all files'), "data-test-id": `${dataTestId}-remove`, className: cn('inline-flex size-6 shrink-0 items-center justify-center rounded-fds-sm focus-visible:outline-none focus-visible:ring-2 cursor-pointer text-fds-red-30 hover:bg-fds-red-05 focus-visible:ring-fds-red-30 dark:hover:bg-fds-red-30/10', !isFillContainer && 'ms-auto'), children: _jsx(RemoveIcon, { size: "sm", "aria-hidden": true }) }))] }));
|
|
277
|
+
};
|
|
278
|
+
let body = null;
|
|
279
|
+
switch (effectiveState) {
|
|
280
|
+
case 'default':
|
|
281
|
+
body = renderIdle();
|
|
282
|
+
break;
|
|
283
|
+
case 'disabled':
|
|
284
|
+
body = hasFiles ? renderFilled('disabled') : renderIdle();
|
|
285
|
+
break;
|
|
286
|
+
case 'forbidden':
|
|
287
|
+
body = renderForbidden();
|
|
288
|
+
break;
|
|
289
|
+
case 'uploading':
|
|
290
|
+
case 'uploading-spinner':
|
|
291
|
+
body = renderUploading();
|
|
292
|
+
break;
|
|
293
|
+
case 'success':
|
|
294
|
+
body = renderFilled('success');
|
|
295
|
+
break;
|
|
296
|
+
case 'error':
|
|
297
|
+
body = (_jsx("div", { role: "alert", className: "contents", children: renderFilled('error') }));
|
|
298
|
+
break;
|
|
299
|
+
}
|
|
300
|
+
const isFilled = effectiveState === 'uploading' ||
|
|
301
|
+
effectiveState === 'uploading-spinner' ||
|
|
302
|
+
effectiveState === 'success' ||
|
|
303
|
+
effectiveState === 'error' ||
|
|
304
|
+
(effectiveState === 'disabled' && hasFiles);
|
|
305
|
+
const frameSize = isSquare
|
|
306
|
+
? ''
|
|
307
|
+
: isFillContainer
|
|
308
|
+
? isFilled ? 'h-full w-full justify-center' : 'h-full w-full'
|
|
309
|
+
: effectiveState === 'forbidden'
|
|
310
|
+
? 'h-[69px] w-[193px]'
|
|
311
|
+
: isFilled
|
|
312
|
+
? 'h-[60px] w-[198px]'
|
|
313
|
+
: 'h-[69px] w-[196px]';
|
|
314
|
+
return (_jsxs("label", { ref: ref, htmlFor: inputId, "data-test-id": dataTestId, "data-state": effectiveState, "data-variant": variant, "data-filled": hasFiles ? 'true' : 'false', dir: dir, "aria-label": ariaLabel ?? t(mergedLabels.idleTitle), "aria-disabled": isDisabled || undefined, "aria-busy": (effectiveState === 'uploading' || effectiveState === 'uploading-spinner') || undefined, className: cn(uploadVariants({ variant, state: effectiveState }), effectiveState === 'default' && (isSquare ? 'upload-dash-4-2-square' : isFillContainer ? 'upload-dash-fluid' : 'upload-dash-4-2'), effectiveState === 'forbidden' && (isSquare
|
|
315
|
+
? 'h-[100px] gap-[4px] upload-dash-4-4'
|
|
316
|
+
: isFillContainer ? 'upload-dash-fluid-red' : 'upload-dash-4-2-red'), (effectiveState === 'uploading' || effectiveState === 'uploading-spinner') && isSquare && 'h-[100px] p-[11px]!', effectiveState === 'success' && isSquare && 'h-[100px] gap-[4px]', effectiveState === 'error' && isSquare && 'h-[100px] gap-[4px] p-[11px]!', effectiveState === 'disabled' && isSquare && hasFiles && 'h-[100px] gap-[4px] p-[11px]!', effectiveState === 'uploading-spinner' && !isSquare && 'py-3.5!', frameSize, className), onDragEnter: handleDragEnter, onDragOver: (e) => e.preventDefault(), onDragLeave: handleDragLeave, onDrop: handleDrop, ...rest, children: [_jsx("input", { id: inputId, type: "file", accept: acceptAttr, multiple: isMultiple, disabled: isDisabled, className: "sr-only", onChange: handleNativeChange, "data-test-id": `${dataTestId}-input` }), body] }));
|
|
317
|
+
});
|
|
318
|
+
export { uploadVariants };
|