@arkyn/components 1.4.7 → 1.4.8
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/bundle.js +1463 -1451
- package/dist/bundle.umd.cjs +22 -22
- package/dist/components/ImageUpload/HasFileContent/index.d.ts.map +1 -1
- package/dist/components/ImageUpload/HasFileContent/index.js +4 -2
- package/dist/components/ImageUpload/NoFileContent/index.d.ts.map +1 -1
- package/dist/components/ImageUpload/NoFileContent/index.js +6 -2
- package/dist/components/ImageUpload/index.d.ts.map +1 -1
- package/dist/components/ImageUpload/index.js +6 -2
- package/package.json +1 -1
- package/src/components/ImageUpload/HasFileContent/index.tsx +5 -0
- package/src/components/ImageUpload/NoFileContent/index.tsx +6 -0
- package/src/components/ImageUpload/index.tsx +7 -0
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/ImageUpload/HasFileContent/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAOnD,OAAO,cAAc,CAAC;AAEtB,iBAAS,cAAc,CAAC,KAAK,EAAE,mBAAmB,
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/ImageUpload/HasFileContent/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAOnD,OAAO,cAAc,CAAC;AAEtB,iBAAS,cAAc,CAAC,KAAK,EAAE,mBAAmB,2CA4DjD;AAED,OAAO,EAAE,cAAc,EAAE,CAAC"}
|
@@ -5,8 +5,10 @@ import { IconButton } from "../../IconButton";
|
|
5
5
|
import { Tooltip } from "../../Tooltip";
|
6
6
|
import "./styles.css";
|
7
7
|
function HasFileContent(props) {
|
8
|
-
const { filePath, isLoading, acceptImage, changeImageButtonText, handleSelectFile, reSendImage, } = props;
|
8
|
+
const { disabled, filePath, isLoading, acceptImage, changeImageButtonText, handleSelectFile, reSendImage, } = props;
|
9
9
|
function handleClick() {
|
10
|
+
if (disabled)
|
11
|
+
return;
|
10
12
|
const input = document.createElement("input");
|
11
13
|
input.type = "file";
|
12
14
|
input.accept = acceptImage;
|
@@ -17,6 +19,6 @@ function HasFileContent(props) {
|
|
17
19
|
};
|
18
20
|
input.click();
|
19
21
|
}
|
20
|
-
return (_jsxs("div", { className: "arkynImageUploadHasFileContent", style: { backgroundImage: `url("${filePath}")` }, children: [reSendImage && (_jsx(Tooltip, { orientation: "bottom", text: "Reenviar imagem", children: _jsx(IconButton, { type: "button", "aria-label": "resend image", variant: "outline", scheme: "danger", size: "sm", isLoading: isLoading, onClick: reSendImage, icon: RefreshCw }) })), _jsx(Button, { isLoading: isLoading, onClick: handleClick, variant: "outline", size: "sm", type: "button", children: changeImageButtonText })] }));
|
22
|
+
return (_jsxs("div", { className: "arkynImageUploadHasFileContent", style: { backgroundImage: `url("${filePath}")` }, children: [reSendImage && (_jsx(Tooltip, { orientation: "bottom", text: "Reenviar imagem", children: _jsx(IconButton, { type: "button", "aria-label": "resend image", variant: "outline", scheme: "danger", size: "sm", isLoading: isLoading, onClick: reSendImage, icon: RefreshCw, disabled: disabled }) })), _jsx(Button, { isLoading: isLoading, onClick: handleClick, variant: "outline", size: "sm", type: "button", disabled: disabled, children: changeImageButtonText })] }));
|
21
23
|
}
|
22
24
|
export { HasFileContent };
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/ImageUpload/NoFileContent/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAKlD,OAAO,cAAc,CAAC;AAEtB,iBAAS,aAAa,CAAC,KAAK,EAAE,kBAAkB,
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/ImageUpload/NoFileContent/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAKlD,OAAO,cAAc,CAAC;AAEtB,iBAAS,aAAa,CAAC,KAAK,EAAE,kBAAkB,2CAkD/C;AAED,OAAO,EAAE,aAAa,EAAE,CAAC"}
|
@@ -2,14 +2,18 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Button } from "../../Button";
|
3
3
|
import "./styles.css";
|
4
4
|
function NoFileContent(props) {
|
5
|
-
const { dropImageText, isLoading, acceptImage, handleSelectFile, selectImageButtonText, } = props;
|
5
|
+
const { dropImageText, isLoading, acceptImage, handleSelectFile, selectImageButtonText, disabled, } = props;
|
6
6
|
function handleDrop(event) {
|
7
|
+
if (disabled)
|
8
|
+
return;
|
7
9
|
event.preventDefault();
|
8
10
|
const file = event.dataTransfer.files[0];
|
9
11
|
if (file)
|
10
12
|
handleSelectFile(file);
|
11
13
|
}
|
12
14
|
function handleClick() {
|
15
|
+
if (disabled)
|
16
|
+
return;
|
13
17
|
const input = document.createElement("input");
|
14
18
|
input.type = "file";
|
15
19
|
input.accept = acceptImage;
|
@@ -20,6 +24,6 @@ function NoFileContent(props) {
|
|
20
24
|
};
|
21
25
|
input.click();
|
22
26
|
}
|
23
|
-
return (_jsxs("div", { onDrop: handleDrop, className: "arkynImageUploadNoFileContent", children: [_jsx(Button, { isLoading: isLoading, onClick: handleClick, variant: "ghost", size: "sm", type: "button", children: selectImageButtonText }), _jsx("p", { children: dropImageText })] }));
|
27
|
+
return (_jsxs("div", { onDrop: handleDrop, className: "arkynImageUploadNoFileContent", children: [_jsx(Button, { isLoading: isLoading, onClick: handleClick, variant: "ghost", size: "sm", type: "button", disabled: disabled, children: selectImageButtonText }), _jsx("p", { children: dropImageText })] }));
|
24
28
|
}
|
25
29
|
export { NoFileContent };
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/ImageUpload/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAUhD,OAAO,cAAc,CAAC;AAEtB,iBAAS,WAAW,CAAC,KAAK,EAAE,gBAAgB,
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/ImageUpload/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAUhD,OAAO,cAAc,CAAC;AAEtB,iBAAS,WAAW,CAAC,KAAK,EAAE,gBAAgB,2CAoG3C;AAED,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
@@ -7,7 +7,7 @@ import { ImageUploadLabel } from "./ImageUploadLabel";
|
|
7
7
|
import { NoFileContent } from "./NoFileContent";
|
8
8
|
import "./styles.css";
|
9
9
|
function ImageUpload(props) {
|
10
|
-
const { name, defaultValue = "", label, showAsterisk = false, action, fileName = "file", method = "POST", acceptImage = "image/*", fileResponseName = "url", changeImageButtonText = "Alterar imagem", selectImageButtonText = "Selecionar imagem", dropImageText = "Ou arraste e solte a imagem aqui", onUpload, } = props;
|
10
|
+
const { name, defaultValue = "", label, showAsterisk = false, action, fileName = "file", method = "POST", acceptImage = "image/*", fileResponseName = "url", changeImageButtonText = "Alterar imagem", selectImageButtonText = "Selecionar imagem", dropImageText = "Ou arraste e solte a imagem aqui", onUpload, disabled = false, } = props;
|
11
11
|
const fieldErrors = useFieldErrors();
|
12
12
|
const fieldError = fieldErrors[name];
|
13
13
|
const [value, setValue] = useState(defaultValue);
|
@@ -16,6 +16,8 @@ function ImageUpload(props) {
|
|
16
16
|
const [filePath, setFilePath] = useState(defaultValue);
|
17
17
|
const [isLoading, setIsLoading] = useState(false);
|
18
18
|
async function handleUploadImage(file) {
|
19
|
+
if (disabled)
|
20
|
+
return;
|
19
21
|
setIsLoading(true);
|
20
22
|
setFile(file);
|
21
23
|
setError("");
|
@@ -37,6 +39,8 @@ function ImageUpload(props) {
|
|
37
39
|
.finally(() => setIsLoading(false));
|
38
40
|
}
|
39
41
|
function handleSelectFile(file) {
|
42
|
+
if (disabled)
|
43
|
+
return;
|
40
44
|
setFilePath(URL.createObjectURL(file));
|
41
45
|
handleUploadImage(file);
|
42
46
|
}
|
@@ -44,6 +48,6 @@ function ImageUpload(props) {
|
|
44
48
|
const hasErrorClassName = errorMessage ? "hasError" : "noHasError";
|
45
49
|
const hasImageClassName = filePath ? "hasImage" : "noHasImage";
|
46
50
|
const className = `arkynImageUpload ${hasErrorClassName} ${hasImageClassName}`;
|
47
|
-
return (_jsxs("div", { className: "arkynImageUploadContainer", children: [label && _jsx(ImageUploadLabel, { label: label, showAsterisk: showAsterisk }), _jsxs("div", { className: className, children: [_jsx("input", { type: "hidden", name: name, value: value || "" }), !filePath && (_jsx(NoFileContent, { isLoading: isLoading, acceptImage: acceptImage, dropImageText: dropImageText, handleSelectFile: handleSelectFile, selectImageButtonText: selectImageButtonText })), filePath && (_jsx(HasFileContent, { isLoading: isLoading, acceptImage: acceptImage, filePath: filePath, handleSelectFile: handleSelectFile, changeImageButtonText: changeImageButtonText, reSendImage: !!errorMessage && file ? () => handleUploadImage(file) : undefined }))] }), errorMessage && _jsx(ImageUploadError, { error: errorMessage })] }));
|
51
|
+
return (_jsxs("div", { className: "arkynImageUploadContainer", children: [label && _jsx(ImageUploadLabel, { label: label, showAsterisk: showAsterisk }), _jsxs("div", { className: className, children: [_jsx("input", { type: "hidden", name: name, value: value || "" }), !filePath && (_jsx(NoFileContent, { disabled: disabled, isLoading: isLoading, acceptImage: acceptImage, dropImageText: dropImageText, handleSelectFile: handleSelectFile, selectImageButtonText: selectImageButtonText })), filePath && (_jsx(HasFileContent, { disabled: disabled, isLoading: isLoading, acceptImage: acceptImage, filePath: filePath, handleSelectFile: handleSelectFile, changeImageButtonText: changeImageButtonText, reSendImage: !!errorMessage && file ? () => handleUploadImage(file) : undefined }))] }), errorMessage && _jsx(ImageUploadError, { error: errorMessage })] }));
|
48
52
|
}
|
49
53
|
export { ImageUpload };
|
package/package.json
CHANGED
@@ -9,6 +9,7 @@ import "./styles.css";
|
|
9
9
|
|
10
10
|
function HasFileContent(props: HasFileContentProps) {
|
11
11
|
const {
|
12
|
+
disabled,
|
12
13
|
filePath,
|
13
14
|
isLoading,
|
14
15
|
acceptImage,
|
@@ -18,6 +19,8 @@ function HasFileContent(props: HasFileContentProps) {
|
|
18
19
|
} = props;
|
19
20
|
|
20
21
|
function handleClick() {
|
22
|
+
if (disabled) return;
|
23
|
+
|
21
24
|
const input = document.createElement("input");
|
22
25
|
|
23
26
|
input.type = "file";
|
@@ -47,6 +50,7 @@ function HasFileContent(props: HasFileContentProps) {
|
|
47
50
|
isLoading={isLoading}
|
48
51
|
onClick={reSendImage}
|
49
52
|
icon={RefreshCw}
|
53
|
+
disabled={disabled}
|
50
54
|
/>
|
51
55
|
</Tooltip>
|
52
56
|
)}
|
@@ -57,6 +61,7 @@ function HasFileContent(props: HasFileContentProps) {
|
|
57
61
|
variant="outline"
|
58
62
|
size="sm"
|
59
63
|
type="button"
|
64
|
+
disabled={disabled}
|
60
65
|
>
|
61
66
|
{changeImageButtonText}
|
62
67
|
</Button>
|
@@ -12,15 +12,20 @@ function NoFileContent(props: NoFileContentProps) {
|
|
12
12
|
acceptImage,
|
13
13
|
handleSelectFile,
|
14
14
|
selectImageButtonText,
|
15
|
+
disabled,
|
15
16
|
} = props;
|
16
17
|
|
17
18
|
function handleDrop(event: DragEvent<HTMLDivElement>) {
|
19
|
+
if (disabled) return;
|
20
|
+
|
18
21
|
event.preventDefault();
|
19
22
|
const file = event.dataTransfer.files[0];
|
20
23
|
if (file) handleSelectFile(file);
|
21
24
|
}
|
22
25
|
|
23
26
|
function handleClick() {
|
27
|
+
if (disabled) return;
|
28
|
+
|
24
29
|
const input = document.createElement("input");
|
25
30
|
|
26
31
|
input.type = "file";
|
@@ -42,6 +47,7 @@ function NoFileContent(props: NoFileContentProps) {
|
|
42
47
|
variant="ghost"
|
43
48
|
size="sm"
|
44
49
|
type="button"
|
50
|
+
disabled={disabled}
|
45
51
|
>
|
46
52
|
{selectImageButtonText}
|
47
53
|
</Button>
|
@@ -25,6 +25,7 @@ function ImageUpload(props: ImageUploadProps) {
|
|
25
25
|
selectImageButtonText = "Selecionar imagem",
|
26
26
|
dropImageText = "Ou arraste e solte a imagem aqui",
|
27
27
|
onUpload,
|
28
|
+
disabled = false,
|
28
29
|
} = props;
|
29
30
|
|
30
31
|
const fieldErrors = useFieldErrors();
|
@@ -37,6 +38,8 @@ function ImageUpload(props: ImageUploadProps) {
|
|
37
38
|
const [isLoading, setIsLoading] = useState(false);
|
38
39
|
|
39
40
|
async function handleUploadImage(file: File) {
|
41
|
+
if (disabled) return;
|
42
|
+
|
40
43
|
setIsLoading(true);
|
41
44
|
setFile(file);
|
42
45
|
setError("");
|
@@ -59,6 +62,8 @@ function ImageUpload(props: ImageUploadProps) {
|
|
59
62
|
}
|
60
63
|
|
61
64
|
function handleSelectFile(file: File) {
|
65
|
+
if (disabled) return;
|
66
|
+
|
62
67
|
setFilePath(URL.createObjectURL(file));
|
63
68
|
handleUploadImage(file);
|
64
69
|
}
|
@@ -78,6 +83,7 @@ function ImageUpload(props: ImageUploadProps) {
|
|
78
83
|
|
79
84
|
{!filePath && (
|
80
85
|
<NoFileContent
|
86
|
+
disabled={disabled}
|
81
87
|
isLoading={isLoading}
|
82
88
|
acceptImage={acceptImage}
|
83
89
|
dropImageText={dropImageText}
|
@@ -88,6 +94,7 @@ function ImageUpload(props: ImageUploadProps) {
|
|
88
94
|
|
89
95
|
{filePath && (
|
90
96
|
<HasFileContent
|
97
|
+
disabled={disabled}
|
91
98
|
isLoading={isLoading}
|
92
99
|
acceptImage={acceptImage}
|
93
100
|
filePath={filePath}
|