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