@ssplib/react-components 0.0.35 → 0.0.37
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/components/form/input/Input.d.ts +4 -2
- package/components/form/input/Input.js +9 -7
- package/components/form/input/MultInput.d.ts +3 -1
- package/components/form/input/MultInput.js +5 -1
- package/components/form/table/Table.js +4 -4
- package/components/navbar/NavBar.d.ts +1 -1
- package/components/navbar/NavBar.js +4 -3
- package/components/providers/FormProvider.d.ts +2 -1
- package/components/providers/FormProvider.js +2 -2
- package/components/providers/OAuthProvider.js +1 -1
- package/package.json +1 -1
- package/types/auth.d.ts +1 -0
- package/types/form.d.ts +63 -0
- package/types/form.js +31 -0
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
export declare function Input({ type, numberMask, xs, sm, md, ...props }: {
|
|
3
|
-
type: 'cnpj' | 'cpf' | 'input' | 'email' | 'cpf_cnpj' | 'phone' | 'input' | 'number' | 'rg';
|
|
2
|
+
export declare function Input({ type, numberMask, xs, sm, inputMinLength, inputMaxLength, md, ...props }: {
|
|
3
|
+
type: 'cnpj' | 'cpf' | 'input' | 'email' | 'cpf_cnpj' | 'phone' | 'input' | 'number' | 'rg' | 'password';
|
|
4
4
|
name: string;
|
|
5
5
|
title?: string;
|
|
6
6
|
required?: boolean;
|
|
7
7
|
numberMask?: string;
|
|
8
8
|
customPlaceholder?: string;
|
|
9
|
+
inputMinLength?: number;
|
|
10
|
+
inputMaxLength?: number;
|
|
9
11
|
xs?: number;
|
|
10
12
|
sm?: number;
|
|
11
13
|
md?: number;
|
|
@@ -44,7 +44,7 @@ const react_1 = __importStar(require("react"));
|
|
|
44
44
|
const MaskInput_1 = __importDefault(require("./MaskInput"));
|
|
45
45
|
const form_1 = require("../../../context/form");
|
|
46
46
|
function Input(_a) {
|
|
47
|
-
var { type = 'input', numberMask = '000000000000000', xs = 12, sm, md } = _a, props = __rest(_a, ["type", "numberMask", "xs", "sm", "md"]);
|
|
47
|
+
var { type = 'input', numberMask = '000000000000000', xs = 12, sm, inputMinLength = 3, inputMaxLength = 255, md } = _a, props = __rest(_a, ["type", "numberMask", "xs", "sm", "inputMinLength", "inputMaxLength", "md"]);
|
|
48
48
|
const context = (0, react_1.useContext)(form_1.FormContext);
|
|
49
49
|
const chooseInput = (0, react_1.useCallback)(() => {
|
|
50
50
|
const inputConfig = {
|
|
@@ -70,14 +70,14 @@ function Input(_a) {
|
|
|
70
70
|
return 'O CPF precisa ter no mínimo 11 dígitos';
|
|
71
71
|
}
|
|
72
72
|
//
|
|
73
|
-
else if (type === 'input') {
|
|
74
|
-
if (v.length >
|
|
75
|
-
return
|
|
76
|
-
if (v.length <
|
|
77
|
-
return
|
|
73
|
+
else if (type === 'input' || type === 'password') {
|
|
74
|
+
if (v.length > inputMaxLength)
|
|
75
|
+
return `Limite máximo de ${inputMaxLength} caracteres`;
|
|
76
|
+
if (v.length < inputMinLength && props.required)
|
|
77
|
+
return `Limite mínimo de ${inputMinLength} caracteres`;
|
|
78
78
|
}
|
|
79
79
|
//
|
|
80
|
-
else if (type === 'email'
|
|
80
|
+
else if (type === 'email') {
|
|
81
81
|
if (v.length > 50)
|
|
82
82
|
return 'Limite máximo de 50 caracteres';
|
|
83
83
|
if (!/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/g.test(v) && props.required)
|
|
@@ -100,6 +100,8 @@ function Input(_a) {
|
|
|
100
100
|
case 'input':
|
|
101
101
|
case 'email':
|
|
102
102
|
return react_1.default.createElement(material_1.TextField, Object.assign({}, formConfig));
|
|
103
|
+
case 'password':
|
|
104
|
+
return react_1.default.createElement(material_1.TextField, Object.assign({}, formConfig, { type: 'password' }));
|
|
103
105
|
case 'number':
|
|
104
106
|
return (react_1.default.createElement(MaskInput_1.default, { formConfig: formConfig, maskProps: {
|
|
105
107
|
mask: numberMask,
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
export default function MultInput({ name, required, title, customPlaceholder, xs, sm, md, ...props }: {
|
|
2
|
+
export default function MultInput({ name, required, title, customPlaceholder, xs, sm, inputMinLength, inputMaxLength, md, ...props }: {
|
|
3
3
|
name: string;
|
|
4
4
|
title?: string;
|
|
5
5
|
customPlaceholder?: string;
|
|
6
6
|
required?: boolean;
|
|
7
|
+
inputMinLength?: number;
|
|
8
|
+
inputMaxLength?: number;
|
|
7
9
|
xs?: number;
|
|
8
10
|
sm?: number;
|
|
9
11
|
md?: number;
|
|
@@ -44,7 +44,7 @@ const react_1 = __importStar(require("react"));
|
|
|
44
44
|
const form_1 = require("../../../context/form");
|
|
45
45
|
function MultInput(_a) {
|
|
46
46
|
var _b;
|
|
47
|
-
var { name, required = false, title, customPlaceholder, xs = 12, sm, md } = _a, props = __rest(_a, ["name", "required", "title", "customPlaceholder", "xs", "sm", "md"]);
|
|
47
|
+
var { name, required = false, title, customPlaceholder, xs = 12, sm, inputMinLength = 3, inputMaxLength = 255, md } = _a, props = __rest(_a, ["name", "required", "title", "customPlaceholder", "xs", "sm", "inputMinLength", "inputMaxLength", "md"]);
|
|
48
48
|
const context = (0, react_1.useContext)(form_1.FormContext);
|
|
49
49
|
return (react_1.default.createElement(material_1.Grid, Object.assign({ item: true }, { xs, sm, md }),
|
|
50
50
|
title && (react_1.default.createElement(InputLabel_1.default, { required: required, sx: { textTransform: 'capitalize' } }, title)),
|
|
@@ -52,6 +52,10 @@ function MultInput(_a) {
|
|
|
52
52
|
validate: (v, f) => {
|
|
53
53
|
if (required && v.length <= 0)
|
|
54
54
|
return 'Este campo é obrigatório';
|
|
55
|
+
if (v.length > inputMaxLength)
|
|
56
|
+
return `Limite máximo de ${inputMaxLength} caracteres`;
|
|
57
|
+
if (v.length < inputMinLength && required)
|
|
58
|
+
return `Limite mínimo de ${inputMinLength} caracteres`;
|
|
55
59
|
},
|
|
56
60
|
}), { error: (0, lodash_get_1.default)(context.errors, name) ? true : false, helperText: (_b = (0, lodash_get_1.default)(context.errors, name)) === null || _b === void 0 ? void 0 : _b.message, placeholder: customPlaceholder ? customPlaceholder : title }))));
|
|
57
61
|
}
|
|
@@ -254,10 +254,10 @@ function Table({ columns, fetchFunc, emptyMsg = {
|
|
|
254
254
|
react_1.default.createElement(Typography_1.default, { fontSize: 16, sx: { wordWrap: 'break-word', color: '#1E293B' }, fontFamily: 'Inter' }, c.keyName === 'stEventoExterno' ? getStatusMsg((0, lodash_get_1.default)(x, c.keyName)) : (0, lodash_get_1.default)(x, c.keyName)))))),
|
|
255
255
|
react_1.default.createElement(Grid_1.default, { item: true, xs: 12, md: 12 / columnSize },
|
|
256
256
|
react_1.default.createElement(material_1.Stack, { direction: 'row', alignItems: 'center', justifyContent: isSmall ? 'start' : 'flex-end', sx: { height: '100%', paddingBottom: isSmall ? 2 : 0 } }, action(x))))))))),
|
|
257
|
-
getMaxItems().length > 0 &&
|
|
258
|
-
react_1.default.createElement(material_1.Stack, { direction: 'row', justifyContent: 'flex-end', marginTop: 2 },
|
|
259
|
-
react_1.default.createElement(material_1.Button, { startIcon: react_1.default.createElement(FileDownload_1.default, null), variant: 'contained', size: 'small', onClick: downloadCSV, sx: { backgroundColor: '#22C55E', marginRight: { xs: 2, md: 0 } } }, "Salvar .CSV")),
|
|
260
|
-
react_1.default.createElement(material_1.Stack, { direction: 'row', justifyContent: 'center',
|
|
257
|
+
getMaxItems().length > 0 && (react_1.default.createElement(react_1.default.Fragment, null,
|
|
258
|
+
csv && (react_1.default.createElement(material_1.Stack, { direction: 'row', justifyContent: 'flex-end', marginTop: 2 },
|
|
259
|
+
react_1.default.createElement(material_1.Button, { startIcon: react_1.default.createElement(FileDownload_1.default, null), variant: 'contained', size: 'small', onClick: downloadCSV, sx: { backgroundColor: '#22C55E', marginRight: { xs: 2, md: 0 } } }, "Salvar .CSV"))),
|
|
260
|
+
react_1.default.createElement(material_1.Stack, { direction: 'row', justifyContent: 'center', paddingY: 4 },
|
|
261
261
|
react_1.default.createElement(Pagination_1.default, { count: paginationCount, siblingCount: isSmall ? 0 : 1, size: 'large', onChange: onPaginationChange, page: listPage })))))));
|
|
262
262
|
}
|
|
263
263
|
exports.Table = Table;
|
|
@@ -6,8 +6,8 @@ export default function NavBar({ links, title, img, pos, next, el, menuItems, }:
|
|
|
6
6
|
}[];
|
|
7
7
|
title: string;
|
|
8
8
|
img: string;
|
|
9
|
-
next?: boolean;
|
|
10
9
|
menuItems: JSX.Element | JSX.Element[];
|
|
10
|
+
next?: boolean;
|
|
11
11
|
el?: JSX.Element;
|
|
12
12
|
pos?: 'fixed' | 'inherit';
|
|
13
13
|
}): JSX.Element;
|
|
@@ -41,7 +41,7 @@ function NavBar({ links, title, img, pos = 'fixed', next = true, el, menuItems,
|
|
|
41
41
|
let router = undefined;
|
|
42
42
|
if (next)
|
|
43
43
|
router = (0, router_1.useRouter)();
|
|
44
|
-
const { user, login, logout,
|
|
44
|
+
const { user, login, logout, type } = (0, react_1.useContext)(auth_1.AuthContext);
|
|
45
45
|
const [anchor, setAnchor] = (0, react_1.useState)(null);
|
|
46
46
|
const [avatarAnchor, setAvatarAnchor] = (0, react_1.useState)(null);
|
|
47
47
|
const menuOpen = Boolean(anchor);
|
|
@@ -115,8 +115,9 @@ function NavBar({ links, title, img, pos = 'fixed', next = true, el, menuItems,
|
|
|
115
115
|
react_1.default.createElement(material_1.Stack, { direction: 'row', spacing: 0.4, alignItems: 'center', onClick: (e) => setAvatarAnchor(e.currentTarget), sx: { userSelect: 'none' } },
|
|
116
116
|
react_1.default.createElement(material_1.Typography, null, "Ol\u00E1,"),
|
|
117
117
|
react_1.default.createElement(material_1.Typography, { fontWeight: 600 }, user.name),
|
|
118
|
-
react_1.default.createElement(KeyboardArrowDown_1.default, null)))) : (react_1.default.createElement(material_1.Button, { variant: 'contained', size: 'small', startIcon: react_1.default.createElement(Person_1.default, null), onClick: login, sx: { color: 'white', textTransform: 'inherit', borderRadius: 50, paddingX: 2 } },
|
|
119
|
-
react_1.default.createElement(material_1.Typography, { fontWeight: 600, fontSize: 15, padding: 0.4 }, "Entrar com o gov.br"))))
|
|
118
|
+
react_1.default.createElement(KeyboardArrowDown_1.default, null)))) : type === 'govbr' ? (react_1.default.createElement(material_1.Button, { variant: 'contained', size: 'small', startIcon: react_1.default.createElement(Person_1.default, null), onClick: login, sx: { color: 'white', textTransform: 'inherit', borderRadius: 50, paddingX: 2 } },
|
|
119
|
+
react_1.default.createElement(material_1.Typography, { fontWeight: 600, fontSize: 15, padding: 0.4 }, "Entrar com o gov.br"))) : (react_1.default.createElement(material_1.Button, { variant: 'contained', size: 'small', startIcon: react_1.default.createElement(Person_1.default, null), onClick: login, sx: { color: 'white', textTransform: 'inherit', borderRadius: 50, paddingX: 2 } },
|
|
120
|
+
react_1.default.createElement(material_1.Typography, { fontWeight: 600, fontSize: 15, padding: 0.4 }, "Login"))))))),
|
|
120
121
|
loading && react_1.default.createElement(LinearProgress_1.default, null)),
|
|
121
122
|
react_1.default.createElement(material_1.Box, { paddingBottom: 9 })));
|
|
122
123
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { ReactElement } from 'react';
|
|
2
2
|
import { FieldValues } from 'react-hook-form';
|
|
3
|
+
import type { FilesID } from '../../types/form';
|
|
3
4
|
export default function FormProvider({ children, onSubmit, formMethod, submiting, }: {
|
|
4
5
|
children: ReactElement | ReactElement[];
|
|
5
|
-
onSubmit: (data: FieldValues) => void;
|
|
6
|
+
onSubmit: (data: FieldValues, filesUid?: FilesID) => void;
|
|
6
7
|
formMethod?: 'POST' | 'GET' | 'PUT' | 'DELETE' | 'UPDATE';
|
|
7
8
|
submiting?: boolean;
|
|
8
9
|
}): JSX.Element;
|
|
@@ -28,7 +28,7 @@ const react_hook_form_1 = require("react-hook-form");
|
|
|
28
28
|
const form_1 = require("../../context/form");
|
|
29
29
|
function FormProvider({ children, onSubmit, formMethod = 'GET', submiting = false, }) {
|
|
30
30
|
const { register, handleSubmit, formState: { errors }, reset, watch, trigger, setValue, unregister, getValues, } = (0, react_hook_form_1.useForm)();
|
|
31
|
-
const [
|
|
31
|
+
const [filesId, setFilesUid] = (0, react_1.useState)([]);
|
|
32
32
|
return (react_1.default.createElement(form_1.FormContext.Provider, { value: {
|
|
33
33
|
formRegister: register,
|
|
34
34
|
formWatch: watch,
|
|
@@ -42,6 +42,6 @@ function FormProvider({ children, onSubmit, formMethod = 'GET', submiting = fals
|
|
|
42
42
|
errors: errors,
|
|
43
43
|
submiting: submiting,
|
|
44
44
|
} },
|
|
45
|
-
react_1.default.createElement("form", { method: formMethod, onSubmit: handleSubmit(onSubmit) }, children)));
|
|
45
|
+
react_1.default.createElement("form", { method: formMethod, onSubmit: handleSubmit((d) => onSubmit(d, filesId)) }, children)));
|
|
46
46
|
}
|
|
47
47
|
exports.default = FormProvider;
|
|
@@ -131,6 +131,6 @@ function OAuthProvider({ children, AUTH_URL, oidcConfig, redirectURL, validateTo
|
|
|
131
131
|
localStorage.removeItem(userImgName);
|
|
132
132
|
router.replace(redirectURL).finally(() => setUserLoaded(true));
|
|
133
133
|
}
|
|
134
|
-
return react_1.default.createElement(auth_1.AuthContext.Provider, { value: { user, isAuth, userLoaded, login, logout, saveUserData } }, children);
|
|
134
|
+
return react_1.default.createElement(auth_1.AuthContext.Provider, { value: { user, isAuth, userLoaded, login, logout, saveUserData, type: 'govbr' } }, children);
|
|
135
135
|
}
|
|
136
136
|
exports.OAuthProvider = OAuthProvider;
|
package/package.json
CHANGED
package/types/auth.d.ts
CHANGED
package/types/form.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { Dispatch, SetStateAction } from 'react';
|
|
2
|
+
import { FieldErrors, FieldValues, UseFormGetValues, UseFormRegister, UseFormReset, UseFormSetValue, UseFormTrigger, UseFormUnregister, UseFormWatch } from 'react-hook-form';
|
|
3
|
+
export declare enum FieldType {
|
|
4
|
+
INPUT = 0,
|
|
5
|
+
MULT_INPUT = 1,
|
|
6
|
+
PHONE = 2,
|
|
7
|
+
CPF_CNPJ = 3,
|
|
8
|
+
CPF = 4,
|
|
9
|
+
CNPJ = 5,
|
|
10
|
+
RG = 6,
|
|
11
|
+
EMAIL = 7,
|
|
12
|
+
ACTIVE = 8,
|
|
13
|
+
CHECKBOX = 9,
|
|
14
|
+
CHECKBOX_WARNING = 10,
|
|
15
|
+
OTHER_CHECKBOX = 11,
|
|
16
|
+
LABEL = 12,
|
|
17
|
+
CUSTOM = 13,
|
|
18
|
+
FILE = 14,
|
|
19
|
+
MULT_FILE = 15,
|
|
20
|
+
DATE = 16,
|
|
21
|
+
TIME = 17,
|
|
22
|
+
NUMBER = 18,
|
|
23
|
+
AUTO_COMPLETE = 19
|
|
24
|
+
}
|
|
25
|
+
export declare enum ColumnDirection {
|
|
26
|
+
ROW = "row",
|
|
27
|
+
COLUMN = "column"
|
|
28
|
+
}
|
|
29
|
+
export interface FormField {
|
|
30
|
+
type?: FieldType;
|
|
31
|
+
name?: string;
|
|
32
|
+
title?: string;
|
|
33
|
+
required?: boolean;
|
|
34
|
+
customPlaceholder?: string;
|
|
35
|
+
size?: number;
|
|
36
|
+
customForm?: React.ReactElement;
|
|
37
|
+
customData?: any;
|
|
38
|
+
}
|
|
39
|
+
export interface FormData {
|
|
40
|
+
title: string;
|
|
41
|
+
required: boolean;
|
|
42
|
+
formFields: FormField[];
|
|
43
|
+
name?: string;
|
|
44
|
+
}
|
|
45
|
+
export interface FormContextType {
|
|
46
|
+
formRegister: UseFormRegister<FieldValues>;
|
|
47
|
+
formWatch: UseFormWatch<FieldValues>;
|
|
48
|
+
formReset: UseFormReset<FieldValues>;
|
|
49
|
+
formSetValue: UseFormSetValue<FieldValues>;
|
|
50
|
+
formTrigger: UseFormTrigger<FieldValues>;
|
|
51
|
+
formUnregister: UseFormUnregister<FieldValues>;
|
|
52
|
+
formGetValues: UseFormGetValues<FieldValues>;
|
|
53
|
+
setFilesUid: Dispatch<SetStateAction<{
|
|
54
|
+
CO_SEQ_ARQUIVO: number;
|
|
55
|
+
CO_TIPO_ARQUIVO: number;
|
|
56
|
+
}[]>>;
|
|
57
|
+
errors: FieldErrors<FieldValues>;
|
|
58
|
+
submiting: boolean;
|
|
59
|
+
}
|
|
60
|
+
export type FilesID = {
|
|
61
|
+
CO_SEQ_ARQUIVO: number;
|
|
62
|
+
CO_TIPO_ARQUIVO: number;
|
|
63
|
+
}[];
|
package/types/form.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ColumnDirection = exports.FieldType = void 0;
|
|
4
|
+
var FieldType;
|
|
5
|
+
(function (FieldType) {
|
|
6
|
+
FieldType[FieldType["INPUT"] = 0] = "INPUT";
|
|
7
|
+
FieldType[FieldType["MULT_INPUT"] = 1] = "MULT_INPUT";
|
|
8
|
+
FieldType[FieldType["PHONE"] = 2] = "PHONE";
|
|
9
|
+
FieldType[FieldType["CPF_CNPJ"] = 3] = "CPF_CNPJ";
|
|
10
|
+
FieldType[FieldType["CPF"] = 4] = "CPF";
|
|
11
|
+
FieldType[FieldType["CNPJ"] = 5] = "CNPJ";
|
|
12
|
+
FieldType[FieldType["RG"] = 6] = "RG";
|
|
13
|
+
FieldType[FieldType["EMAIL"] = 7] = "EMAIL";
|
|
14
|
+
FieldType[FieldType["ACTIVE"] = 8] = "ACTIVE";
|
|
15
|
+
FieldType[FieldType["CHECKBOX"] = 9] = "CHECKBOX";
|
|
16
|
+
FieldType[FieldType["CHECKBOX_WARNING"] = 10] = "CHECKBOX_WARNING";
|
|
17
|
+
FieldType[FieldType["OTHER_CHECKBOX"] = 11] = "OTHER_CHECKBOX";
|
|
18
|
+
FieldType[FieldType["LABEL"] = 12] = "LABEL";
|
|
19
|
+
FieldType[FieldType["CUSTOM"] = 13] = "CUSTOM";
|
|
20
|
+
FieldType[FieldType["FILE"] = 14] = "FILE";
|
|
21
|
+
FieldType[FieldType["MULT_FILE"] = 15] = "MULT_FILE";
|
|
22
|
+
FieldType[FieldType["DATE"] = 16] = "DATE";
|
|
23
|
+
FieldType[FieldType["TIME"] = 17] = "TIME";
|
|
24
|
+
FieldType[FieldType["NUMBER"] = 18] = "NUMBER";
|
|
25
|
+
FieldType[FieldType["AUTO_COMPLETE"] = 19] = "AUTO_COMPLETE";
|
|
26
|
+
})(FieldType = exports.FieldType || (exports.FieldType = {}));
|
|
27
|
+
var ColumnDirection;
|
|
28
|
+
(function (ColumnDirection) {
|
|
29
|
+
ColumnDirection["ROW"] = "row";
|
|
30
|
+
ColumnDirection["COLUMN"] = "column";
|
|
31
|
+
})(ColumnDirection = exports.ColumnDirection || (exports.ColumnDirection = {}));
|