@symply.io/basic-components 1.0.5 → 1.0.6-beta.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.
- package/FileUploader/index.d.ts +4 -0
- package/FileUploader/index.js +62 -0
- package/FileUploader/types.d.ts +21 -0
- package/FileUploader/types.js +1 -0
- package/FileUploader/useInteractions.d.ts +17 -0
- package/FileUploader/useInteractions.js +79 -0
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/package.json +2 -1
@@ -0,0 +1,62 @@
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
2
|
+
__assign = Object.assign || function(t) {
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
4
|
+
s = arguments[i];
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
6
|
+
t[p] = s[p];
|
7
|
+
}
|
8
|
+
return t;
|
9
|
+
};
|
10
|
+
return __assign.apply(this, arguments);
|
11
|
+
};
|
12
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
13
|
+
var t = {};
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
15
|
+
t[p] = s[p];
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
19
|
+
t[p[i]] = s[p[i]];
|
20
|
+
}
|
21
|
+
return t;
|
22
|
+
};
|
23
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
24
|
+
import Link from "@mui/material/Link";
|
25
|
+
import Grid from "@mui/material/Grid";
|
26
|
+
import Button from "@mui/material/Button";
|
27
|
+
import Typography from "@mui/material/Typography";
|
28
|
+
import useMediaQuery from "@mui/material/useMediaQuery";
|
29
|
+
import CircularProgress from "@mui/material/CircularProgress";
|
30
|
+
import ThemeProvider from "@mui/material/styles/ThemeProvider";
|
31
|
+
import useInteractions from "./useInteractions";
|
32
|
+
import useCustomTheme from "../useCustomTheme";
|
33
|
+
function FileUploader(props) {
|
34
|
+
var _a = props.height, height = _a === void 0 ? "150px" : _a, _b = props.maxWidth, maxWidth = _b === void 0 ? "430px" : _b, loading = props.loading, disabled = props.disabled, dropFileText = props.dropFileText, chooseFileText = props.chooseFileText, primaryColor = props.primaryColor, secondaryColor = props.secondaryColor, rest = __rest(props, ["height", "maxWidth", "loading", "disabled", "dropFileText", "chooseFileText", "primaryColor", "secondaryColor"]);
|
35
|
+
var theme = useCustomTheme({ primaryColor: primaryColor, secondaryColor: secondaryColor });
|
36
|
+
var lessThanSm = useMediaQuery(theme.breakpoints.down("sm"));
|
37
|
+
var _c = useInteractions(__assign(__assign({}, rest), { disabled: disabled })), alertArgs = _c.alertArgs, rootProps = _c.rootProps, onCloseAlert = _c.onCloseAlert, onSelectFile = _c.onSelectFile, getRootProps = _c.getRootProps, getInputProps = _c.getInputProps;
|
38
|
+
return (_jsx(ThemeProvider, __assign({ theme: theme }, { children: lessThanSm ? (_jsxs("div", __assign({}, getRootProps(), { children: [_jsx("input", __assign({}, getInputProps())), _jsx(Link, __assign({ color: disabled ? theme.palette.grey[400] : theme.palette.primary.main, sx: {
|
39
|
+
fontFamily: "Roboto, Helvetica, Arial, sans-serif",
|
40
|
+
cursor: disabled ? "not-allowed" : "pointer"
|
41
|
+
} }, { children: loading ? (_jsx(CircularProgress, { sx: { height: "25px", width: "25px" } })) : (chooseFileText || "Choose a file") }))] }))) : (_jsx(Grid, __assign({ container: true, direction: "column", justifyContent: "center", alignItems: "center", sx: {
|
42
|
+
border: "1px dashed #0099a7",
|
43
|
+
borderRadius: "5px",
|
44
|
+
outline: "none",
|
45
|
+
backgroundColor: "#F2F2F2",
|
46
|
+
maxWidth: maxWidth,
|
47
|
+
height: height,
|
48
|
+
width: "100%"
|
49
|
+
} }, rootProps, { children: loading ? (_jsx(CircularProgress, { style: { height: "30px", width: "30px" } })) : (_jsxs("div", { children: [_jsx("input", __assign({}, getInputProps())), _jsx(Typography, __assign({ component: "p", variant: "caption", sx: {
|
50
|
+
fontSize: ".875rem",
|
51
|
+
textAlign: "center"
|
52
|
+
} }, { children: dropFileText || "Drop files here" })), _jsx(Button, __assign({ variant: "contained", onClick: onSelectFile, sx: {
|
53
|
+
backgroundColor: "white !important",
|
54
|
+
color: disabled
|
55
|
+
? theme.palette.grey[400]
|
56
|
+
: theme.palette.primary.main,
|
57
|
+
fontFamily: "Roboto, Helvetica, Arial, sans-serif",
|
58
|
+
cursor: disabled ? "not-allowed" : "pointer"
|
59
|
+
}, disabled: disabled }, { children: _jsx(Typography, { children: chooseFileText || "Choose a file" }) }))] })) }))) })));
|
60
|
+
}
|
61
|
+
export default FileUploader;
|
62
|
+
export * from "./types";
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import { CSSProperties } from "react";
|
2
|
+
import { DropzoneProps } from "react-dropzone";
|
3
|
+
export interface InterfaceProps {
|
4
|
+
sizeExceededErrorText?: string;
|
5
|
+
wrongFileTypeErrorText?: string;
|
6
|
+
onUpload: (files: Array<File>) => void;
|
7
|
+
disabled?: boolean;
|
8
|
+
maxSize?: number;
|
9
|
+
accept?: DropzoneProps["accept"];
|
10
|
+
maxFiles?: DropzoneProps["maxFiles"];
|
11
|
+
multiple?: DropzoneProps["multiple"];
|
12
|
+
}
|
13
|
+
export interface FileUploaderProps extends InterfaceProps {
|
14
|
+
loading?: boolean;
|
15
|
+
dropFileText?: string;
|
16
|
+
chooseFileText?: string;
|
17
|
+
height?: CSSProperties["height"];
|
18
|
+
maxWidth?: CSSProperties["maxWidth"];
|
19
|
+
primaryColor?: CSSProperties["color"];
|
20
|
+
secondaryColor?: CSSProperties["color"];
|
21
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,17 @@
|
|
1
|
+
/// <reference types="react" />
|
2
|
+
import { InterfaceProps } from "./types";
|
3
|
+
declare function useInteractions(props: InterfaceProps): {
|
4
|
+
alertArgs: {
|
5
|
+
open: boolean;
|
6
|
+
message: string;
|
7
|
+
};
|
8
|
+
rootProps: {
|
9
|
+
onClick: (e: import("react").MouseEvent<HTMLElement, MouseEvent>) => void;
|
10
|
+
onKeyDown: (e: import("react").KeyboardEvent<HTMLElement>) => void;
|
11
|
+
};
|
12
|
+
onCloseAlert: () => void;
|
13
|
+
onSelectFile: () => void;
|
14
|
+
getRootProps: <T extends import("react-dropzone").DropzoneRootProps>(props?: T | undefined) => T;
|
15
|
+
getInputProps: <T_1 extends import("react-dropzone").DropzoneInputProps>(props?: T_1 | undefined) => T_1;
|
16
|
+
};
|
17
|
+
export default useInteractions;
|
@@ -0,0 +1,79 @@
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
2
|
+
__assign = Object.assign || function(t) {
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
4
|
+
s = arguments[i];
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
6
|
+
t[p] = s[p];
|
7
|
+
}
|
8
|
+
return t;
|
9
|
+
};
|
10
|
+
return __assign.apply(this, arguments);
|
11
|
+
};
|
12
|
+
import { useState, useCallback, useMemo } from "react";
|
13
|
+
import { useDropzone } from "react-dropzone";
|
14
|
+
function useInteractions(props) {
|
15
|
+
var multiple = props.multiple, disabled = props.disabled, maxFiles = props.maxFiles, _a = props.maxSize, maxSize = _a === void 0 ? 1024 * 1024 * 5 : _a, accept = props.accept, onUpload = props.onUpload, sizeExceededErrorText = props.sizeExceededErrorText, wrongFileTypeErrorText = props.wrongFileTypeErrorText;
|
16
|
+
var ERROR_TYPE_MSG = useMemo(function () {
|
17
|
+
return wrongFileTypeErrorText ||
|
18
|
+
"The type of the file you uploaded is not accepted, please reupload!";
|
19
|
+
}, [wrongFileTypeErrorText]);
|
20
|
+
var ERROR_SIZE_MSG = useMemo(function () {
|
21
|
+
return sizeExceededErrorText ||
|
22
|
+
"Your file exceed the max size of ".concat(maxSize / 1024 / 1024, "MB.");
|
23
|
+
}, [sizeExceededErrorText, maxSize]);
|
24
|
+
var _b = useState({ open: false, message: "" }), alertArgs = _b[0], setAlertArgs = _b[1];
|
25
|
+
var onOpenAlert = useCallback(function (message) {
|
26
|
+
setAlertArgs(function (args) { return (__assign(__assign({}, args), { open: true, message: message })); });
|
27
|
+
}, []);
|
28
|
+
var onCloseAlert = useCallback(function () {
|
29
|
+
setAlertArgs({ open: false, message: "" });
|
30
|
+
}, []);
|
31
|
+
var onDrop = useCallback(function (acceptedFiles, rejectedFiles) {
|
32
|
+
if (rejectedFiles && rejectedFiles.length > 0) {
|
33
|
+
rejectedFiles.some(function (rejectedFile) {
|
34
|
+
var file = rejectedFile.file, errors = rejectedFile.errors;
|
35
|
+
if (accept && !Object.keys(accept).includes(file.type)) {
|
36
|
+
onOpenAlert(ERROR_TYPE_MSG);
|
37
|
+
return true;
|
38
|
+
}
|
39
|
+
if (file.size > maxSize) {
|
40
|
+
onOpenAlert(ERROR_SIZE_MSG);
|
41
|
+
return true;
|
42
|
+
}
|
43
|
+
if (errors.length > 0) {
|
44
|
+
onOpenAlert(errors.join("; "));
|
45
|
+
return true;
|
46
|
+
}
|
47
|
+
return false;
|
48
|
+
});
|
49
|
+
}
|
50
|
+
else {
|
51
|
+
onUpload(acceptedFiles);
|
52
|
+
}
|
53
|
+
}, [accept, onUpload]);
|
54
|
+
var _c = useDropzone({
|
55
|
+
onDrop: onDrop,
|
56
|
+
accept: accept,
|
57
|
+
multiple: multiple,
|
58
|
+
disabled: disabled,
|
59
|
+
maxSize: maxSize,
|
60
|
+
maxFiles: maxFiles
|
61
|
+
}), getRootProps = _c.getRootProps, getInputProps = _c.getInputProps, onSelectFile = _c.open;
|
62
|
+
var rootProps = getRootProps({
|
63
|
+
onClick: function (e) { return e.stopPropagation(); },
|
64
|
+
onKeyDown: function (e) {
|
65
|
+
if (e.key === "Space" || e.key === "Enter") {
|
66
|
+
e.stopPropagation();
|
67
|
+
}
|
68
|
+
}
|
69
|
+
});
|
70
|
+
return {
|
71
|
+
alertArgs: alertArgs,
|
72
|
+
rootProps: rootProps,
|
73
|
+
onCloseAlert: onCloseAlert,
|
74
|
+
onSelectFile: onSelectFile,
|
75
|
+
getRootProps: getRootProps,
|
76
|
+
getInputProps: getInputProps
|
77
|
+
};
|
78
|
+
}
|
79
|
+
export default useInteractions;
|
package/index.d.ts
CHANGED
@@ -10,6 +10,7 @@ export * from "./DateInput";
|
|
10
10
|
export * from "./DigitInput";
|
11
11
|
export * from "./DynamicHeaderBar";
|
12
12
|
export * from "./FeinInput";
|
13
|
+
export * from "./FileUploader";
|
13
14
|
export * from "./FormRadioGroup";
|
14
15
|
export * from "./FormSelector";
|
15
16
|
export * from "./HelpCaption";
|
@@ -35,6 +36,7 @@ export { default as Copyright } from "./Copyright";
|
|
35
36
|
export { default as DigitInput } from "./DigitInput";
|
36
37
|
export { default as DynamicHeaderBar } from "./DynamicHeaderBar";
|
37
38
|
export { default as FeinInput } from "./FeinInput";
|
39
|
+
export { default as FileUploader } from "./FileUploader";
|
38
40
|
export { default as FormRadioGroup } from "./FormRadioGroup";
|
39
41
|
export { default as HelpCaption } from "./HelpCaption";
|
40
42
|
export { default as LoadingModal } from "./LoadingModal";
|
package/index.js
CHANGED
@@ -10,6 +10,7 @@ export * from "./DateInput";
|
|
10
10
|
export * from "./DigitInput";
|
11
11
|
export * from "./DynamicHeaderBar";
|
12
12
|
export * from "./FeinInput";
|
13
|
+
export * from "./FileUploader";
|
13
14
|
export * from "./FormRadioGroup";
|
14
15
|
export * from "./FormSelector";
|
15
16
|
export * from "./HelpCaption";
|
@@ -35,6 +36,7 @@ export { default as Copyright } from "./Copyright";
|
|
35
36
|
export { default as DigitInput } from "./DigitInput";
|
36
37
|
export { default as DynamicHeaderBar } from "./DynamicHeaderBar";
|
37
38
|
export { default as FeinInput } from "./FeinInput";
|
39
|
+
export { default as FileUploader } from "./FileUploader";
|
38
40
|
export { default as FormRadioGroup } from "./FormRadioGroup";
|
39
41
|
export { default as HelpCaption } from "./HelpCaption";
|
40
42
|
export { default as LoadingModal } from "./LoadingModal";
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@symply.io/basic-components",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.6-beta.1",
|
4
4
|
"description": "Basic and reusable components for all frontend of Symply apps",
|
5
5
|
"keywords": [
|
6
6
|
"react",
|
@@ -58,6 +58,7 @@
|
|
58
58
|
"@mui/system": "~5.4.2",
|
59
59
|
"@reach/router": "^1.3.4",
|
60
60
|
"color-alpha": "^1.1.3",
|
61
|
+
"react-dropzone": "~14.2.3",
|
61
62
|
"react-player": "^2.9.0",
|
62
63
|
"rifm": "^0.12.1"
|
63
64
|
},
|