allaw-ui 3.0.9 → 3.1.1
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,39 @@ 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
|
+
var url = URL.createObjectURL(initialFile);
|
|
58
|
+
setPreviewUrl(url);
|
|
59
|
+
initialFile.arrayBuffer().then(function (content) {
|
|
60
|
+
setFileContent(content);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
if (initialPreviewUrl) {
|
|
64
|
+
setPreviewUrl(initialPreviewUrl);
|
|
65
|
+
}
|
|
66
|
+
if (initialCropMetadata) {
|
|
67
|
+
setCropMetadata(initialCropMetadata);
|
|
68
|
+
}
|
|
69
|
+
}, [initialFile, initialPreviewUrl, initialCropMetadata]);
|
|
54
70
|
useEffect(function () {
|
|
55
71
|
return function () {
|
|
56
|
-
|
|
72
|
+
if (previewUrl) {
|
|
73
|
+
URL.revokeObjectURL(previewUrl);
|
|
74
|
+
}
|
|
57
75
|
};
|
|
58
|
-
}, []);
|
|
76
|
+
}, [previewUrl]);
|
|
59
77
|
var startProgressSimulation = function () {
|
|
60
78
|
stopProgressSimulation();
|
|
61
79
|
setInternalProgress(1);
|
|
@@ -252,7 +270,7 @@ var FileUploader = function (_a) {
|
|
|
252
270
|
? "translate(".concat(cropMetadata.offsetX, "px, ").concat(cropMetadata.offsetY, "px) scale(").concat(cropMetadata.zoom, ")")
|
|
253
271
|
: "scale(1)",
|
|
254
272
|
} },
|
|
255
|
-
React.createElement(
|
|
273
|
+
React.createElement("img", { src: previewUrl, alt: displayFileName, className: styles.preview_image, draggable: false }))),
|
|
256
274
|
enableCropping && (React.createElement("div", { className: styles.edit_button_container, onClick: function (e) {
|
|
257
275
|
e.stopPropagation();
|
|
258
276
|
openCropModal();
|