@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,105 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
11
|
+
var t = {};
|
|
12
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
13
|
+
t[p] = s[p];
|
|
14
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
15
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
16
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
17
|
+
t[p[i]] = s[p[i]];
|
|
18
|
+
}
|
|
19
|
+
return t;
|
|
20
|
+
};
|
|
21
|
+
import KeyboardArrowLeft from '@mui/icons-material/KeyboardArrowLeft';
|
|
22
|
+
import KeyboardArrowRight from '@mui/icons-material/KeyboardArrowRight';
|
|
23
|
+
import SaveIcon from '@mui/icons-material/Save';
|
|
24
|
+
import { LoadingButton } from '@mui/lab';
|
|
25
|
+
import { Box, Button, MobileStepper, Stack, useMediaQuery, useTheme } from '@mui/material';
|
|
26
|
+
import React, { useContext, useRef, useState } from 'react';
|
|
27
|
+
import { toast } from 'react-toastify';
|
|
28
|
+
import { FormContext } from '../../../context/form';
|
|
29
|
+
const getKeys = (values, id) => {
|
|
30
|
+
if (!values || Object.keys(values).length <= 0)
|
|
31
|
+
return [];
|
|
32
|
+
if (!values[id])
|
|
33
|
+
return [];
|
|
34
|
+
let keys = Object.keys(values[id]).map((x) => `${id}.${x}`);
|
|
35
|
+
if (values.files)
|
|
36
|
+
keys = [...keys, ...Object.keys(values.files).map((x) => `files.${x}`)];
|
|
37
|
+
return keys;
|
|
38
|
+
};
|
|
39
|
+
function sleep(ms) {
|
|
40
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
41
|
+
}
|
|
42
|
+
export function Stepper(_a) {
|
|
43
|
+
var { debugLog = false, test = false, testConfig = {}, customMarginBottom = 10 } = _a, props = __rest(_a, ["debugLog", "test", "testConfig", "customMarginBottom"]);
|
|
44
|
+
props.children = Array.isArray(props.children) ? props.children.filter((x, id) => x) : props.children;
|
|
45
|
+
const length = Array.isArray(props.children) ? props.children.length : 1;
|
|
46
|
+
const context = useContext(FormContext);
|
|
47
|
+
// next button ref
|
|
48
|
+
const nRef = useRef(null);
|
|
49
|
+
const theme = useTheme();
|
|
50
|
+
const [activeStep, setActiveStep] = useState(0);
|
|
51
|
+
const blocks = Array.isArray(props.children) ? props.children : [props.children];
|
|
52
|
+
const stepperBlocks = blocks.map((x, idx) => {
|
|
53
|
+
return React.cloneElement(x, Object.assign(Object.assign({}, x.props), { prefix: idx }));
|
|
54
|
+
});
|
|
55
|
+
const maxSteps = length;
|
|
56
|
+
const handleNext = () => __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
if (debugLog)
|
|
58
|
+
console.log(context.formGetValues());
|
|
59
|
+
// console.log('valores conferidos', getKeys(context.formGetValues(), activeStep), context.formGetValues(getKeys(context.formGetValues(), activeStep)))
|
|
60
|
+
const result = yield context.formTrigger(getKeys(context.formGetValues(), activeStep));
|
|
61
|
+
if (!result) {
|
|
62
|
+
toast('Formulário incompleto! Verifique os campos marcados e tente novamente.', { type: 'warning', theme: 'light' });
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
setActiveStep((prevActiveStep) => prevActiveStep + 1);
|
|
66
|
+
});
|
|
67
|
+
const nextCheck = (e) => __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
const result = yield context.formTrigger(getKeys(context.formGetValues(), activeStep));
|
|
69
|
+
if (!result) {
|
|
70
|
+
e.preventDefault();
|
|
71
|
+
toast('Formulário incompleto! Verifique os campos marcados e tente novamente.', { type: 'warning', theme: 'light' });
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
const handleBack = () => {
|
|
76
|
+
setActiveStep((prevActiveStep) => prevActiveStep - 1);
|
|
77
|
+
};
|
|
78
|
+
const preencher = () => {
|
|
79
|
+
Object.keys(testConfig).forEach((id, idx) => {
|
|
80
|
+
const obj = testConfig[Number(id)];
|
|
81
|
+
Object.keys(obj).forEach((x) => {
|
|
82
|
+
context.formUnregister(`${id}.${x}`);
|
|
83
|
+
context.formSetValue(`${id}.${x}`, obj[x]);
|
|
84
|
+
});
|
|
85
|
+
if (idx < Object.keys(testConfig).length - 1) {
|
|
86
|
+
sleep(100).then(() => {
|
|
87
|
+
var _a;
|
|
88
|
+
const bt = nRef.current;
|
|
89
|
+
(_a = nRef.current) === null || _a === void 0 ? void 0 : _a.click();
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
return (React.createElement(Box, null,
|
|
95
|
+
test && (React.createElement(Stack, { direction: 'row', justifyContent: 'end' },
|
|
96
|
+
React.createElement(Button, { variant: 'contained', color: 'error', onClick: preencher }, "EXCLUIR BANCO PRODU\u00C7\u00C3O"))),
|
|
97
|
+
React.createElement(Stack, { sx: { padding: 2, marginBottom: customMarginBottom } },
|
|
98
|
+
React.createElement(Box, null, stepperBlocks.map((b, index) => (React.createElement(Box, { key: 'formsB' + index, hidden: !(activeStep === index) }, stepperBlocks[index])))),
|
|
99
|
+
React.createElement(MobileStepper, { variant: 'text', steps: maxSteps,
|
|
100
|
+
// position='bottom'
|
|
101
|
+
position: useMediaQuery(theme.breakpoints.only('xs')) ? 'bottom' : 'static', activeStep: activeStep, sx: { paddingTop: 2, paddingBottom: 4, paddingX: 0 }, backButton: React.createElement(Button, { variant: 'contained', startIcon: React.createElement(KeyboardArrowLeft, null), onClick: handleBack, disabled: activeStep === 0, sx: { textTransform: 'none' } }, "Voltar"), nextButton: activeStep < maxSteps - 1 ? (React.createElement(Button, { variant: 'contained', endIcon: React.createElement(KeyboardArrowRight, null), onClick: handleNext, sx: { textTransform: 'none' }, ref: nRef }, "Pr\u00F3ximo")) : (React.createElement(Box, null,
|
|
102
|
+
React.createElement(LoadingButton, { variant: 'contained', type: 'submit', loading: context.submiting, loadingPosition: 'start', startIcon: React.createElement(SaveIcon, null), onClick: (e) => nextCheck(e), sx: { textTransform: 'none', backgroundColor: '#22C55E', '&:hover': { backgroundColor: '#48cf7a' } } },
|
|
103
|
+
React.createElement("span", null, "Salvar")))) }))));
|
|
104
|
+
}
|
|
105
|
+
export default React.memo(Stepper);
|
|
@@ -0,0 +1,67 @@
|
|
|
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 ContentPasteOutlinedIcon from '@mui/icons-material/ContentPasteOutlined';
|
|
13
|
+
import { Box, Grid, Stack } from '@mui/material';
|
|
14
|
+
import Typography from '@mui/material/Typography';
|
|
15
|
+
import React, { useContext } from 'react';
|
|
16
|
+
import Switch from '../switch/Switch';
|
|
17
|
+
import { FormContext } from '../../../context/form';
|
|
18
|
+
function childrenTree(component, prefix, idx) {
|
|
19
|
+
if (!component.props)
|
|
20
|
+
return component;
|
|
21
|
+
const children = component.props.children;
|
|
22
|
+
if (!children)
|
|
23
|
+
return React.cloneElement(component, Object.assign(Object.assign({}, component.props), { name: `${prefix}.${component.props.name}`, key: component.props.name ? `${prefix}.${component.props.name}` : `noListing-${idx}-${prefix}-${component.props.name}` }));
|
|
24
|
+
let newChildren;
|
|
25
|
+
if (Array.isArray(children)) {
|
|
26
|
+
let c = [];
|
|
27
|
+
children.forEach((x, cIdx) => {
|
|
28
|
+
c.push(childrenTree(x, prefix, idx + (cIdx + 1)));
|
|
29
|
+
});
|
|
30
|
+
newChildren = c;
|
|
31
|
+
}
|
|
32
|
+
//
|
|
33
|
+
else {
|
|
34
|
+
newChildren = childrenTree(children, prefix, idx + 1);
|
|
35
|
+
}
|
|
36
|
+
const newComponent = React.cloneElement(component, Object.assign(Object.assign({}, component.props), { children: newChildren, name: `${prefix}.${component.props.name}`, key: component.props.name ? `${prefix}.${component.props.name}` : `noListing-${idx}-${prefix}-${component.props.name}` }));
|
|
37
|
+
return newComponent;
|
|
38
|
+
}
|
|
39
|
+
export function StepperBlock(_a) {
|
|
40
|
+
var { optional = false, title, prefix = 0, optionalMessage, defaultChecked } = _a, props = __rest(_a, ["optional", "title", "prefix", "optionalMessage", "defaultChecked"]);
|
|
41
|
+
const context = useContext(FormContext);
|
|
42
|
+
const switchName = `switch-${prefix}`;
|
|
43
|
+
const fields = Array.isArray(props.children) ? props.children : [props.children];
|
|
44
|
+
const cloneChildren = fields.map((x, index) => {
|
|
45
|
+
return x && childrenTree(x, prefix, index);
|
|
46
|
+
});
|
|
47
|
+
return (React.createElement(Box, null,
|
|
48
|
+
React.createElement(Grid, { item: true, xs: 12 },
|
|
49
|
+
React.createElement(Stack, { direction: 'row', justifyContent: 'space-between' },
|
|
50
|
+
React.createElement(Stack, { direction: 'row', spacing: 2 },
|
|
51
|
+
React.createElement(Box, { sx: { marginTop: 0.6 } },
|
|
52
|
+
React.createElement(Stack, { sx: { backgroundColor: '#E6F8EB', borderRadius: '100%', height: '35px', width: '35px' }, justifyContent: 'center', alignItems: 'center' },
|
|
53
|
+
React.createElement(ContentPasteOutlinedIcon, { sx: { height: '18px', fill: '#01BA35' } }))),
|
|
54
|
+
React.createElement(Typography, { variant: 'h6', fontWeight: 600, fontSize: 28, fontFamily: 'Inter', sx: {
|
|
55
|
+
color: '#1E293B',
|
|
56
|
+
paddingBottom: 4,
|
|
57
|
+
} }, title)),
|
|
58
|
+
React.createElement(Box, { hidden: !optional },
|
|
59
|
+
React.createElement(Switch, { name: switchName, defaultChecked: defaultChecked, overrideNo: props.overrideSwitchNo, overrideYes: props.overrideSwitchYes })))),
|
|
60
|
+
React.createElement(Stack, { spacing: 2 }, !optional ? (React.createElement(Grid, { container: true, spacing: 1 }, cloneChildren)) : !context.formWatch(switchName) ? (React.createElement(Stack, { justifyContent: 'center', alignItems: 'center' },
|
|
61
|
+
React.createElement(Typography, { fontFamily: 'Inter', fontSize: 22, paddingY: 8, textAlign: 'center' }, optionalMessage ? (optionalMessage) : (React.createElement(React.Fragment, null,
|
|
62
|
+
React.createElement("b", null, title),
|
|
63
|
+
" \u00E9 opcional. ",
|
|
64
|
+
React.createElement("br", null),
|
|
65
|
+
"Marque a op\u00E7\u00E3o acima caso haja necessidade."))))) : (React.createElement(Grid, { container: true, spacing: 1 }, cloneChildren)))));
|
|
66
|
+
}
|
|
67
|
+
export default React.memo(StepperBlock);
|
|
@@ -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 { FormControlLabel, InputLabel, Stack, Switch as MUISwitch, Typography } from '@mui/material';
|
|
13
|
+
import React, { useContext, useEffect, useMemo } from 'react';
|
|
14
|
+
import { FormContext } from '../../../context/form';
|
|
15
|
+
export function Switch(_a) {
|
|
16
|
+
var { defaultChecked = false } = _a, props = __rest(_a, ["defaultChecked"]);
|
|
17
|
+
const context = useContext(FormContext);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
context === null || context === void 0 ? void 0 : context.formSetValue(props.name, defaultChecked);
|
|
20
|
+
}, []);
|
|
21
|
+
const yesMessage = useMemo(() => props.overrideYes || 'Sim', [props.overrideYes]);
|
|
22
|
+
const noMessage = useMemo(() => props.overrideNo || 'Não', [props.overrideNo]);
|
|
23
|
+
return (React.createElement(Stack, { sx: { alignItems: 'center', justifyContent: 'center' } },
|
|
24
|
+
props.title && React.createElement(InputLabel, null, props.title),
|
|
25
|
+
React.createElement(FormControlLabel, { control: React.createElement(MUISwitch, Object.assign({ defaultChecked: defaultChecked }, context === null || context === void 0 ? void 0 : context.formRegister(props.name))), label: React.createElement(Typography, { width: 25, sx: { userSelect: 'none', fontWeight: 600 } }, (context === null || context === void 0 ? void 0 : context.formWatch(props.name)) ? yesMessage : noMessage), sx: { paddingLeft: 1 } })));
|
|
26
|
+
}
|
|
27
|
+
export default React.memo(Switch);
|
|
@@ -0,0 +1,33 @@
|
|
|
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 React, { useContext, useEffect } from 'react';
|
|
13
|
+
import { FormContext } from '../../../context/form';
|
|
14
|
+
// Coloque esse componente dentro de um bloco que é retirado com o valor do input
|
|
15
|
+
export function ToggleVisibility(_a) {
|
|
16
|
+
var { invert = false, hasCheckValue = false } = _a, props = __rest(_a, ["invert", "hasCheckValue"]);
|
|
17
|
+
const context = useContext(FormContext);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
return () => {
|
|
20
|
+
if (hasCheckValue ? invert : context.formWatch(props.switchId) === invert) {
|
|
21
|
+
props.unregisterNameList.forEach((x) => context.formUnregister(x));
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}, [props.unregisterNameList]);
|
|
25
|
+
return React.createElement(React.Fragment, null);
|
|
26
|
+
}
|
|
27
|
+
export function SwitchWatch(_a) {
|
|
28
|
+
var { invert = false, checkValue } = _a, props = __rest(_a, ["invert", "checkValue"]);
|
|
29
|
+
const context = useContext(FormContext);
|
|
30
|
+
return (React.createElement(React.Fragment, null, (checkValue ? ((context === null || context === void 0 ? void 0 : context.formWatch(props.switchId)) === checkValue) !== invert : (context === null || context === void 0 ? void 0 : context.formWatch(props.switchId)) !== invert) && (React.createElement(React.Fragment, null,
|
|
31
|
+
React.createElement(ToggleVisibility, { switchId: props.switchId, unregisterNameList: props.unregisterNameList, hasCheckValue: !!checkValue, invert: checkValue ? ((context === null || context === void 0 ? void 0 : context.formWatch(props.switchId)) === checkValue) !== invert : invert }),
|
|
32
|
+
props.children))));
|
|
33
|
+
}
|