allaw-ui 3.1.0 → 3.1.2
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.
|
@@ -27,6 +27,14 @@ export interface FileUploaderProps {
|
|
|
27
27
|
fileName?: string;
|
|
28
28
|
fileSize?: number;
|
|
29
29
|
filePresentationLabel?: string;
|
|
30
|
+
initialFile?: File;
|
|
31
|
+
initialPreviewUrl?: string;
|
|
32
|
+
initialCropMetadata?: {
|
|
33
|
+
zoom: number;
|
|
34
|
+
offsetX: number;
|
|
35
|
+
offsetY: number;
|
|
36
|
+
shape: "circle" | "square" | "banner";
|
|
37
|
+
};
|
|
30
38
|
}
|
|
31
39
|
declare const FileUploader: React.FC<FileUploaderProps>;
|
|
32
40
|
export default FileUploader;
|
|
@@ -41,21 +41,37 @@ import ImageCropperModal from "./ImageCropperModal";
|
|
|
41
41
|
import IconButton from "../../atoms/buttons/IconButton";
|
|
42
42
|
import TertiaryButton from "../../atoms/buttons/TertiaryButton";
|
|
43
43
|
var FileUploader = function (_a) {
|
|
44
|
-
var acceptedExtensions = _a.acceptedExtensions, maxFileSizeMB = _a.maxFileSizeMB, _b = _a.enableDragAndDrop, enableDragAndDrop = _b === void 0 ? true : _b, _c = _a.enableCropping, enableCropping = _c === void 0 ? false : _c, _d = _a.cropShape, cropShape = _d === void 0 ? "square" : _d, iconUrl = _a.iconUrl, descriptionParts = _a.descriptionParts, onFileRead = _a.onFileRead, onFileRemove = _a.onFileRemove, _e = _a.uploadProgress, uploadProgress = _e === void 0 ? 0 : _e, _f = _a.isLoading, isLoading = _f === void 0 ? false : _f, _g = _a.autoManageProgress, autoManageProgress = _g === void 0 ? false : _g, _h = _a.progressSteps, progressSteps = _h === void 0 ? 10 : _h, _j = _a.progressInterval, progressInterval = _j === void 0 ? 500 : _j, _k = _a.errorMessage, errorMessage = _k === void 0 ? null : _k, _l = _a.buttonLabel, buttonLabel = _l === void 0 ? "Choisir un fichier" : _l, _m = _a.acceptedLabel, acceptedLabel = _m === void 0 ? "Format accepté :" : _m, _o = _a.maxSizeLabel, maxSizeLabel = _o === void 0 ? "Taille maximale :" : _o, fileName = _a.fileName, fileSize = _a.fileSize, _p = _a.filePresentationLabel, filePresentationLabel = _p === void 0 ? "Voici votre fichier." : _p;
|
|
45
|
-
var _q = useState(null), selectedFile = _q[0], setSelectedFile = _q[1];
|
|
44
|
+
var acceptedExtensions = _a.acceptedExtensions, maxFileSizeMB = _a.maxFileSizeMB, _b = _a.enableDragAndDrop, enableDragAndDrop = _b === void 0 ? true : _b, _c = _a.enableCropping, enableCropping = _c === void 0 ? false : _c, _d = _a.cropShape, cropShape = _d === void 0 ? "square" : _d, iconUrl = _a.iconUrl, descriptionParts = _a.descriptionParts, onFileRead = _a.onFileRead, onFileRemove = _a.onFileRemove, _e = _a.uploadProgress, uploadProgress = _e === void 0 ? 0 : _e, _f = _a.isLoading, isLoading = _f === void 0 ? false : _f, _g = _a.autoManageProgress, autoManageProgress = _g === void 0 ? false : _g, _h = _a.progressSteps, progressSteps = _h === void 0 ? 10 : _h, _j = _a.progressInterval, progressInterval = _j === void 0 ? 500 : _j, _k = _a.errorMessage, errorMessage = _k === void 0 ? null : _k, _l = _a.buttonLabel, buttonLabel = _l === void 0 ? "Choisir un fichier" : _l, _m = _a.acceptedLabel, acceptedLabel = _m === void 0 ? "Format accepté :" : _m, _o = _a.maxSizeLabel, maxSizeLabel = _o === void 0 ? "Taille maximale :" : _o, fileName = _a.fileName, fileSize = _a.fileSize, _p = _a.filePresentationLabel, filePresentationLabel = _p === void 0 ? "Voici votre fichier." : _p, initialFile = _a.initialFile, initialPreviewUrl = _a.initialPreviewUrl, initialCropMetadata = _a.initialCropMetadata;
|
|
45
|
+
var _q = useState(initialFile || null), selectedFile = _q[0], setSelectedFile = _q[1];
|
|
46
46
|
var _r = useState(null), fileContent = _r[0], setFileContent = _r[1];
|
|
47
47
|
var _s = useState(false), isHovering = _s[0], setIsHovering = _s[1];
|
|
48
48
|
var _t = useState(false), showCropper = _t[0], setShowCropper = _t[1];
|
|
49
|
-
var _u = useState(null), previewUrl = _u[0], setPreviewUrl = _u[1];
|
|
50
|
-
var _v = useState(null), cropMetadata = _v[0], setCropMetadata = _v[1];
|
|
49
|
+
var _u = useState(initialPreviewUrl || null), previewUrl = _u[0], setPreviewUrl = _u[1];
|
|
50
|
+
var _v = useState(initialCropMetadata || null), cropMetadata = _v[0], setCropMetadata = _v[1];
|
|
51
51
|
var _w = useState(0), internalProgress = _w[0], setInternalProgress = _w[1];
|
|
52
52
|
var progressIntervalRef = useRef(null);
|
|
53
53
|
var fileInputRef = useRef(null);
|
|
54
|
+
useEffect(function () {
|
|
55
|
+
if (initialFile) {
|
|
56
|
+
setSelectedFile(initialFile);
|
|
57
|
+
initialFile.arrayBuffer().then(function (content) {
|
|
58
|
+
setFileContent(content);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
if (initialPreviewUrl) {
|
|
62
|
+
setPreviewUrl(initialPreviewUrl);
|
|
63
|
+
}
|
|
64
|
+
if (initialCropMetadata) {
|
|
65
|
+
setCropMetadata(initialCropMetadata);
|
|
66
|
+
}
|
|
67
|
+
}, [initialFile, initialPreviewUrl, initialCropMetadata]);
|
|
54
68
|
useEffect(function () {
|
|
55
69
|
return function () {
|
|
56
|
-
|
|
70
|
+
if (previewUrl && !initialPreviewUrl) {
|
|
71
|
+
URL.revokeObjectURL(previewUrl);
|
|
72
|
+
}
|
|
57
73
|
};
|
|
58
|
-
}, []);
|
|
74
|
+
}, [previewUrl, initialPreviewUrl]);
|
|
59
75
|
var startProgressSimulation = function () {
|
|
60
76
|
stopProgressSimulation();
|
|
61
77
|
setInternalProgress(1);
|
|
@@ -301,10 +317,16 @@ var FileUploader = function (_a) {
|
|
|
301
317
|
React.createElement("div", { className: styles.uploaded_file_icon }, iconUrl ? (React.createElement(Image, { src: iconUrl, alt: "File icon", className: styles.file_icon, width: 20, height: 20 })) : (React.createElement("i", { className: "allaw-icon-file" }))),
|
|
302
318
|
React.createElement("div", { className: styles.uploaded_file_name_size },
|
|
303
319
|
React.createElement("div", { className: styles.uploaded_file_name },
|
|
304
|
-
React.createElement("span", { className: styles.file_name }, displayFileName ||
|
|
320
|
+
React.createElement("span", { className: styles.file_name }, displayFileName ||
|
|
321
|
+
(selectedFile === null || selectedFile === void 0 ? void 0 : selectedFile.name) ||
|
|
322
|
+
"Analyse en cours..."),
|
|
305
323
|
selectedFile && (React.createElement("i", { className: "allaw-icon-check ".concat(styles.success_icon) }))),
|
|
306
324
|
React.createElement("div", { className: styles.uploaded_file_size },
|
|
307
|
-
React.createElement("span", { className: styles.file_size }, displayFileSize > 0
|
|
325
|
+
React.createElement("span", { className: styles.file_size }, displayFileSize > 0
|
|
326
|
+
? formatFileSize(displayFileSize)
|
|
327
|
+
: (selectedFile === null || selectedFile === void 0 ? void 0 : selectedFile.size)
|
|
328
|
+
? formatFileSize(selectedFile.size)
|
|
329
|
+
: ""))),
|
|
308
330
|
selectedFile && (React.createElement("div", { className: styles.uploaded_file_delete_container },
|
|
309
331
|
React.createElement("div", { className: styles.uploaded_file_delete, onClick: handleFileDelete },
|
|
310
332
|
React.createElement("i", { className: "allaw-icon-close" }))))),
|