@ssplib/react-components 0.0.248 → 0.0.250
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/package.json +2 -2
- package/src/components/detalhes/Category.js +7 -0
- package/src/components/detalhes/Field.js +35 -0
- package/src/components/detalhes/FieldLabel.js +21 -0
- package/src/components/detalhes/File.js +35 -0
- package/src/components/form/checkbox/CheckBox.js +12 -0
- package/{components → src/components}/form/checkbox/CheckBoxAdditional.js +11 -37
- package/src/components/form/checkbox/CheckBoxWarning.js +14 -0
- package/src/components/form/checkbox/RequiredCheckBoxValidator.js +56 -0
- package/src/components/form/date/DatePicker.js +71 -0
- package/src/components/form/date/TimePicker.js +53 -0
- package/src/components/form/file/DropFileUpload.js +207 -0
- package/src/components/form/file/FileUpload.js +171 -0
- package/src/components/form/input/ActiveInput.js +27 -0
- package/src/components/form/input/AutoComplete.js +40 -0
- package/src/components/form/input/FetchAutoComplete.js +103 -0
- package/src/components/form/input/FixedAutoComplete.js +46 -0
- package/{components → src/components}/form/input/Input.js +22 -52
- package/src/components/form/input/MaskInput.js +52 -0
- package/src/components/form/input/MultInput.js +38 -0
- package/src/components/form/input/OtherCheckBox.js +27 -0
- package/src/components/form/stepper/Stepper.js +105 -0
- package/src/components/form/stepper/StepperBlock.js +67 -0
- package/src/components/form/switch/Switch.js +27 -0
- package/src/components/form/switch/ToggleVisibility.js +33 -0
- package/{components → src/components}/form/table/Table.js +200 -230
- package/src/components/icons/icons.js +16 -0
- package/src/components/modal/Modal.js +75 -0
- package/src/components/navbar/NavBar.js +127 -0
- package/src/components/navbar/TabNavBar.js +135 -0
- package/src/components/providers/FormProvider.js +23 -0
- package/src/components/providers/KeycloakAuthProvider.js +69 -0
- package/{components → src/components}/providers/OAuthProvider.js +19 -49
- package/src/components/providers/SspComponentsProvider.js +11 -0
- package/{components → src/components}/utils/Bt.js +7 -13
- package/src/components/utils/CustomMenu.js +33 -0
- package/src/context/auth.js +2 -0
- package/{context → src/context}/form.d.ts +2 -3
- package/src/context/form.js +2 -0
- package/src/index.js +41 -0
- package/src/types/auth.js +1 -0
- package/{types → src/types}/form.js +4 -7
- package/components/detalhes/Category.js +0 -14
- package/components/detalhes/Field.js +0 -42
- package/components/detalhes/FieldLabel.js +0 -28
- package/components/detalhes/File.js +0 -62
- package/components/form/checkbox/CheckBox.js +0 -18
- package/components/form/checkbox/CheckBoxWarning.js +0 -43
- package/components/form/checkbox/RequiredCheckBoxValidator.js +0 -85
- package/components/form/date/DatePicker.js +0 -100
- package/components/form/date/TimePicker.js +0 -82
- package/components/form/file/DropFileUpload.js +0 -236
- package/components/form/file/FileUpload.js +0 -200
- package/components/form/input/ActiveInput.js +0 -33
- package/components/form/input/AutoComplete.js +0 -69
- package/components/form/input/FetchAutoComplete.js +0 -132
- package/components/form/input/FixedAutoComplete.js +0 -76
- package/components/form/input/MaskInput.js +0 -78
- package/components/form/input/MultInput.js +0 -67
- package/components/form/input/OtherCheckBox.js +0 -56
- package/components/form/stepper/Stepper.js +0 -135
- package/components/form/stepper/StepperBlock.js +0 -97
- package/components/form/switch/Switch.js +0 -54
- package/components/form/switch/ToggleVisibility.js +0 -61
- package/components/icons/icons.js +0 -24
- package/components/modal/Modal.js +0 -105
- package/components/navbar/NavBar.js +0 -156
- package/components/navbar/TabNavBar.js +0 -164
- package/components/providers/FormProvider.js +0 -49
- package/components/providers/KeycloakAuthProvider.js +0 -98
- package/components/providers/SspComponentsProvider.js +0 -18
- package/components/utils/CustomMenu.js +0 -39
- package/context/auth.js +0 -5
- package/context/form.js +0 -5
- package/index.js +0 -80
- package/types/auth.js +0 -2
- /package/{components → src/components}/detalhes/Category.d.ts +0 -0
- /package/{components → src/components}/detalhes/Field.d.ts +0 -0
- /package/{components → src/components}/detalhes/FieldLabel.d.ts +0 -0
- /package/{components → src/components}/detalhes/File.d.ts +0 -0
- /package/{components → src/components}/form/checkbox/CheckBox.d.ts +0 -0
- /package/{components → src/components}/form/checkbox/CheckBoxAdditional.d.ts +0 -0
- /package/{components → src/components}/form/checkbox/CheckBoxWarning.d.ts +0 -0
- /package/{components → src/components}/form/checkbox/RequiredCheckBoxValidator.d.ts +0 -0
- /package/{components → src/components}/form/date/DatePicker.d.ts +0 -0
- /package/{components → src/components}/form/date/TimePicker.d.ts +0 -0
- /package/{components → src/components}/form/file/DropFileUpload.d.ts +0 -0
- /package/{components → src/components}/form/file/FileUpload.d.ts +0 -0
- /package/{components → src/components}/form/input/ActiveInput.d.ts +0 -0
- /package/{components → src/components}/form/input/AutoComplete.d.ts +0 -0
- /package/{components → src/components}/form/input/FetchAutoComplete.d.ts +0 -0
- /package/{components → src/components}/form/input/FixedAutoComplete.d.ts +0 -0
- /package/{components → src/components}/form/input/Input.d.ts +0 -0
- /package/{components → src/components}/form/input/MaskInput.d.ts +0 -0
- /package/{components → src/components}/form/input/MultInput.d.ts +0 -0
- /package/{components → src/components}/form/input/OtherCheckBox.d.ts +0 -0
- /package/{components → src/components}/form/stepper/Stepper.d.ts +0 -0
- /package/{components → src/components}/form/stepper/StepperBlock.d.ts +0 -0
- /package/{components → src/components}/form/switch/Switch.d.ts +0 -0
- /package/{components → src/components}/form/switch/ToggleVisibility.d.ts +0 -0
- /package/{components → src/components}/form/table/Table.d.ts +0 -0
- /package/{components → src/components}/icons/icons.d.ts +0 -0
- /package/{components → src/components}/modal/Modal.d.ts +0 -0
- /package/{components → src/components}/navbar/NavBar.d.ts +0 -0
- /package/{components → src/components}/navbar/TabNavBar.d.ts +0 -0
- /package/{components → src/components}/providers/FormProvider.d.ts +0 -0
- /package/{components → src/components}/providers/KeycloakAuthProvider.d.ts +0 -0
- /package/{components → src/components}/providers/OAuthProvider.d.ts +0 -0
- /package/{components → src/components}/providers/SspComponentsProvider.d.ts +0 -0
- /package/{components → src/components}/utils/Bt.d.ts +0 -0
- /package/{components → src/components}/utils/CustomMenu.d.ts +0 -0
- /package/{context → src/context}/auth.d.ts +0 -0
- /package/{index.d.ts → src/index.d.ts} +0 -0
- /package/{types → src/types}/auth.d.ts +0 -0
- /package/{types → src/types}/form.d.ts +0 -0
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import CameraAltIcon from '@mui/icons-material/CameraAlt';
|
|
2
|
+
import Delete from '@mui/icons-material/Delete';
|
|
3
|
+
import DoneIcon from '@mui/icons-material/Done';
|
|
4
|
+
import InsertDriveFileIcon from '@mui/icons-material/InsertDriveFile';
|
|
5
|
+
import PictureAsPdf from '@mui/icons-material/PictureAsPdf';
|
|
6
|
+
import { Box, Button, CircularProgress, Grid, InputLabel, Paper, TableContainer, Typography, useMediaQuery, useTheme } from '@mui/material';
|
|
7
|
+
import { Stack } from '@mui/system';
|
|
8
|
+
import get from 'lodash.get';
|
|
9
|
+
import React, { useCallback, useContext, useEffect, useState } from 'react';
|
|
10
|
+
import { AuthContext } from '../../../context/auth';
|
|
11
|
+
import { FormContext } from '../../../context/form';
|
|
12
|
+
function bytesToMegabytes(bytes) {
|
|
13
|
+
const megabytes = bytes / (1024 * 1024);
|
|
14
|
+
return megabytes;
|
|
15
|
+
}
|
|
16
|
+
export default function FileUpload({ name, tipoArquivo, title, required = false, multiple = false, apiURL, route = '', sizeLimit = 4, xs = 12, sm, md, }) {
|
|
17
|
+
const context = useContext(FormContext);
|
|
18
|
+
const { user } = useContext(AuthContext);
|
|
19
|
+
const theme = useTheme();
|
|
20
|
+
const isSmall = useMediaQuery(theme.breakpoints.only('xs'));
|
|
21
|
+
const [files, setFiles] = useState([]);
|
|
22
|
+
const [filesLoaded, setFilesLoaded] = useState([]);
|
|
23
|
+
const [fileIds, setFilesIds] = useState({});
|
|
24
|
+
// const [filesError, setFilesError] = useState<number[]>([])
|
|
25
|
+
const [errorMsg, setErrorMsg] = useState('');
|
|
26
|
+
const onFile = useCallback((e) => {
|
|
27
|
+
const newFiles = e.target.files;
|
|
28
|
+
const filesTo = Object.keys(newFiles).map((key) => newFiles[key]);
|
|
29
|
+
setFiles([
|
|
30
|
+
...files,
|
|
31
|
+
...filesTo
|
|
32
|
+
.filter((file) => {
|
|
33
|
+
if (bytesToMegabytes(file.size) > sizeLimit) {
|
|
34
|
+
setErrorMsg(`Por favor, escolha um arquivo com tamanho inferior a ${sizeLimit} MB`);
|
|
35
|
+
setTimeout(() => {
|
|
36
|
+
setErrorMsg('');
|
|
37
|
+
}, 3000);
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
return true;
|
|
41
|
+
})
|
|
42
|
+
.map((file, index) => {
|
|
43
|
+
let id = Date.now() + index;
|
|
44
|
+
// fetch API
|
|
45
|
+
const fd = new FormData();
|
|
46
|
+
fd.append('files', file);
|
|
47
|
+
fd.append('tipoArquivo', tipoArquivo);
|
|
48
|
+
fetch(apiURL, {
|
|
49
|
+
method: 'POST',
|
|
50
|
+
body: fd,
|
|
51
|
+
headers: {
|
|
52
|
+
Authorization: `Bearer ${user ? user.token : ''}`,
|
|
53
|
+
},
|
|
54
|
+
})
|
|
55
|
+
.then((res) => {
|
|
56
|
+
if (!res.ok) {
|
|
57
|
+
removeFile(id);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
res.json().then((j) => {
|
|
61
|
+
if (j.status && j.status.status === 200) {
|
|
62
|
+
const fileIdFromApi = get(j, route, j)[0];
|
|
63
|
+
const fileId = fileIdFromApi['coSeqArquivo'];
|
|
64
|
+
context.setFilesUid((fId) => [
|
|
65
|
+
...fId,
|
|
66
|
+
{
|
|
67
|
+
CO_SEQ_ARQUIVO: fileId,
|
|
68
|
+
CO_TIPO_ARQUIVO: parseInt(tipoArquivo),
|
|
69
|
+
},
|
|
70
|
+
]);
|
|
71
|
+
setFilesLoaded((fl) => [...fl, id]);
|
|
72
|
+
const f = {};
|
|
73
|
+
f[id] = fileId;
|
|
74
|
+
setFilesIds((ids) => (Object.assign(Object.assign({}, ids), f)));
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
removeFile(id);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
})
|
|
81
|
+
.catch((err) => {
|
|
82
|
+
removeFile(id);
|
|
83
|
+
});
|
|
84
|
+
return { id: id, name: file.name, loading: true, error: false, file: file };
|
|
85
|
+
}),
|
|
86
|
+
]);
|
|
87
|
+
}, [files, context]);
|
|
88
|
+
const removeFile = (id, hideMsg, fileId) => {
|
|
89
|
+
setFiles(files.filter((x) => x.id !== id));
|
|
90
|
+
if (fileId)
|
|
91
|
+
context.setFilesUid((fId) => fId.filter((idd) => idd.CO_SEQ_ARQUIVO !== fileId));
|
|
92
|
+
if (!hideMsg) {
|
|
93
|
+
setErrorMsg('Erro ao enviar arquivo. Tente novamente mais tarde');
|
|
94
|
+
setTimeout(() => {
|
|
95
|
+
setErrorMsg('');
|
|
96
|
+
}, 3000);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
const deleteFile = (e, id) => {
|
|
100
|
+
if (Object.keys(fileIds).includes(id.toString())) {
|
|
101
|
+
fetch(`${apiURL}/${fileIds[id]}`, {
|
|
102
|
+
method: 'DELETE',
|
|
103
|
+
headers: {
|
|
104
|
+
Authorization: `Bearer ${user === null || user === void 0 ? void 0 : user.token}`,
|
|
105
|
+
},
|
|
106
|
+
})
|
|
107
|
+
.then((res) => {
|
|
108
|
+
if (!res.ok)
|
|
109
|
+
removeFile(id, true, fileIds[id]);
|
|
110
|
+
if (res.status === 200) {
|
|
111
|
+
removeFile(id, true, fileIds[id]);
|
|
112
|
+
}
|
|
113
|
+
})
|
|
114
|
+
.catch((err) => console.log(err));
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
useEffect(() => {
|
|
118
|
+
const dt = new DataTransfer();
|
|
119
|
+
files.forEach((x) => {
|
|
120
|
+
dt.items.add(x.file);
|
|
121
|
+
});
|
|
122
|
+
context === null || context === void 0 ? void 0 : context.formSetValue(name, dt.files);
|
|
123
|
+
}, [files, context, name]);
|
|
124
|
+
useEffect(() => {
|
|
125
|
+
return () => {
|
|
126
|
+
context.setFilesUid((files) => files.filter((x) => x.CO_TIPO_ARQUIVO !== parseInt(tipoArquivo)));
|
|
127
|
+
};
|
|
128
|
+
}, []);
|
|
129
|
+
return (React.createElement(Grid, Object.assign({ item: true }, { xs, sm, md }, { sx: { width: '100%' } }),
|
|
130
|
+
React.createElement(InputLabel, { required: required, sx: { marginBottom: 2, textTransform: 'capitalize' } }, title),
|
|
131
|
+
React.createElement(Box, { sx: { backgroundColor: '#e2eafc', padding: 1, borderRadius: 1, marginTop: 1 } },
|
|
132
|
+
React.createElement("input", Object.assign({ id: name, type: 'file', multiple: multiple }, context === null || context === void 0 ? void 0 : context.formRegister(name, {
|
|
133
|
+
validate: (v, f) => {
|
|
134
|
+
if ((v.length && filesLoaded.length) <= 0 && required)
|
|
135
|
+
return 'O campo de arquivo é obrigatório';
|
|
136
|
+
},
|
|
137
|
+
}), { onChange: onFile, accept: '.pdf', style: { display: 'none' } })),
|
|
138
|
+
React.createElement("input", Object.assign({ id: name + 'foto', type: 'file', capture: 'environment', multiple: multiple }, context === null || context === void 0 ? void 0 : context.formRegister(name, {
|
|
139
|
+
validate: (v, f) => {
|
|
140
|
+
if ((v.length && filesLoaded.length) <= 0 && required)
|
|
141
|
+
return 'O campo de arquivo é obrigatório';
|
|
142
|
+
},
|
|
143
|
+
}), { onChange: onFile, accept: '.jpg, .png, .jpeg', style: { display: 'none' } })),
|
|
144
|
+
React.createElement(Box, { sx: {
|
|
145
|
+
display: {
|
|
146
|
+
sx: 'block',
|
|
147
|
+
md: 'flex',
|
|
148
|
+
},
|
|
149
|
+
} },
|
|
150
|
+
React.createElement(Box, { sx: { width: '100%', marginRight: { xs: 0, md: 1 }, marginBottom: { xs: 1, md: 0 } } }, !multiple && files.length >= 1 ? (React.createElement(Button, { disabled: true, variant: 'contained', disableElevation: true, startIcon: React.createElement(InsertDriveFileIcon, null), component: 'span', sx: { textTransform: 'none' }, fullWidth: true }, "Escolher Documento")) : (React.createElement("label", { htmlFor: name },
|
|
151
|
+
React.createElement(Button, { variant: 'contained', disableElevation: true, startIcon: React.createElement(InsertDriveFileIcon, null), component: 'span', sx: { textTransform: 'none' }, fullWidth: true }, "Escolher Documento")))),
|
|
152
|
+
React.createElement(Box, { sx: { width: '100%' } }, !multiple && files.length >= 1 ? (React.createElement(Button, { disabled: true, variant: 'contained', disableElevation: true, startIcon: React.createElement(CameraAltIcon, null), component: 'span', sx: { textTransform: 'none', backgroundColor: '#0096c7' }, fullWidth: true }, isSmall ? 'Tirar Foto' : 'Escolher Imagem')) : (React.createElement("label", { htmlFor: name + 'foto' },
|
|
153
|
+
React.createElement(Button, { variant: 'contained', disableElevation: true, startIcon: React.createElement(CameraAltIcon, null), component: 'span', sx: { textTransform: 'none', backgroundColor: '#0096c7' }, fullWidth: true }, isSmall ? 'Tirar Foto' : 'Escolher Imagem'))))),
|
|
154
|
+
React.createElement(Typography, { fontWeight: 600, paddingY: 1, color: 'black' },
|
|
155
|
+
"Voc\u00EA selecionou ",
|
|
156
|
+
files.length,
|
|
157
|
+
" arquivo",
|
|
158
|
+
files.length > 1 && 's'),
|
|
159
|
+
files.length > 0 && (React.createElement(TableContainer, { component: Paper },
|
|
160
|
+
React.createElement(Stack, { direction: 'column' }, files.map((x) => (React.createElement(Stack, { key: x.name, direction: 'row', justifyContent: 'space-between', padding: 0.5 },
|
|
161
|
+
React.createElement(Box, null,
|
|
162
|
+
React.createElement(Stack, { direction: 'row', spacing: 2 },
|
|
163
|
+
filesLoaded.includes(x.id) ? React.createElement(DoneIcon, { sx: { fill: '#06d6a0' } }) : React.createElement(CircularProgress, { size: 22, sx: { color: 'black' } }),
|
|
164
|
+
React.createElement(PictureAsPdf, { color: 'error' }),
|
|
165
|
+
React.createElement(Typography, { fontWeight: 600 }, x.name))),
|
|
166
|
+
React.createElement(Box, null, filesLoaded.includes(x.id) && (React.createElement(Button, { variant: 'contained', size: 'small', sx: { textTransform: 'none', backgroundColor: '#d1495b', '&:hover': { backgroundColor: '#c1121f' } }, onClick: (e) => deleteFile(e, x.id), startIcon: React.createElement(Delete, null) }, "Remover"))))))))),
|
|
167
|
+
errorMsg && (React.createElement(React.Fragment, null,
|
|
168
|
+
React.createElement(Typography, { variant: 'caption', color: '#e53935', fontWeight: 600, fontSize: 14, paddingTop: 2 }, errorMsg),
|
|
169
|
+
React.createElement("br", null))),
|
|
170
|
+
get(context === null || context === void 0 ? void 0 : context.errors, name) && (React.createElement(Typography, { variant: 'caption', color: '#e53935', fontWeight: 600, fontSize: 14 }, "* O campo de arquivo \u00E9 obrigat\u00F3rio")))));
|
|
171
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { Grid, Stack } from '@mui/material';
|
|
13
|
+
import InputLabel from '@mui/material/InputLabel';
|
|
14
|
+
import React from 'react';
|
|
15
|
+
import Switch from '../switch/Switch';
|
|
16
|
+
import { SwitchWatch } from '../switch/ToggleVisibility';
|
|
17
|
+
import { Input } from './Input';
|
|
18
|
+
export default function FileUpload(_a) {
|
|
19
|
+
var { name, required = false, title, defaultChecked = false, xs = 12, unregisterNameList, sm, md } = _a, props = __rest(_a, ["name", "required", "title", "defaultChecked", "xs", "unregisterNameList", "sm", "md"]);
|
|
20
|
+
const switchName = `${name}-switch`;
|
|
21
|
+
return (React.createElement(Grid, Object.assign({ item: true }, { xs, sm, md }),
|
|
22
|
+
title && (React.createElement(InputLabel, { required: required, sx: { textTransform: 'capitalize' } }, title)),
|
|
23
|
+
React.createElement(Stack, { direction: 'row' },
|
|
24
|
+
React.createElement(Switch, { name: switchName, defaultChecked: defaultChecked }),
|
|
25
|
+
React.createElement(SwitchWatch, { switchId: switchName, unregisterNameList: unregisterNameList },
|
|
26
|
+
React.createElement(Input, { name: 'ddd', type: 'input' })))));
|
|
27
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Autocomplete, Grid, TextField } from '@mui/material';
|
|
2
|
+
import InputLabel from '@mui/material/InputLabel';
|
|
3
|
+
import get from 'lodash.get';
|
|
4
|
+
import React, { useCallback, useContext, useState } from 'react';
|
|
5
|
+
import { useQuery } from 'react-query';
|
|
6
|
+
import { AuthContext } from '../../../context/auth';
|
|
7
|
+
import { FormContext } from '../../../context/form';
|
|
8
|
+
export default function AutoComplete({ name, required = false, title, customPlaceholder, url, xs = 12, sm, md, dataPath = '', }) {
|
|
9
|
+
const context = useContext(FormContext);
|
|
10
|
+
const { user } = useContext(AuthContext);
|
|
11
|
+
const [options, setOptions] = useState([]);
|
|
12
|
+
const { isLoading, data, error } = useQuery(`autocomplete-${name}`, () => fetch(url, {
|
|
13
|
+
headers: {
|
|
14
|
+
Authorization: `Bearer ${user ? user.token : ''}`,
|
|
15
|
+
},
|
|
16
|
+
}).then((x) => x.json().then((list) => setOptions(getData(list)))));
|
|
17
|
+
// transformar isso em um component ou utils
|
|
18
|
+
const getData = useCallback((dt) => {
|
|
19
|
+
if (Array.isArray(dt))
|
|
20
|
+
return dt;
|
|
21
|
+
if (typeof dt === 'object')
|
|
22
|
+
return get(dt, dataPath);
|
|
23
|
+
}, []);
|
|
24
|
+
const onSelect = useCallback((e, value) => {
|
|
25
|
+
context === null || context === void 0 ? void 0 : context.formSetValue(name, value ? value.id : '');
|
|
26
|
+
context === null || context === void 0 ? void 0 : context.formTrigger(name);
|
|
27
|
+
}, [context, name]);
|
|
28
|
+
return (React.createElement(Grid, Object.assign({ item: true }, { xs, sm, md }),
|
|
29
|
+
title && React.createElement(InputLabel, { required: required }, title),
|
|
30
|
+
React.createElement("input", Object.assign({ type: 'text' }, context === null || context === void 0 ? void 0 : context.formRegister(name, {
|
|
31
|
+
validate: (v, f) => {
|
|
32
|
+
if (v.length <= 0 && required)
|
|
33
|
+
return 'Este campo é obrigatório';
|
|
34
|
+
},
|
|
35
|
+
}), { hidden: true })),
|
|
36
|
+
React.createElement(Autocomplete, { options: options, isOptionEqualToValue: (option, value) => option.id === value.id, onChange: onSelect, renderInput: (params) => {
|
|
37
|
+
var _a;
|
|
38
|
+
return (React.createElement(TextField, Object.assign({}, params, { placeholder: customPlaceholder, size: 'small', error: get(context === null || context === void 0 ? void 0 : context.errors, name) ? true : false, helperText: (_a = get(context === null || context === void 0 ? void 0 : context.errors, name)) === null || _a === void 0 ? void 0 : _a.message })));
|
|
39
|
+
} })));
|
|
40
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { Autocomplete, Grid, InputLabel, TextField } from '@mui/material';
|
|
2
|
+
import get from 'lodash.get';
|
|
3
|
+
import React, { useContext, useEffect, useState } from 'react';
|
|
4
|
+
import { AuthContext } from '../../../context/auth';
|
|
5
|
+
import { FormContext } from '../../../context/form';
|
|
6
|
+
let useDefault = true;
|
|
7
|
+
export default function FetchAutoComplete({ name, url, title, customLoadingText, shouldRefetch = true, required = false, defaultValue, route = '', onChange = () => { }, xs = 12, sm, watchValue, md, }) {
|
|
8
|
+
const context = useContext(FormContext);
|
|
9
|
+
const [loading, setLoading] = useState(true);
|
|
10
|
+
const [list, setList] = useState([]);
|
|
11
|
+
const [loadingText, setLoadingText] = useState('Carregando...');
|
|
12
|
+
const [dValue, setDValue] = useState(null);
|
|
13
|
+
const [value, setValue] = useState(null);
|
|
14
|
+
const { user } = useContext(AuthContext);
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
if (defaultValue) {
|
|
17
|
+
fetch(url, {
|
|
18
|
+
method: 'GET',
|
|
19
|
+
headers: {
|
|
20
|
+
Authorization: `Bearer ${user === null || user === void 0 ? void 0 : user.token}`,
|
|
21
|
+
},
|
|
22
|
+
}).then((res) => {
|
|
23
|
+
if (res.ok) {
|
|
24
|
+
console.log('llll');
|
|
25
|
+
res.json().then((j) => {
|
|
26
|
+
let value = get(j, route, j).filter((x) => x.id === defaultValue);
|
|
27
|
+
if (value.length > 0) {
|
|
28
|
+
setList(get(j, route, j));
|
|
29
|
+
setLoading(false);
|
|
30
|
+
context.formSetValue(name, defaultValue);
|
|
31
|
+
setDValue(value[0]);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
setLoadingText('Erro ao carregar dados. Valor inválido');
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
setLoadingText('Erro ao carregar dados');
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}, []);
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
if (watchValue && useDefault) {
|
|
46
|
+
setValue(watchValue);
|
|
47
|
+
context.formSetValue(name, watchValue.id);
|
|
48
|
+
onChange(watchValue.id);
|
|
49
|
+
}
|
|
50
|
+
}, [watchValue]);
|
|
51
|
+
function onFocus() {
|
|
52
|
+
if ((defaultValue || !shouldRefetch) && list.length > 0)
|
|
53
|
+
return;
|
|
54
|
+
setLoading(true);
|
|
55
|
+
setList([]);
|
|
56
|
+
customLoadingText && setLoadingText(customLoadingText);
|
|
57
|
+
fetch(url, {
|
|
58
|
+
method: 'GET',
|
|
59
|
+
headers: {
|
|
60
|
+
Authorization: `Bearer ${user === null || user === void 0 ? void 0 : user.token}`,
|
|
61
|
+
},
|
|
62
|
+
}).then((res) => {
|
|
63
|
+
if (res.ok) {
|
|
64
|
+
res.json().then((j) => {
|
|
65
|
+
setList(get(j, route, j));
|
|
66
|
+
setLoading(false);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
setLoadingText('Erro ao carregar dados');
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
function handleAutoCompleteChange(value) {
|
|
75
|
+
useDefault = false;
|
|
76
|
+
if (value) {
|
|
77
|
+
setValue(value);
|
|
78
|
+
context.formSetValue(name, value.id);
|
|
79
|
+
onChange(value.id);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
setValue(null);
|
|
83
|
+
context.formSetValue(name, '');
|
|
84
|
+
onChange(undefined);
|
|
85
|
+
}
|
|
86
|
+
if (defaultValue && list.length <= 0 && !dValue)
|
|
87
|
+
return (React.createElement(Grid, Object.assign({ item: true }, { xs, sm, md }),
|
|
88
|
+
React.createElement(TextField, { size: 'small', fullWidth: true, placeholder: loadingText, disabled: true })));
|
|
89
|
+
return (React.createElement(Grid, Object.assign({ item: true }, { xs, sm, md }),
|
|
90
|
+
title && React.createElement(InputLabel, { required: required }, title),
|
|
91
|
+
React.createElement("input", Object.assign({ type: 'text' }, context === null || context === void 0 ? void 0 : context.formRegister(name, {
|
|
92
|
+
validate: (v, f) => {
|
|
93
|
+
if (v.length <= 0 && required)
|
|
94
|
+
return 'Este campo é obrigatório';
|
|
95
|
+
},
|
|
96
|
+
}), { hidden: true })),
|
|
97
|
+
React.createElement(Autocomplete, { value: value, loading: loading, loadingText: loadingText, options: list, defaultValue: dValue, getOptionDisabled: (option) => { var _a; return (_a = option === null || option === void 0 ? void 0 : option.disabled) !== null && _a !== void 0 ? _a : false; }, isOptionEqualToValue: (op, value) => op.id === value.id, onChange: (e, v) => handleAutoCompleteChange(v), renderInput: (params) => {
|
|
98
|
+
var _a;
|
|
99
|
+
return (React.createElement(TextField, Object.assign({}, params, { size: 'small', fullWidth: true, placeholder: title, onFocus: onFocus, error: get(context === null || context === void 0 ? void 0 : context.errors, name) ? true : false, helperText: (_a = get(context === null || context === void 0 ? void 0 : context.errors, name)) === null || _a === void 0 ? void 0 : _a.message })));
|
|
100
|
+
}, sx: {
|
|
101
|
+
bgcolor: 'white',
|
|
102
|
+
}, size: 'small', fullWidth: true })));
|
|
103
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Autocomplete, Grid, InputLabel, TextField } from '@mui/material';
|
|
2
|
+
import get from 'lodash.get';
|
|
3
|
+
import React, { useContext, useEffect, useState } from 'react';
|
|
4
|
+
import { FormContext } from '../../../context/form';
|
|
5
|
+
let useDefault = true;
|
|
6
|
+
export function FixedAutoComplete({ name, title, required = false, list, defaultValue, onChange = () => { }, xs = 12, sm, watchValue, md, }) {
|
|
7
|
+
const context = useContext(FormContext);
|
|
8
|
+
const [value, setValue] = useState(null);
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
if (defaultValue)
|
|
11
|
+
context === null || context === void 0 ? void 0 : context.formSetValue(name, defaultValue.id);
|
|
12
|
+
}, []);
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
if (watchValue && useDefault) {
|
|
15
|
+
setValue(watchValue);
|
|
16
|
+
context.formSetValue(name, watchValue.id);
|
|
17
|
+
onChange(watchValue.id);
|
|
18
|
+
}
|
|
19
|
+
}, [watchValue]);
|
|
20
|
+
function handleAutoCompleteChange(value) {
|
|
21
|
+
useDefault = false;
|
|
22
|
+
if (value) {
|
|
23
|
+
setValue(value);
|
|
24
|
+
context.formSetValue(name, value.id);
|
|
25
|
+
onChange(value.id);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
setValue(null);
|
|
29
|
+
context.formSetValue(name, '');
|
|
30
|
+
onChange(undefined);
|
|
31
|
+
}
|
|
32
|
+
return (React.createElement(Grid, Object.assign({ item: true }, { xs, sm, md }),
|
|
33
|
+
title && React.createElement(InputLabel, { required: required }, title),
|
|
34
|
+
React.createElement("input", Object.assign({ type: 'text' }, context === null || context === void 0 ? void 0 : context.formRegister(name, {
|
|
35
|
+
validate: (v, f) => {
|
|
36
|
+
if (v.length <= 0 && required)
|
|
37
|
+
return 'Este campo é obrigatório';
|
|
38
|
+
},
|
|
39
|
+
}), { hidden: true })),
|
|
40
|
+
React.createElement(Autocomplete, { value: value, options: list, defaultValue: defaultValue, getOptionLabel: (option) => (option.label ? option.label.toString() : 'Não Encontrado'), isOptionEqualToValue: (op, value) => op.id === value.id, onChange: (e, v) => handleAutoCompleteChange(v), renderInput: (params) => {
|
|
41
|
+
var _a;
|
|
42
|
+
return (React.createElement(TextField, Object.assign({}, params, { size: 'small', fullWidth: true, placeholder: title, error: get(context === null || context === void 0 ? void 0 : context.errors, name) ? true : false, helperText: (_a = get(context === null || context === void 0 ? void 0 : context.errors, name)) === null || _a === void 0 ? void 0 : _a.message })));
|
|
43
|
+
}, size: 'small', sx: {
|
|
44
|
+
bgcolor: 'white',
|
|
45
|
+
}, fullWidth: true })));
|
|
46
|
+
}
|
|
@@ -1,27 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
1
|
var __rest = (this && this.__rest) || function (s, e) {
|
|
26
2
|
var t = {};
|
|
27
3
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
@@ -33,20 +9,15 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
33
9
|
}
|
|
34
10
|
return t;
|
|
35
11
|
};
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const lodash_get_1 = __importDefault(require("lodash.get"));
|
|
43
|
-
const react_1 = __importStar(require("react"));
|
|
44
|
-
const MaskInput_1 = __importDefault(require("./MaskInput"));
|
|
45
|
-
const form_1 = require("../../../context/form");
|
|
46
|
-
function Input(_a) {
|
|
12
|
+
import { Grid, InputLabel, TextField } from '@mui/material';
|
|
13
|
+
import get from 'lodash.get';
|
|
14
|
+
import React, { useContext, useEffect } from 'react';
|
|
15
|
+
import MaskInput from './MaskInput';
|
|
16
|
+
import { FormContext } from '../../../context/form';
|
|
17
|
+
export function Input(_a) {
|
|
47
18
|
var { type = 'input', numberMask = '000000000000000', xs = 12, sm, inputMinLength = 1, inputMaxLength = 255, defaultValue = '', md, watchValue = '' } = _a, props = __rest(_a, ["type", "numberMask", "xs", "sm", "inputMinLength", "inputMaxLength", "defaultValue", "md", "watchValue"]);
|
|
48
|
-
const context =
|
|
49
|
-
|
|
19
|
+
const context = useContext(FormContext);
|
|
20
|
+
useEffect(() => {
|
|
50
21
|
context.formSetValue(props.name, watchValue);
|
|
51
22
|
}, [watchValue]);
|
|
52
23
|
const chooseInput = () => {
|
|
@@ -56,7 +27,7 @@ function Input(_a) {
|
|
|
56
27
|
placeholder: props.customPlaceholder ? props.customPlaceholder : props.title,
|
|
57
28
|
};
|
|
58
29
|
const name = props.name;
|
|
59
|
-
const errorData = (
|
|
30
|
+
const errorData = get(context === null || context === void 0 ? void 0 : context.errors, props.name);
|
|
60
31
|
const helperText = errorData === null || errorData === void 0 ? void 0 : errorData.message;
|
|
61
32
|
const error = errorData ? true : false;
|
|
62
33
|
const formConfig = Object.assign(Object.assign(Object.assign(Object.assign({}, context === null || context === void 0 ? void 0 : context.formRegister(name, {
|
|
@@ -114,30 +85,30 @@ function Input(_a) {
|
|
|
114
85
|
switch (type) {
|
|
115
86
|
case 'input':
|
|
116
87
|
case 'email':
|
|
117
|
-
return
|
|
88
|
+
return React.createElement(TextField, Object.assign({}, formConfig, { defaultValue: defaultValue }));
|
|
118
89
|
case 'password':
|
|
119
|
-
return
|
|
90
|
+
return React.createElement(TextField, Object.assign({}, formConfig, { type: 'password' }));
|
|
120
91
|
case 'number':
|
|
121
|
-
return (
|
|
92
|
+
return (React.createElement(MaskInput, { formConfig: formConfig, defaultValue: defaultValue, maskProps: {
|
|
122
93
|
mask: numberMask,
|
|
123
94
|
}, watchValue: watchValue }));
|
|
124
95
|
case 'cep':
|
|
125
|
-
return (
|
|
96
|
+
return (React.createElement(MaskInput, { formConfig: formConfig, defaultValue: defaultValue, maskProps: {
|
|
126
97
|
mask: '00000-000',
|
|
127
98
|
}, watchValue: watchValue }));
|
|
128
99
|
case 'phone':
|
|
129
|
-
return (
|
|
100
|
+
return (React.createElement(MaskInput, { formConfig: formConfig, defaultValue: defaultValue, maskProps: {
|
|
130
101
|
mask: '(00) [#]0000-0000',
|
|
131
102
|
definitions: {
|
|
132
103
|
'#': /^9$/,
|
|
133
104
|
},
|
|
134
105
|
}, watchValue: watchValue }));
|
|
135
106
|
case 'sei':
|
|
136
|
-
return (
|
|
107
|
+
return (React.createElement(MaskInput, { formConfig: formConfig, defaultValue: defaultValue, maskProps: {
|
|
137
108
|
mask: '00000-00000000/0000-00',
|
|
138
109
|
}, watchValue: watchValue }));
|
|
139
110
|
case 'cpf_cnpj':
|
|
140
|
-
return (
|
|
111
|
+
return (React.createElement(MaskInput, { formConfig: formConfig, defaultValue: defaultValue, maskProps: {
|
|
141
112
|
mask: '000.000.000-00[0]',
|
|
142
113
|
}, onMask: (value, setMask) => {
|
|
143
114
|
if (value.length > 14)
|
|
@@ -146,22 +117,21 @@ function Input(_a) {
|
|
|
146
117
|
setMask('000.000.000-00[0]');
|
|
147
118
|
}, watchValue: watchValue }));
|
|
148
119
|
case 'cpf':
|
|
149
|
-
return (
|
|
120
|
+
return (React.createElement(MaskInput, { formConfig: formConfig, defaultValue: defaultValue, maskProps: {
|
|
150
121
|
mask: '000.000.000-00',
|
|
151
122
|
}, watchValue: watchValue }));
|
|
152
123
|
case 'cnpj':
|
|
153
|
-
return (
|
|
124
|
+
return (React.createElement(MaskInput, { formConfig: formConfig, defaultValue: defaultValue, maskProps: {
|
|
154
125
|
mask: '00.000.000/0000-00',
|
|
155
126
|
}, watchValue: watchValue }));
|
|
156
127
|
case 'rg':
|
|
157
|
-
return (
|
|
128
|
+
return (React.createElement(MaskInput, { formConfig: formConfig, defaultValue: defaultValue, maskProps: {
|
|
158
129
|
mask: '00000[000000]',
|
|
159
130
|
}, watchValue: watchValue }));
|
|
160
131
|
}
|
|
161
132
|
};
|
|
162
|
-
return (
|
|
163
|
-
props.title && (
|
|
133
|
+
return (React.createElement(Grid, Object.assign({ item: true }, { xs, sm, md }),
|
|
134
|
+
props.title && (React.createElement(InputLabel, { htmlFor: 'campo', required: props.required }, props.title)),
|
|
164
135
|
chooseInput()));
|
|
165
136
|
}
|
|
166
|
-
|
|
167
|
-
exports.default = react_1.default.memo(Input);
|
|
137
|
+
export default React.memo(Input);
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { TextField } from '@mui/material';
|
|
13
|
+
import React, { useContext, useEffect, useRef, useState } from 'react';
|
|
14
|
+
import { IMaskInput } from 'react-imask';
|
|
15
|
+
import { FormContext } from '../../../context/form';
|
|
16
|
+
const TextMaskCustom = React.forwardRef(function TextMaskCustom(props, ref) {
|
|
17
|
+
const { onChange, maskProps, onMask, maskValue, setMaskValue, watchValue } = props, prop = __rest(props, ["onChange", "maskProps", "onMask", "maskValue", "setMaskValue", "watchValue"]);
|
|
18
|
+
const [mask, setMask] = useState(maskProps.mask);
|
|
19
|
+
delete prop.value;
|
|
20
|
+
const myRef = useRef(null);
|
|
21
|
+
const [myValue, setMyValue] = useState('');
|
|
22
|
+
const context = useContext(FormContext);
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
if (watchValue) {
|
|
25
|
+
setMyValue(watchValue);
|
|
26
|
+
}
|
|
27
|
+
}, [watchValue]);
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
context.formSetValue(prop.name, myRef.current.element.value);
|
|
30
|
+
}, [myValue]);
|
|
31
|
+
delete prop.watchValue;
|
|
32
|
+
return (React.createElement(IMaskInput, Object.assign({}, prop, maskProps, { mask: mask, value: myValue, ref: myRef, inputRef: ref, onChange: (e) => { }, onAccept: (value, mask) => {
|
|
33
|
+
setMyValue(value);
|
|
34
|
+
mask.updateValue();
|
|
35
|
+
if (!onMask)
|
|
36
|
+
return;
|
|
37
|
+
onMask(value, setMask);
|
|
38
|
+
} })));
|
|
39
|
+
});
|
|
40
|
+
export default function MaskInput(props) {
|
|
41
|
+
const context = useContext(FormContext);
|
|
42
|
+
const [maskValue, setMaskValue] = useState('');
|
|
43
|
+
return (React.createElement(React.Fragment, null,
|
|
44
|
+
React.createElement(TextField, Object.assign({}, props.formConfig, { onInput: (e) => {
|
|
45
|
+
const name = props.formConfig.name;
|
|
46
|
+
const value = e.target.value;
|
|
47
|
+
context.formSetValue(name, value);
|
|
48
|
+
}, InputProps: {
|
|
49
|
+
inputComponent: TextMaskCustom,
|
|
50
|
+
inputProps: { maskProps: props.maskProps, onMask: props.onMask, maskValue, setMaskValue, watchValue: props.watchValue },
|
|
51
|
+
}, disabled: props.disabled, fullWidth: true }))));
|
|
52
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { Grid, TextField } from '@mui/material';
|
|
13
|
+
import InputLabel from '@mui/material/InputLabel';
|
|
14
|
+
import get from 'lodash.get';
|
|
15
|
+
import React, { useContext, useEffect } from 'react';
|
|
16
|
+
import { FormContext } from '../../../context/form';
|
|
17
|
+
export default function MultInput(_a) {
|
|
18
|
+
var _b;
|
|
19
|
+
var { name, required = false, title, customPlaceholder, defaultValue = '', xs = 12, sm, watchValue = '', inputMinLength = 3, inputMaxLength = 255, md } = _a, props = __rest(_a, ["name", "required", "title", "customPlaceholder", "defaultValue", "xs", "sm", "watchValue", "inputMinLength", "inputMaxLength", "md"]);
|
|
20
|
+
const context = useContext(FormContext);
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
context.formSetValue(name, watchValue);
|
|
23
|
+
}, [watchValue]);
|
|
24
|
+
return (React.createElement(Grid, Object.assign({ item: true }, { xs, sm, md }),
|
|
25
|
+
title && (React.createElement(InputLabel, { required: required, sx: { textTransform: 'capitalize' } }, title)),
|
|
26
|
+
React.createElement(TextField, Object.assign({ multiline: true, fullWidth: true, minRows: 3, defaultValue: defaultValue }, context.formRegister(name, {
|
|
27
|
+
validate: (v, f) => {
|
|
28
|
+
if (required && v.length <= 0)
|
|
29
|
+
return 'Este campo é obrigatório';
|
|
30
|
+
if (v.length > inputMaxLength)
|
|
31
|
+
return `Limite máximo de ${inputMaxLength} caracteres`;
|
|
32
|
+
if (v.length < inputMinLength && required)
|
|
33
|
+
return `Limite mínimo de ${inputMinLength} caracteres`;
|
|
34
|
+
},
|
|
35
|
+
}), { error: get(context.errors, name) ? true : false, helperText: (_b = get(context.errors, name)) === null || _b === void 0 ? void 0 : _b.message, sx: {
|
|
36
|
+
bgcolor: 'white',
|
|
37
|
+
}, placeholder: customPlaceholder ? customPlaceholder : title }))));
|
|
38
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Box, Checkbox, Grid, Stack, TextField } from '@mui/material';
|
|
2
|
+
import get from 'lodash.get';
|
|
3
|
+
import React, { useContext, useEffect } from 'react';
|
|
4
|
+
import { FormContext } from '../../../context/form';
|
|
5
|
+
export default function SSPOtherCheckBox({ name, required = false, xs = 12, sm, md }) {
|
|
6
|
+
var _a;
|
|
7
|
+
const context = useContext(FormContext);
|
|
8
|
+
const checkName = `switch-${name}`;
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
const checkValue = context.formWatch(checkName);
|
|
11
|
+
if (!checkValue)
|
|
12
|
+
context.formSetValue(name, undefined);
|
|
13
|
+
}, [context]);
|
|
14
|
+
return (React.createElement(Grid, Object.assign({ item: true }, { xs, sm, md }),
|
|
15
|
+
React.createElement(Stack, { direction: 'row' },
|
|
16
|
+
React.createElement(Box, null,
|
|
17
|
+
React.createElement(Checkbox, Object.assign({ size: 'small' }, context.formRegister(checkName), { sx: { paddingLeft: 0, margin: 0 } }))),
|
|
18
|
+
context.formWatch(checkName) ? (React.createElement(TextField, Object.assign({ size: 'small' }, context.formRegister(name, {
|
|
19
|
+
validate: (v, f) => {
|
|
20
|
+
const value = context.formWatch(checkName);
|
|
21
|
+
if (value === true) {
|
|
22
|
+
if (!v || (v.length <= 0 && required))
|
|
23
|
+
return 'Este campo não pode ser vazio';
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
}), { required: true, error: get(context.errors, name) ? true : false, helperText: (_a = get(context.errors, name)) === null || _a === void 0 ? void 0 : _a.message, placeholder: 'Outro' }))) : (React.createElement(TextField, { size: 'small', disabled: true, placeholder: 'Outro' })))));
|
|
27
|
+
}
|