pge-front-common 14.0.56 → 14.1.0
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/lib/components/Upload/index.d.ts +3 -0
- package/lib/components/Upload/index.type.d.ts +3 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.esm.js +55 -15
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +55 -15
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -8,6 +8,9 @@ export declare const FileUpload: React.ForwardRefExoticComponent<{
|
|
|
8
8
|
title?: React.ReactNode;
|
|
9
9
|
descricaoLabel?: string;
|
|
10
10
|
errorText?: string;
|
|
11
|
+
noSelectedFileText?: string;
|
|
12
|
+
maxFileSize?: `${number}KB` | `${number}MB` | `${number}GB`;
|
|
13
|
+
helperText?: React.ReactNode;
|
|
11
14
|
} & {
|
|
12
15
|
disabled?: boolean | undefined;
|
|
13
16
|
form?: string | undefined;
|
|
@@ -9,6 +9,9 @@ export type UploadFileProps = {
|
|
|
9
9
|
title?: ReactNode;
|
|
10
10
|
descricaoLabel?: string;
|
|
11
11
|
errorText?: string;
|
|
12
|
+
noSelectedFileText?: string;
|
|
13
|
+
maxFileSize?: `${number}KB` | `${number}MB` | `${number}GB`;
|
|
14
|
+
helperText?: ReactNode;
|
|
12
15
|
} & ButtonAttrs;
|
|
13
16
|
export type FileUploadHandle = {
|
|
14
17
|
reset: () => void;
|
package/lib/index.d.ts
CHANGED
|
@@ -85,6 +85,9 @@ declare const FileUpload: React__default.ForwardRefExoticComponent<{
|
|
|
85
85
|
title?: React__default.ReactNode;
|
|
86
86
|
descricaoLabel?: string;
|
|
87
87
|
errorText?: string;
|
|
88
|
+
noSelectedFileText?: string;
|
|
89
|
+
maxFileSize?: `${number}KB` | `${number}MB` | `${number}GB`;
|
|
90
|
+
helperText?: React__default.ReactNode;
|
|
88
91
|
} & {
|
|
89
92
|
disabled?: boolean | undefined;
|
|
90
93
|
form?: string | undefined;
|
package/lib/index.esm.js
CHANGED
|
@@ -607,18 +607,51 @@ var css_248z$w = ".styles-module__container___9pLua {\r\n width: 100%;\r\n hei
|
|
|
607
607
|
var styles$t = {"container":"styles-module__container___9pLua","label":"styles-module__label___AWyTG","labelUpload":"styles-module__labelUpload___LOAO-","inputContainer":"styles-module__inputContainer___tsCfV","button":"styles-module__button___1GicM","hiddenInput":"styles-module__hiddenInput___lDoAG","description":"styles-module__description___S1vZj","instructionText":"styles-module__instructionText___fa9r4","primary":"styles-module__primary___AtNI-","secondary":"styles-module__secondary___-anJq","danger":"styles-module__danger___RwQhk","errorText":"styles-module__errorText___1LAhk","successText":"styles-module__successText___s1G4K"};
|
|
608
608
|
styleInject(css_248z$w);
|
|
609
609
|
|
|
610
|
+
var parseSizeToBytes = function (size) {
|
|
611
|
+
if (!size)
|
|
612
|
+
return 0;
|
|
613
|
+
var match = size.match(/(\d+(?:\.\d+)?)\s*(KB|MB|GB)/i);
|
|
614
|
+
if (!match)
|
|
615
|
+
return 0;
|
|
616
|
+
var value = parseFloat(match[1]);
|
|
617
|
+
var unit = match[2].toUpperCase();
|
|
618
|
+
switch (unit) {
|
|
619
|
+
case "KB":
|
|
620
|
+
return value * 1024;
|
|
621
|
+
case "MB":
|
|
622
|
+
return value * 1024 * 1024;
|
|
623
|
+
case "GB":
|
|
624
|
+
return value * 1024 * 1024 * 1024;
|
|
625
|
+
default:
|
|
626
|
+
return 0;
|
|
627
|
+
}
|
|
628
|
+
};
|
|
610
629
|
var FileUpload = forwardRef(function (_a, ref) {
|
|
611
630
|
var _b;
|
|
612
|
-
var _c = _a.variant, variant = _c === void 0 ? "primary" : _c, _d = _a.danger, danger = _d === void 0 ? false : _d, fileTypes = _a.fileTypes, onFileSelect = _a.onFileSelect, _e = _a.title, title = _e === void 0 ? React__default.createElement(React__default.Fragment, null, "Upload de Arquivos:") : _e, _f = _a.descricaoLabel, descricaoLabel = _f === void 0 ? "Escolher arquivo" : _f, className = _a.className, _g = _a.errorText, errorText = _g === void 0 ? "" : _g; __rest(_a, ["variant", "danger", "fileTypes", "onFileSelect", "title", "descricaoLabel", "className", "errorText"]);
|
|
631
|
+
var _c = _a.variant, variant = _c === void 0 ? "primary" : _c, _d = _a.danger, danger = _d === void 0 ? false : _d, fileTypes = _a.fileTypes, onFileSelect = _a.onFileSelect, _e = _a.title, title = _e === void 0 ? React__default.createElement(React__default.Fragment, null, "Upload de Arquivos:") : _e, _f = _a.descricaoLabel, descricaoLabel = _f === void 0 ? "Escolher arquivo" : _f, className = _a.className, _g = _a.errorText, errorText = _g === void 0 ? "" : _g, _h = _a.noSelectedFileText, noSelectedFileText = _h === void 0 ? "Nenhum arquivo selecionado" : _h, _j = _a.helperText, helperText = _j === void 0 ? "" : _j, _k = _a.maxFileSize, maxFileSize = _k === void 0 ? "" : _k; __rest(_a, ["variant", "danger", "fileTypes", "onFileSelect", "title", "descricaoLabel", "className", "errorText", "noSelectedFileText", "helperText", "maxFileSize"]);
|
|
613
632
|
var buttonClass = clsx(styles$t.labelUpload, styles$t.button, styles$t[variant], (_b = {},
|
|
614
633
|
_b[styles$t.danger] = danger && variant !== "primary",
|
|
615
634
|
_b), className);
|
|
616
|
-
var
|
|
635
|
+
var inputId = useId$1();
|
|
636
|
+
var helperId = useId$1();
|
|
637
|
+
var errorId = useId$1();
|
|
638
|
+
var _l = React__default.useState(""), fileName = _l[0], setFileName = _l[1];
|
|
617
639
|
var fileInputRef = useRef(null);
|
|
618
640
|
var handleFileChange = function (event) {
|
|
619
641
|
var _a, _b;
|
|
620
642
|
var selectedFile = ((_a = event.target.files) === null || _a === void 0 ? void 0 : _a[0]) || null;
|
|
621
643
|
if (selectedFile) {
|
|
644
|
+
if (maxFileSize) {
|
|
645
|
+
var maxBytes = parseSizeToBytes(maxFileSize);
|
|
646
|
+
if (selectedFile.size > maxBytes) {
|
|
647
|
+
setFileName("");
|
|
648
|
+
onFileSelect(selectedFile);
|
|
649
|
+
if (fileInputRef.current) {
|
|
650
|
+
fileInputRef.current.value = "";
|
|
651
|
+
}
|
|
652
|
+
return;
|
|
653
|
+
}
|
|
654
|
+
}
|
|
622
655
|
var fileExtension = (_b = selectedFile.name.split(".").pop()) === null || _b === void 0 ? void 0 : _b.toLowerCase();
|
|
623
656
|
if (fileExtension && fileTypes.includes(".".concat(fileExtension))) {
|
|
624
657
|
setFileName(selectedFile.name);
|
|
@@ -626,7 +659,7 @@ var FileUpload = forwardRef(function (_a, ref) {
|
|
|
626
659
|
}
|
|
627
660
|
else {
|
|
628
661
|
setFileName("");
|
|
629
|
-
onFileSelect(
|
|
662
|
+
onFileSelect(selectedFile);
|
|
630
663
|
if (fileInputRef.current) {
|
|
631
664
|
fileInputRef.current.value = "";
|
|
632
665
|
}
|
|
@@ -642,20 +675,25 @@ var FileUpload = forwardRef(function (_a, ref) {
|
|
|
642
675
|
}
|
|
643
676
|
},
|
|
644
677
|
}); });
|
|
645
|
-
return (
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
678
|
+
var openFileDialog = function () { var _a; return (_a = fileInputRef.current) === null || _a === void 0 ? void 0 : _a.click(); };
|
|
679
|
+
return (React__default.createElement("div", { role: "group", "aria-labelledby": "".concat(inputId, "-label"), "aria-describedby": "".concat(helperId, " ").concat(errorText ? errorId : ""), className: styles$t.container },
|
|
680
|
+
React__default.createElement("span", { id: "".concat(inputId, "-label"), className: styles$t.label }, title),
|
|
681
|
+
React__default.createElement("div", { className: styles$t.inputContainer },
|
|
682
|
+
React__default.createElement("button", { type: "button", className: buttonClass, onClick: openFileDialog, onKeyDown: function (e) {
|
|
683
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
684
|
+
e.preventDefault();
|
|
685
|
+
openFileDialog();
|
|
686
|
+
}
|
|
687
|
+
}, "aria-label": "".concat(typeof title === "string" ? title : descricaoLabel, ". Tipos permitidos: ").concat(fileTypes.join(", "), ". Tamanho m\u00E1ximo: ").concat(maxFileSize, ".") },
|
|
688
|
+
React__default.createElement(IconUploadFile, { "aria-hidden": "true" }),
|
|
689
|
+
descricaoLabel),
|
|
690
|
+
React__default.createElement("input", { id: inputId, type: "file", ref: fileInputRef, className: styles$t.hiddenInput, onChange: handleFileChange, accept: fileTypes.join(","), "aria-describedby": "".concat(helperId, " ").concat(errorText ? errorId : ""), "aria-invalid": !!errorText }),
|
|
691
|
+
React__default.createElement("span", { className: styles$t.description }, fileName || noSelectedFileText)),
|
|
692
|
+
React__default.createElement("span", { id: errorText ? errorId : helperId, role: "alert", "aria-live": "polite", className: errorText
|
|
655
693
|
? styles$t.errorText
|
|
656
694
|
: fileName
|
|
657
695
|
? styles$t.successText
|
|
658
|
-
: styles$t.instructionText
|
|
696
|
+
: styles$t.instructionText }, errorText || helperText)));
|
|
659
697
|
});
|
|
660
698
|
|
|
661
699
|
var css_248z$v = ".styles-module__container___YGeVk {\r\n position: relative;\r\n display: flex;\r\n}\r\n\r\n.styles-module__tooltip___mnnfp {\r\n position: absolute;\r\n width: max-content;\r\n height: fit-content;\r\n max-width: 480px;\r\n border-radius: 8px;\r\n word-wrap: break-word;\r\n background: var(--background-color);\r\n padding: 10px;\r\n border: 1px solid #c3c3c3;\r\n z-index: 1000;\r\n}\r\n\r\n.styles-module__textContent___F6Omr {\r\n font-weight: 400;\r\n font-size: var(--font-size-14, 14px);\r\n line-height: 21px;\r\n color: var(--foreground);\r\n}\r\n\r\n.styles-module__top-right___KAK6B {\r\n bottom: 100%;\r\n left: 100%;\r\n margin-bottom: 8px;\r\n}\r\n\r\n.styles-module__bottom-right___2qH8T {\r\n top: 100%;\r\n left: 100%;\r\n margin-top: 8px;\r\n}\r\n\r\n.styles-module__bottom-left___9jLIE {\r\n top: 100%;\r\n right: 100%;\r\n margin-top: 8px;\r\n}\r\n\r\n.styles-module__top-left___wu3BB {\r\n bottom: 100%;\r\n right: 100%;\r\n margin-bottom: 8px;\r\n}\r\n\r\n.styles-module__mobile___jimue {\r\n bottom: 100%;\r\n left: 100%;\r\n margin-bottom: 8px;\r\n}\r\n\r\n@media screen and (max-width: 480px) {\r\n .styles-module__container___YGeVk {\r\n position: static;\r\n }\r\n\r\n .styles-module__tooltip___mnnfp {\r\n width: max-content;\r\n max-width: 92vw;\r\n left: 0;\r\n bottom: 90%;\r\n text-align: start;\r\n padding: 10px;\r\n position: absolute;\r\n flex-wrap: wrap;\r\n border-radius: 8px;\r\n }\r\n\r\n .styles-module__textContent___F6Omr {\r\n font-size: var(--font-size-12, 12px);\r\n }\r\n}\r\n";
|
|
@@ -21523,7 +21561,9 @@ var selectColourStyles = function (isInvalid, isMobile) { return ({
|
|
|
21523
21561
|
? "0px 0px 0px 2px #DC354580"
|
|
21524
21562
|
: isFocused
|
|
21525
21563
|
? "0px 0px 0px 2px #0091ea80"
|
|
21526
|
-
: "0px hsl(0, 0%, 96%)", backgroundColor: isDisabled ? "var(--input-disabled-bg-color)" : "white"
|
|
21564
|
+
: "0px hsl(0, 0%, 96%)", backgroundColor: isDisabled ? "var(--input-disabled-bg-color)" : "white", ":hover": {
|
|
21565
|
+
backgroundColor: isDisabled ? "var(--input-disabled-bg-color)" : "#005a9214",
|
|
21566
|
+
} }));
|
|
21527
21567
|
},
|
|
21528
21568
|
option: function (styles, _a) {
|
|
21529
21569
|
var isDisabled = _a.isDisabled, isSelected = _a.isSelected, isFocused = _a.isFocused;
|