@ssplib/react-components 0.0.98 → 0.0.99
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.
|
@@ -38,9 +38,12 @@ const lodash_get_1 = __importDefault(require("lodash.get"));
|
|
|
38
38
|
const react_1 = __importStar(require("react"));
|
|
39
39
|
const auth_1 = require("../../../context/auth");
|
|
40
40
|
const form_1 = require("../../../context/form");
|
|
41
|
+
const material_2 = require("@mui/material");
|
|
41
42
|
function FileUpload({ name, tipoArquivo, title, required = false, multiple = false, apiURL, xs = 12, sm, md, }) {
|
|
42
43
|
const context = (0, react_1.useContext)(form_1.FormContext);
|
|
43
44
|
const { user } = (0, react_1.useContext)(auth_1.AuthContext);
|
|
45
|
+
const theme = (0, material_2.useTheme)();
|
|
46
|
+
const isSmall = (0, material_1.useMediaQuery)(theme.breakpoints.only('xs'));
|
|
44
47
|
const [files, setFiles] = (0, react_1.useState)([]);
|
|
45
48
|
const [filesLoaded, setFilesLoaded] = (0, react_1.useState)([]);
|
|
46
49
|
const [fileIds, setFilesIds] = (0, react_1.useState)({});
|
|
@@ -115,8 +118,14 @@ function FileUpload({ name, tipoArquivo, title, required = false, multiple = fal
|
|
|
115
118
|
});
|
|
116
119
|
context === null || context === void 0 ? void 0 : context.formSetValue(name, dt.files);
|
|
117
120
|
}, [files, context, name]);
|
|
121
|
+
(0, react_1.useEffect)(() => {
|
|
122
|
+
return () => {
|
|
123
|
+
context.setFilesUid((files) => files.filter((x) => x.CO_TIPO_ARQUIVO !== parseInt(tipoArquivo)));
|
|
124
|
+
};
|
|
125
|
+
}, []);
|
|
118
126
|
return (react_1.default.createElement(material_1.Grid, Object.assign({ item: true }, { xs, sm, md }, { sx: { width: '100%' } }),
|
|
119
|
-
react_1.default.createElement(material_1.
|
|
127
|
+
react_1.default.createElement(material_1.FormLabel, { required: required, sx: { marginBottom: 2, textTransform: 'capitalize' } }, title),
|
|
128
|
+
react_1.default.createElement(material_1.Box, { sx: { backgroundColor: '#e2eafc', padding: 1, borderRadius: 1, marginTop: 1 } },
|
|
120
129
|
react_1.default.createElement("input", Object.assign({ id: name, type: 'file', multiple: multiple }, context === null || context === void 0 ? void 0 : context.formRegister(name, {
|
|
121
130
|
validate: (v, f) => {
|
|
122
131
|
if (v.length <= 0 && required)
|
|
@@ -135,10 +144,10 @@ function FileUpload({ name, tipoArquivo, title, required = false, multiple = fal
|
|
|
135
144
|
md: 'flex',
|
|
136
145
|
},
|
|
137
146
|
} },
|
|
138
|
-
react_1.default.createElement(material_1.Box, { sx: { width: '100%', marginRight: { xs: 0, md: 1 }, marginBottom: { xs: 1, md: 0 } } }, !multiple && files.length >= 1 ? (react_1.default.createElement(material_1.Button, { disabled: true, variant: 'contained', disableElevation: true, startIcon: react_1.default.createElement(InsertDriveFile_1.default, null), component: 'span', sx: { textTransform: 'none' }, fullWidth: true },
|
|
139
|
-
react_1.default.createElement(material_1.Button, { variant: 'contained', disableElevation: true, startIcon: react_1.default.createElement(InsertDriveFile_1.default, null), component: 'span', sx: { textTransform: 'none' }, fullWidth: true },
|
|
140
|
-
react_1.default.createElement(material_1.Box, { sx: { width: '100%' } }, !multiple && files.length >= 1 ? (react_1.default.createElement(material_1.Button, { disabled: true, variant: 'contained', disableElevation: true, startIcon: react_1.default.createElement(CameraAlt_1.default, null), component: 'span', sx: { textTransform: 'none', backgroundColor: '#0096c7' }, fullWidth: true },
|
|
141
|
-
react_1.default.createElement(material_1.Button, { variant: 'contained', disableElevation: true, startIcon: react_1.default.createElement(CameraAlt_1.default, null), component: 'span', sx: { textTransform: 'none', backgroundColor: '#0096c7' }, fullWidth: true },
|
|
147
|
+
react_1.default.createElement(material_1.Box, { sx: { width: '100%', marginRight: { xs: 0, md: 1 }, marginBottom: { xs: 1, md: 0 } } }, !multiple && files.length >= 1 ? (react_1.default.createElement(material_1.Button, { disabled: true, variant: 'contained', disableElevation: true, startIcon: react_1.default.createElement(InsertDriveFile_1.default, null), component: 'span', sx: { textTransform: 'none' }, fullWidth: true }, "Escolher Documento")) : (react_1.default.createElement("label", { htmlFor: name },
|
|
148
|
+
react_1.default.createElement(material_1.Button, { variant: 'contained', disableElevation: true, startIcon: react_1.default.createElement(InsertDriveFile_1.default, null), component: 'span', sx: { textTransform: 'none' }, fullWidth: true }, "Escolher Documento")))),
|
|
149
|
+
react_1.default.createElement(material_1.Box, { sx: { width: '100%' } }, !multiple && files.length >= 1 ? (react_1.default.createElement(material_1.Button, { disabled: true, variant: 'contained', disableElevation: true, startIcon: react_1.default.createElement(CameraAlt_1.default, null), component: 'span', sx: { textTransform: 'none', backgroundColor: '#0096c7' }, fullWidth: true }, isSmall ? 'Tirar Foto' : 'Escolher Imagem')) : (react_1.default.createElement("label", { htmlFor: name + 'foto' },
|
|
150
|
+
react_1.default.createElement(material_1.Button, { variant: 'contained', disableElevation: true, startIcon: react_1.default.createElement(CameraAlt_1.default, null), component: 'span', sx: { textTransform: 'none', backgroundColor: '#0096c7' }, fullWidth: true }, isSmall ? 'Tirar Foto' : 'Escolher Imagem'))))),
|
|
142
151
|
react_1.default.createElement(material_1.Typography, { fontWeight: 600, paddingY: 1, color: 'black' },
|
|
143
152
|
"Voc\u00EA selecionou ",
|
|
144
153
|
files.length,
|