@pipelinesolucoes/form 1.0.0-beta.4 → 1.0.0-beta.6
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/README.md +13 -16
- package/dist/components/NotificationSnackbar.js +1 -1
- package/dist/components/NotificationSnackbar.js.map +1 -1
- package/dist/components/TextFieldPassword.d.ts +115 -0
- package/dist/components/TextFieldPassword.js +177 -0
- package/dist/components/TextFieldPassword.js.map +1 -0
- package/dist/components/TextFieldValidate.js +1 -1
- package/dist/components/TextFieldValidate.js.map +1 -1
- package/dist/components/login/LoginForm.d.ts +144 -12
- package/dist/components/login/LoginForm.js +137 -64
- package/dist/components/login/LoginForm.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/mui-theme.d.ts +2 -2
- package/dist/mui-theme.js +2 -0
- package/dist/mui-theme.js.map +1 -0
- package/dist/theme.js +1 -1
- package/dist/theme.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -3
package/README.md
CHANGED
|
@@ -14,15 +14,26 @@ A biblioteca inclui os seguintes componentes:
|
|
|
14
14
|
Componente de botão que redireciona o usuário para um endpoint externo (ex: autenticação com Google).
|
|
15
15
|
Durante o clique, o botão entra em estado de loading e, caso ocorra algum erro, exibe uma mensagem abaixo do botão.
|
|
16
16
|
|
|
17
|
+
- **LoginForm**
|
|
18
|
+
Componente de formulário de login com suporte a autenticação via Google e login por email/senha.
|
|
19
|
+
Inclui validação básica de email, exibição de mensagens de erro/sucesso retornadas pelo handler `onClick` e
|
|
20
|
+
customização visual via props (container, campos, botão e links).
|
|
21
|
+
|
|
17
22
|
- **PasswordRecoveryForm**
|
|
18
23
|
Componente de formulário para recuperação de senha via e-mail.
|
|
19
|
-
Faz a validação do e-mail, dispara um `onSubmit` assíncrono (obrigatório) e exibe a mensagem retornada.
|
|
24
|
+
Faz a validação do e-mail, dispara um `onSubmit` assíncrono (obrigatório) e exibe a mensagem retornada.
|
|
25
|
+
|
|
26
|
+
- **TextFieldPassword**
|
|
27
|
+
Componente de campo de senha baseado no TextField do Material UI, com botão para alternar entre mostrar/ocultar a senha. O componente:
|
|
28
|
+
- Retorna somente a senha digitada via `onPasswordChange`
|
|
29
|
+
- Valida obrigatório + formato (regex) e exibe mensagens de erro automaticamente
|
|
30
|
+
- Dispara um "evento" de validação via `onValidationChange`
|
|
20
31
|
|
|
21
32
|
- **TextFieldValidate**
|
|
22
33
|
Componente de campo de texto com validação, baseado no TextField do Material UI.
|
|
23
34
|
Permite personalização visual via `styled` e suporte a validações comuns (obrigatório, tamanho mínimo, regex) e validação customizada.
|
|
24
35
|
|
|
25
|
-
- **
|
|
36
|
+
- **NotificationSnackbar**
|
|
26
37
|
Componente que exibe uma notificação no topo da tela utilizando o Snackbar e Alert do Material UI.
|
|
27
38
|
---
|
|
28
39
|
|
|
@@ -47,20 +58,6 @@ yarn add @pipelinesolucoes/form
|
|
|
47
58
|
|
|
48
59
|
```
|
|
49
60
|
|
|
50
|
-
## 🚀 Uso básico
|
|
51
|
-
|
|
52
|
-
```
|
|
53
|
-
import { Actionform } from "@pipelinesolucoes/form";
|
|
54
|
-
|
|
55
|
-
export function Example() {
|
|
56
|
-
return (
|
|
57
|
-
<Actionform variant="contained" color="primary">
|
|
58
|
-
Ação
|
|
59
|
-
</Actionform>
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
```
|
|
63
|
-
|
|
64
61
|
## 🧩 Uso em Design Systems
|
|
65
62
|
|
|
66
63
|
Este pacote foi projetado para:
|
|
@@ -47,7 +47,7 @@ const NotificationSnackbar = ({ background = '#fff', open, text, variant = 'body
|
|
|
47
47
|
var _a, _b, _c, _d;
|
|
48
48
|
const theme = useTheme();
|
|
49
49
|
// 1) prop -> 2) token -> 3) fallback
|
|
50
|
-
const resolvedBackground = (_d = background !== null && background !== void 0 ? background : (_c = (_b = (_a = theme.pipesol) === null || _a === void 0 ? void 0 : _a.
|
|
50
|
+
const resolvedBackground = (_d = background !== null && background !== void 0 ? background : (_c = (_b = (_a = theme.pipesol) === null || _a === void 0 ? void 0 : _a.forms) === null || _b === void 0 ? void 0 : _b.notification) === null || _c === void 0 ? void 0 : _c.background) !== null && _d !== void 0 ? _d : "#ffffff";
|
|
51
51
|
return (_jsx(Snackbar, { open: open, autoHideDuration: 4000, onClose: onClose, anchorOrigin: anchorOrigin, children: _jsx(Alert, { onClose: onClose, severity: severity, variant: "filled", sx: { color: resolvedBackground }, children: _jsx(Typography, { variant: variant, component: "span", children: text }) }) }));
|
|
52
52
|
};
|
|
53
53
|
NotificationSnackbar.displayName = 'NotificationSnackbar';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NotificationSnackbar.js","sourceRoot":"","sources":["../../src/components/NotificationSnackbar.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAIb,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAc,UAAU,EAAqC,QAAQ,EAAE,MAAM,eAAe,CAAC;AAYrH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,MAAM,oBAAoB,GAAwC,CAAC,EACjE,UAAU,GAAC,MAAM,EACjB,IAAI,EACJ,IAAI,EACJ,OAAO,GAAC,OAAO,EACf,QAAQ,GAAG,SAAS,EACpB,YAAY,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,EACxD,OAAO,GACR,EAAE,EAAE;;IAEH,MAAM,KAAK,GAAG,QAAQ,EAAE,CAAC;IAEzB,qCAAqC;IACrC,MAAM,kBAAkB,GACtB,MAAA,UAAU,aAAV,UAAU,cAAV,UAAU,GACV,MAAA,MAAA,MAAA,KAAK,CAAC,OAAO,0CAAE,
|
|
1
|
+
{"version":3,"file":"NotificationSnackbar.js","sourceRoot":"","sources":["../../src/components/NotificationSnackbar.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAIb,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAc,UAAU,EAAqC,QAAQ,EAAE,MAAM,eAAe,CAAC;AAYrH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,MAAM,oBAAoB,GAAwC,CAAC,EACjE,UAAU,GAAC,MAAM,EACjB,IAAI,EACJ,IAAI,EACJ,OAAO,GAAC,OAAO,EACf,QAAQ,GAAG,SAAS,EACpB,YAAY,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,EACxD,OAAO,GACR,EAAE,EAAE;;IAEH,MAAM,KAAK,GAAG,QAAQ,EAAE,CAAC;IAEzB,qCAAqC;IACrC,MAAM,kBAAkB,GACtB,MAAA,UAAU,aAAV,UAAU,cAAV,UAAU,GACV,MAAA,MAAA,MAAA,KAAK,CAAC,OAAO,0CAAE,KAAK,0CAAE,YAAY,0CAAE,UAAU,mCAC9C,SAAS,CAAC;IAEZ,OAAO,CACL,KAAC,QAAQ,IACP,IAAI,EAAE,IAAI,EACV,gBAAgB,EAAE,IAAI,EACtB,OAAO,EAAE,OAAO,EAChB,YAAY,EAAE,YAAY,YAE1B,KAAC,KAAK,IAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAC,QAAQ,EAAC,EAAE,EAAE,EAAE,KAAK,EAAE,kBAAkB,EAAE,YAC7F,KAAC,UAAU,IAAC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAC,MAAM,YAAE,IAAI,GAAc,GAC5D,GACC,CACZ,CAAC;AACJ,CAAC,CAAC;AAEF,oBAAoB,CAAC,WAAW,GAAG,sBAAsB,CAAC;AAE1D,eAAe,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { BorderProps } from '@/types/BorderProps';
|
|
3
|
+
import { ColorProps } from '@/types/ColorProps';
|
|
4
|
+
import { LayoutProps } from '@/types/LayoutProps';
|
|
5
|
+
type ValidationStatus = 'idle' | 'required' | 'invalid' | 'valid';
|
|
6
|
+
interface PasswordValidationResult {
|
|
7
|
+
isValid: boolean;
|
|
8
|
+
status: ValidationStatus;
|
|
9
|
+
message: string;
|
|
10
|
+
value: string;
|
|
11
|
+
}
|
|
12
|
+
interface TextFieldPasswordProps extends BorderProps, ColorProps, LayoutProps {
|
|
13
|
+
id?: string;
|
|
14
|
+
label?: string;
|
|
15
|
+
placeholder?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Valor controlado do campo (opcional).
|
|
18
|
+
* Se você não passar `value`, o componente funciona de forma "semi-controlada" internamente.
|
|
19
|
+
*/
|
|
20
|
+
value?: string;
|
|
21
|
+
background?: string;
|
|
22
|
+
backgroundDisabled?: string;
|
|
23
|
+
color?: string;
|
|
24
|
+
colorFocused?: string;
|
|
25
|
+
colorDisabled?: string;
|
|
26
|
+
borderRadius?: string;
|
|
27
|
+
boxShadow?: string;
|
|
28
|
+
borderColor?: string;
|
|
29
|
+
padding?: string;
|
|
30
|
+
disabled?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Se true, valida obrigatório.
|
|
33
|
+
* @default true
|
|
34
|
+
*/
|
|
35
|
+
required?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Regra de formato (regex) para validar a senha.
|
|
38
|
+
* @default /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^A-Za-z0-9]).{8,}$/
|
|
39
|
+
*/
|
|
40
|
+
passwordPattern?: RegExp;
|
|
41
|
+
/**
|
|
42
|
+
* Mensagem quando o campo é obrigatório e está vazio.
|
|
43
|
+
* @default 'Senha obrigatória'
|
|
44
|
+
*/
|
|
45
|
+
requiredMessage?: string;
|
|
46
|
+
/**
|
|
47
|
+
* Mensagem quando a senha não atende o padrão.
|
|
48
|
+
* @default 'Senha inválida'
|
|
49
|
+
*/
|
|
50
|
+
invalidMessage?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Quando validar:
|
|
53
|
+
* - 'blur': valida ao sair do campo
|
|
54
|
+
* - 'change': valida a cada digitação
|
|
55
|
+
* - 'both': valida nos dois
|
|
56
|
+
* @default 'blur'
|
|
57
|
+
*/
|
|
58
|
+
validateOn?: 'blur' | 'change' | 'both';
|
|
59
|
+
/**
|
|
60
|
+
* Retorna somente a senha digitada (string).
|
|
61
|
+
*/
|
|
62
|
+
onPasswordChange?: (password: string) => void;
|
|
63
|
+
/**
|
|
64
|
+
* "Evento" com o resultado completo da validação.
|
|
65
|
+
*/
|
|
66
|
+
onValidationChange?: (result: PasswordValidationResult) => void;
|
|
67
|
+
/**
|
|
68
|
+
* Se você ainda quiser receber o evento nativo.
|
|
69
|
+
*/
|
|
70
|
+
onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;
|
|
71
|
+
onBlur?: (event: React.FocusEvent<HTMLInputElement>) => void;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Componente de campo de senha baseado no TextField do Material UI, com botão para alternar
|
|
75
|
+
* entre mostrar/ocultar a senha. O componente:
|
|
76
|
+
* - Retorna somente a senha digitada via `onPasswordChange`
|
|
77
|
+
* - Valida obrigatório + formato (regex) e exibe mensagens de erro automaticamente
|
|
78
|
+
* - Dispara um "evento" de validação via `onValidationChange`
|
|
79
|
+
*
|
|
80
|
+
* @param {string} [id] ID do input.
|
|
81
|
+
* @param {string} [label] Label do campo.
|
|
82
|
+
* @param {string} [placeholder] Placeholder do input.
|
|
83
|
+
* @param {string} [value] Valor controlado do campo.
|
|
84
|
+
* @param {boolean} [required=true] Se true, valida senha obrigatória.
|
|
85
|
+
* @param {RegExp} [passwordPattern=/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^A-Za-z0-9]).{8,}$/] Regex para validar formato.
|
|
86
|
+
* @param {string} [requiredMessage='Senha obrigatória'] Mensagem para campo vazio.
|
|
87
|
+
* @param {string} [invalidMessage='Senha inválida'] Mensagem para formato inválido.
|
|
88
|
+
* @param {'blur' | 'change' | 'both'} [validateOn='blur'] Quando validar.
|
|
89
|
+
* @param {(password: string) => void} [onPasswordChange] Retorna somente a senha digitada.
|
|
90
|
+
* @param {(result: PasswordValidationResult) => void} [onValidationChange] Evento com resultado completo da validação.
|
|
91
|
+
* @param {(event: React.ChangeEvent<HTMLInputElement>) => void} [onChange] onChange nativo (opcional).
|
|
92
|
+
* @param {(event: React.FocusEvent<HTMLInputElement>) => void} [onBlur] onBlur nativo (opcional).
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```tsx
|
|
96
|
+
* import React from 'react';
|
|
97
|
+
* import { TextFieldPassword } from '@/components/TextFieldPassword';
|
|
98
|
+
*
|
|
99
|
+
* const Example = () => {
|
|
100
|
+
* const [password, setPassword] = React.useState('');
|
|
101
|
+
*
|
|
102
|
+
* return (
|
|
103
|
+
* <TextFieldPassword
|
|
104
|
+
* label="Senha"
|
|
105
|
+
* value={password}
|
|
106
|
+
* onPasswordChange={(p) => setPassword(p)}
|
|
107
|
+
* onValidationChange={(r) => console.log(r)}
|
|
108
|
+
* validateOn="both"
|
|
109
|
+
* />
|
|
110
|
+
* );
|
|
111
|
+
* };
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
declare const TextFieldPassword: React.FC<TextFieldPasswordProps>;
|
|
115
|
+
export default TextFieldPassword;
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import TextField from '@mui/material/TextField';
|
|
5
|
+
import InputAdornment from '@mui/material/InputAdornment';
|
|
6
|
+
import IconButton from '@mui/material/IconButton';
|
|
7
|
+
import VisibilityIcon from '@mui/icons-material/Visibility';
|
|
8
|
+
import VisibilityOffIcon from '@mui/icons-material/VisibilityOff';
|
|
9
|
+
import { styled } from '@mui/material/styles';
|
|
10
|
+
const StyledTextField = styled(TextField, {
|
|
11
|
+
shouldForwardProp: (prop) => ![
|
|
12
|
+
'background',
|
|
13
|
+
'borderRadius',
|
|
14
|
+
'boxShadow',
|
|
15
|
+
'borderColor',
|
|
16
|
+
'colorFocused',
|
|
17
|
+
'backgroundDisabled',
|
|
18
|
+
'colorDisabled',
|
|
19
|
+
'padding',
|
|
20
|
+
'colorText',
|
|
21
|
+
].includes(prop),
|
|
22
|
+
})(({ theme, background, backgroundDisabled, colorText, borderRadius, boxShadow, borderColor, colorFocused, colorDisabled, padding, }) => {
|
|
23
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
24
|
+
const field = (_b = (_a = theme.pipesol) === null || _a === void 0 ? void 0 : _a.forms) === null || _b === void 0 ? void 0 : _b.field;
|
|
25
|
+
const bg = (_c = background !== null && background !== void 0 ? background : field === null || field === void 0 ? void 0 : field.background) !== null && _c !== void 0 ? _c : 'transparent';
|
|
26
|
+
const bgDisabled = (_d = backgroundDisabled !== null && backgroundDisabled !== void 0 ? backgroundDisabled : field === null || field === void 0 ? void 0 : field.backgroundDisabled) !== null && _d !== void 0 ? _d : bg;
|
|
27
|
+
const txt = (_e = colorText !== null && colorText !== void 0 ? colorText : field === null || field === void 0 ? void 0 : field.color) !== null && _e !== void 0 ? _e : theme.palette.text.primary;
|
|
28
|
+
const txtDisabled = (_f = colorDisabled !== null && colorDisabled !== void 0 ? colorDisabled : field === null || field === void 0 ? void 0 : field.colorDisabled) !== null && _f !== void 0 ? _f : theme.palette.text.disabled;
|
|
29
|
+
const br = (_g = borderRadius !== null && borderRadius !== void 0 ? borderRadius : field === null || field === void 0 ? void 0 : field.borderRadius) !== null && _g !== void 0 ? _g : '8px';
|
|
30
|
+
const sh = (_h = boxShadow !== null && boxShadow !== void 0 ? boxShadow : field === null || field === void 0 ? void 0 : field.boxShadow) !== null && _h !== void 0 ? _h : 'none';
|
|
31
|
+
const bd = (_j = borderColor !== null && borderColor !== void 0 ? borderColor : field === null || field === void 0 ? void 0 : field.borderColor) !== null && _j !== void 0 ? _j : theme.palette.divider;
|
|
32
|
+
const bdFocused = (_k = colorFocused !== null && colorFocused !== void 0 ? colorFocused : field === null || field === void 0 ? void 0 : field.colorFocused) !== null && _k !== void 0 ? _k : theme.palette.primary.main;
|
|
33
|
+
const pad = padding !== null && padding !== void 0 ? padding : field === null || field === void 0 ? void 0 : field.padding;
|
|
34
|
+
return {
|
|
35
|
+
background: bg,
|
|
36
|
+
borderRadius: br,
|
|
37
|
+
boxShadow: sh,
|
|
38
|
+
'& .MuiInputBase-root': {
|
|
39
|
+
color: txt,
|
|
40
|
+
},
|
|
41
|
+
'& .MuiOutlinedInput-root': Object.assign(Object.assign({ background: bg, borderRadius: br, boxShadow: sh }, (pad ? { padding: pad } : {})), { '& .MuiOutlinedInput-notchedOutline': {
|
|
42
|
+
borderColor: bd,
|
|
43
|
+
}, '&:hover .MuiOutlinedInput-notchedOutline': {
|
|
44
|
+
borderColor: bd,
|
|
45
|
+
}, '&.Mui-focused .MuiOutlinedInput-notchedOutline': {
|
|
46
|
+
borderColor: bdFocused,
|
|
47
|
+
}, '&.Mui-disabled': {
|
|
48
|
+
background: bgDisabled,
|
|
49
|
+
color: txtDisabled,
|
|
50
|
+
'& .MuiOutlinedInput-notchedOutline': {
|
|
51
|
+
borderColor: bd,
|
|
52
|
+
},
|
|
53
|
+
}, '& input.Mui-disabled': {
|
|
54
|
+
WebkitTextFillColor: txtDisabled,
|
|
55
|
+
} }),
|
|
56
|
+
'& .MuiInputLabel-root': {
|
|
57
|
+
color: txt,
|
|
58
|
+
},
|
|
59
|
+
'& .MuiInputLabel-root.Mui-focused': {
|
|
60
|
+
color: bdFocused,
|
|
61
|
+
},
|
|
62
|
+
'& .MuiInputLabel-root.Mui-disabled': {
|
|
63
|
+
color: txtDisabled,
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
/**
|
|
68
|
+
* Componente de campo de senha baseado no TextField do Material UI, com botão para alternar
|
|
69
|
+
* entre mostrar/ocultar a senha. O componente:
|
|
70
|
+
* - Retorna somente a senha digitada via `onPasswordChange`
|
|
71
|
+
* - Valida obrigatório + formato (regex) e exibe mensagens de erro automaticamente
|
|
72
|
+
* - Dispara um "evento" de validação via `onValidationChange`
|
|
73
|
+
*
|
|
74
|
+
* @param {string} [id] ID do input.
|
|
75
|
+
* @param {string} [label] Label do campo.
|
|
76
|
+
* @param {string} [placeholder] Placeholder do input.
|
|
77
|
+
* @param {string} [value] Valor controlado do campo.
|
|
78
|
+
* @param {boolean} [required=true] Se true, valida senha obrigatória.
|
|
79
|
+
* @param {RegExp} [passwordPattern=/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^A-Za-z0-9]).{8,}$/] Regex para validar formato.
|
|
80
|
+
* @param {string} [requiredMessage='Senha obrigatória'] Mensagem para campo vazio.
|
|
81
|
+
* @param {string} [invalidMessage='Senha inválida'] Mensagem para formato inválido.
|
|
82
|
+
* @param {'blur' | 'change' | 'both'} [validateOn='blur'] Quando validar.
|
|
83
|
+
* @param {(password: string) => void} [onPasswordChange] Retorna somente a senha digitada.
|
|
84
|
+
* @param {(result: PasswordValidationResult) => void} [onValidationChange] Evento com resultado completo da validação.
|
|
85
|
+
* @param {(event: React.ChangeEvent<HTMLInputElement>) => void} [onChange] onChange nativo (opcional).
|
|
86
|
+
* @param {(event: React.FocusEvent<HTMLInputElement>) => void} [onBlur] onBlur nativo (opcional).
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```tsx
|
|
90
|
+
* import React from 'react';
|
|
91
|
+
* import { TextFieldPassword } from '@/components/TextFieldPassword';
|
|
92
|
+
*
|
|
93
|
+
* const Example = () => {
|
|
94
|
+
* const [password, setPassword] = React.useState('');
|
|
95
|
+
*
|
|
96
|
+
* return (
|
|
97
|
+
* <TextFieldPassword
|
|
98
|
+
* label="Senha"
|
|
99
|
+
* value={password}
|
|
100
|
+
* onPasswordChange={(p) => setPassword(p)}
|
|
101
|
+
* onValidationChange={(r) => console.log(r)}
|
|
102
|
+
* validateOn="both"
|
|
103
|
+
* />
|
|
104
|
+
* );
|
|
105
|
+
* };
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
const TextFieldPassword = ({ id, label, placeholder, value, onPasswordChange, onValidationChange, required = true, passwordPattern = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^A-Za-z0-9]).{8,}$/, requiredMessage = 'Senha obrigatória', invalidMessage = 'Senha inválida', validateOn = 'blur', background = '#fff', backgroundDisabled = '#E5E7EB', color = '#000', colorFocused = '#1976d2', colorDisabled = '#9CA3AF', borderRadius = '0', boxShadow = 'none', borderColor = '#ccc', disabled = false, padding = '4px 8px', onChange, onBlur, }) => {
|
|
109
|
+
const [showPassword, setShowPassword] = React.useState(false);
|
|
110
|
+
const [touched, setTouched] = React.useState(false);
|
|
111
|
+
// fallback interno caso o usuário não use `value`
|
|
112
|
+
const [innerValue, setInnerValue] = React.useState(value !== null && value !== void 0 ? value : '');
|
|
113
|
+
const currentValue = value !== null && value !== void 0 ? value : innerValue;
|
|
114
|
+
React.useEffect(() => {
|
|
115
|
+
if (typeof value === 'string')
|
|
116
|
+
setInnerValue(value);
|
|
117
|
+
}, [value]);
|
|
118
|
+
const computeValidation = React.useCallback((nextValue) => {
|
|
119
|
+
const trimmed = nextValue !== null && nextValue !== void 0 ? nextValue : '';
|
|
120
|
+
if (required && trimmed.length === 0) {
|
|
121
|
+
return { isValid: false, status: 'required', message: requiredMessage, value: nextValue };
|
|
122
|
+
}
|
|
123
|
+
if (trimmed.length > 0 && passwordPattern && !passwordPattern.test(trimmed)) {
|
|
124
|
+
return { isValid: false, status: 'invalid', message: invalidMessage, value: nextValue };
|
|
125
|
+
}
|
|
126
|
+
// se não é required e está vazio, consideramos "idle" (sem erro)
|
|
127
|
+
if (!required && trimmed.length === 0) {
|
|
128
|
+
return { isValid: true, status: 'idle', message: '', value: nextValue };
|
|
129
|
+
}
|
|
130
|
+
return { isValid: true, status: 'valid', message: '', value: nextValue };
|
|
131
|
+
}, [invalidMessage, passwordPattern, required, requiredMessage]);
|
|
132
|
+
const emitValidation = React.useCallback((nextValue) => {
|
|
133
|
+
const result = computeValidation(nextValue);
|
|
134
|
+
if (onValidationChange)
|
|
135
|
+
onValidationChange(result);
|
|
136
|
+
return result;
|
|
137
|
+
}, [computeValidation, onValidationChange]);
|
|
138
|
+
const [validation, setValidation] = React.useState(() => computeValidation(currentValue));
|
|
139
|
+
const shouldValidateOnChange = validateOn === 'change' || validateOn === 'both';
|
|
140
|
+
const shouldValidateOnBlur = validateOn === 'blur' || validateOn === 'both';
|
|
141
|
+
const handleChange = (event) => {
|
|
142
|
+
const nextValue = event.target.value;
|
|
143
|
+
// atualiza interno caso não seja controlado
|
|
144
|
+
if (typeof value !== 'string')
|
|
145
|
+
setInnerValue(nextValue);
|
|
146
|
+
// retorna apenas a senha (string)
|
|
147
|
+
if (onPasswordChange)
|
|
148
|
+
onPasswordChange(nextValue);
|
|
149
|
+
// mantém compatibilidade com evento nativo
|
|
150
|
+
if (onChange)
|
|
151
|
+
onChange(event);
|
|
152
|
+
if (shouldValidateOnChange) {
|
|
153
|
+
const result = emitValidation(nextValue);
|
|
154
|
+
setValidation(result);
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
const handleBlur = (event) => {
|
|
158
|
+
if (!touched)
|
|
159
|
+
setTouched(true);
|
|
160
|
+
if (onBlur)
|
|
161
|
+
onBlur(event);
|
|
162
|
+
if (shouldValidateOnBlur) {
|
|
163
|
+
const result = emitValidation(currentValue);
|
|
164
|
+
setValidation(result);
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
const shouldShowError = touched && !validation.isValid && validation.status !== 'idle';
|
|
168
|
+
const helperText = shouldShowError ? validation.message : ' ';
|
|
169
|
+
return (_jsx(StyledTextField, { type: showPassword ? 'text' : 'password', id: id, label: label, placeholder: placeholder, value: currentValue, background: background, backgroundDisabled: backgroundDisabled, colorText: color, colorFocused: colorFocused, colorDisabled: colorDisabled, borderRadius: borderRadius, boxShadow: boxShadow, borderColor: borderColor, padding: padding, disabled: disabled, required: required, fullWidth: true, error: shouldShowError, helperText: helperText, slotProps: {
|
|
170
|
+
input: {
|
|
171
|
+
endAdornment: (_jsx(InputAdornment, { position: "end", children: _jsx(IconButton, { onClick: () => setShowPassword((prev) => !prev), edge: "end", "aria-label": showPassword ? 'Ocultar senha' : 'Mostrar senha', children: showPassword ? _jsx(VisibilityOffIcon, {}) : _jsx(VisibilityIcon, {}) }) })),
|
|
172
|
+
},
|
|
173
|
+
}, onChange: handleChange, onBlur: handleBlur }));
|
|
174
|
+
};
|
|
175
|
+
TextFieldPassword.displayName = 'TextFieldPassword';
|
|
176
|
+
export default TextFieldPassword;
|
|
177
|
+
//# sourceMappingURL=TextFieldPassword.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TextFieldPassword.js","sourceRoot":"","sources":["../../src/components/TextFieldPassword.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,SAAS,MAAM,yBAAyB,CAAC;AAChD,OAAO,cAAc,MAAM,8BAA8B,CAAC;AAC1D,OAAO,UAAU,MAAM,0BAA0B,CAAC;AAClD,OAAO,cAAc,MAAM,gCAAgC,CAAC;AAC5D,OAAO,iBAAiB,MAAM,mCAAmC,CAAC;AAClE,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAsF9C,MAAM,eAAe,GAAG,MAAM,CAAC,SAAS,EAAE;IACxC,iBAAiB,EAAE,CAAC,IAAI,EAAE,EAAE,CAC1B,CAAC;QACC,YAAY;QACZ,cAAc;QACd,WAAW;QACX,aAAa;QACb,cAAc;QACd,oBAAoB;QACpB,eAAe;QACf,SAAS;QACT,WAAW;KACZ,CAAC,QAAQ,CAAC,IAAc,CAAC;CAC7B,CAAC,CAWA,CAAC,EACC,KAAK,EACL,UAAU,EACV,kBAAkB,EAClB,SAAS,EACT,YAAY,EACZ,SA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N,KAAK,EAAE,KAAK,EACZ,WAAW,EAAE,WAAW,EACxB,KAAK,EAAE,YAAY,EACnB,UAAU,EAAE,UAAU,EACtB,kBAAkB,EAAE,kBAAkB,EACtC,SAAS,EAAE,KAAK,EAChB,YAAY,EAAE,YAAY,EAC1B,aAAa,EAAE,aAAa,EAC5B,YAAY,EAAE,YAAY,EAC1B,SAAS,EAAE,SAAS,EACpB,WAAW,EAAE,WAAW,EACxB,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,SAAS,QACT,KAAK,EAAE,eAAe,EACtB,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE;YACT,KAAK,EAAE;gBACL,YAAY,EAAE,CACZ,KAAC,cAAc,IAAC,QAAQ,EAAC,KAAK,YAC5B,KAAC,UAAU,IACT,OAAO,EAAE,GAAG,EAAE,CAAC,eAAe,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,EAC/C,IAAI,EAAC,KAAK,gBACE,YAAY,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,eAAe,YAE3D,YAAY,CAAC,CAAC,CAAC,KAAC,iBAAiB,KAAG,CAAC,CAAC,CAAC,KAAC,cAAc,KAAG,GAC/C,GACE,CAClB;aACF;SACF,EACD,QAAQ,EAAE,YAAY,EACtB,MAAM,EAAE,UAAU,GAClB,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,iBAAiB,CAAC,WAAW,GAAG,mBAAmB,CAAC;AAEpD,eAAe,iBAAiB,CAAC"}
|
|
@@ -16,7 +16,7 @@ const StyledTextField = styled(TextField, {
|
|
|
16
16
|
].includes(prop),
|
|
17
17
|
})(({ theme, background, backgroundDisabled, colorText, borderRadius, boxShadow, borderColor, colorFocused, colorDisabled, padding, }) => {
|
|
18
18
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
19
|
-
const field = (_b = (_a = theme.pipesol) === null || _a === void 0 ? void 0 : _a.
|
|
19
|
+
const field = (_b = (_a = theme.pipesol) === null || _a === void 0 ? void 0 : _a.forms) === null || _b === void 0 ? void 0 : _b.field;
|
|
20
20
|
// props -> tokens -> fallback
|
|
21
21
|
const bg = (_c = background !== null && background !== void 0 ? background : field === null || field === void 0 ? void 0 : field.background) !== null && _c !== void 0 ? _c : "transparent";
|
|
22
22
|
const bgDisabled = (_d = backgroundDisabled !== null && backgroundDisabled !== void 0 ? backgroundDisabled : field === null || field === void 0 ? void 0 : field.backgroundDisabled) !== null && _d !== void 0 ? _d : bg;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextFieldValidate.js","sourceRoot":"","sources":["../../src/components/TextFieldValidate.tsx"],"names":[],"mappings":";AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,SAAS,MAAM,yBAAyB,CAAC;AA4ChD,MAAM,eAAe,GAAG,MAAM,CAAC,SAAS,EAAE;IACxC,iBAAiB,EAAE,CAAC,IAAI,EAAE,EAAE,CAC1B,CAAC;QACC,YAAY;QACZ,cAAc;QACd,WAAW;QACX,aAAa;QACb,cAAc;QACd,oBAAoB;QACpB,eAAe;QACf,SAAS;QACT,WAAW;KACZ,CAAC,QAAQ,CAAC,IAAc,CAAC;CAC7B,CAAC,CAWA,CAAC,EACC,KAAK,EACL,UAAU,EACV,kBAAkB,EAClB,SAAS,EACT,YAAY,EACZ,SAAS,EACT,WAAW,EACX,YAAY,EACZ,aAAa,EACb,OAAO,GACR,EAAE,EAAE;;IACH,MAAM,KAAK,GAAG,MAAA,MAAA,KAAK,CAAC,OAAO,0CAAE,
|
|
1
|
+
{"version":3,"file":"TextFieldValidate.js","sourceRoot":"","sources":["../../src/components/TextFieldValidate.tsx"],"names":[],"mappings":";AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;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{ SvgIconProps } from '@mui/material';
|
|
3
|
-
|
|
4
|
+
import { ButtonProps } from '@/types/ButtonProps';
|
|
5
|
+
import { FieldProps } from '@/types/FieldProps';
|
|
6
|
+
import { ColorProps } from '@/types/ColorProps';
|
|
7
|
+
import { BorderProps } from '@/types/BorderProps';
|
|
8
|
+
/**
|
|
9
|
+
* Retorno do onClick/onSubmit do componente pai.
|
|
10
|
+
* - success: define se a ação foi bem sucedida
|
|
11
|
+
* - message: mensagem para exibir no próprio LoginForm
|
|
12
|
+
* - color: cor opcional para a mensagem (caso queira sobrescrever as cores padrão)
|
|
13
|
+
*/
|
|
14
|
+
export interface ClickResult {
|
|
15
|
+
success: boolean;
|
|
16
|
+
message: string;
|
|
17
|
+
color?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface LoginFormProps extends ColorProps, BorderProps, ButtonProps, FieldProps {
|
|
4
20
|
Icon?: React.ElementType<SvgIconProps>;
|
|
5
21
|
titulo?: () => React.ReactElement;
|
|
6
22
|
googleButton: () => React.ReactElement;
|
|
7
23
|
color: string;
|
|
8
24
|
background?: string;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
25
|
+
borderRadius?: string;
|
|
26
|
+
border?: string;
|
|
27
|
+
boxShadow?: string;
|
|
28
|
+
backgroundField?: string;
|
|
29
|
+
colorField?: string;
|
|
30
|
+
colorFocusedField?: string;
|
|
31
|
+
borderRadiusField?: string;
|
|
32
|
+
boxShadowField?: string;
|
|
33
|
+
borderColorField?: string;
|
|
34
|
+
paddingField?: string;
|
|
35
|
+
textButton?: string;
|
|
36
|
+
variantButton?: TypographyVariant;
|
|
37
|
+
backgroundButton?: string;
|
|
38
|
+
backgroundHoverButton?: string;
|
|
39
|
+
colorButton?: string;
|
|
40
|
+
colorHoverButton?: string;
|
|
41
|
+
borderRadiusButton?: string;
|
|
42
|
+
borderButton?: string;
|
|
43
|
+
boxShadowButton?: string;
|
|
44
|
+
widthButton?: string;
|
|
45
|
+
heightButton?: string;
|
|
46
|
+
paddingButton?: string;
|
|
47
|
+
marginButton?: string;
|
|
48
|
+
/** Cores padrão para mensagem (caso o pai não retorne color no ClickResult) */
|
|
17
49
|
color_message_sucess: string;
|
|
18
|
-
message_erro?: string;
|
|
19
50
|
color_message_erro: string;
|
|
20
51
|
color_link: string;
|
|
21
52
|
color_separador: string;
|
|
22
|
-
background_color_button_google?: string;
|
|
23
|
-
color_button_google: string;
|
|
24
53
|
urlRecuperarConta: string;
|
|
25
54
|
urlCriarConta: string;
|
|
26
55
|
children?: React.ReactNode;
|
|
56
|
+
/**
|
|
57
|
+
* Evento disparado ao clicar no botão principal.
|
|
58
|
+
* O componente pai devolve a mensagem e o sucesso/erro.
|
|
59
|
+
*/
|
|
60
|
+
onClick?: (data: {
|
|
61
|
+
email: string;
|
|
62
|
+
password: string;
|
|
63
|
+
}) => Promise<ClickResult> | ClickResult;
|
|
27
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Componente de formulário de login com suporte a autenticação via Google e login por email/senha.
|
|
67
|
+
* Inclui validação básica de email, exibição de mensagens de erro/sucesso retornadas pelo handler `onClick`
|
|
68
|
+
* e customização visual via props (container, campos, botão e links).
|
|
69
|
+
*
|
|
70
|
+
* @param {string} urlRecuperarConta URL para a página de recuperação de conta/senha. Obrigatório.
|
|
71
|
+
* @param {string} urlCriarConta URL para a página de criação de conta. Obrigatório.
|
|
72
|
+
* @param {React.ElementType<SvgIconProps>} [Icon] Ícone opcional (MUI SvgIcon) exibido no topo do formulário.
|
|
73
|
+
* @param {() => React.ReactElement} [titulo] Função que retorna o conteúdo do título exibido no topo do formulário.
|
|
74
|
+
* @param {() => React.ReactElement} googleButton Função que retorna o botão de login com Google. Obrigatório.
|
|
75
|
+
*
|
|
76
|
+
* @param {string} color Cor usada em alguns textos/containers auxiliares (ex.: wrapper dos links). Obrigatório.
|
|
77
|
+
* @param {string} [background='transparent'] Cor de fundo do container principal.
|
|
78
|
+
* @param {string} [borderRadius='0'] Raio da borda do container principal.
|
|
79
|
+
* @param {string} [border='none'] Borda do container principal.
|
|
80
|
+
* @param {string} [boxShadow='none'] Sombra do container principal.
|
|
81
|
+
*
|
|
82
|
+
* @param {string} [backgroundField='transparent'] Fundo dos campos (email/senha).
|
|
83
|
+
* @param {string} [colorField='#000'] Cor do texto dos campos (email/senha).
|
|
84
|
+
* @param {string} [colorFocusedField] Cor do estado focado do campo (se suportado pelos campos internos).
|
|
85
|
+
* @param {string} [borderRadiusField='0px'] Raio da borda dos campos.
|
|
86
|
+
* @param {string} [boxShadowField='none'] Sombra dos campos.
|
|
87
|
+
* @param {string} [borderColorField='#ccc'] Cor da borda dos campos.
|
|
88
|
+
* @param {string} [paddingField='4px 8px'] Espaçamento interno dos campos.
|
|
89
|
+
*
|
|
90
|
+
* @param {string} [textButton='Enviar'] Texto do botão principal.
|
|
91
|
+
* @param {TypographyVariant} [variantButton='body1'] Variante do Typography usada no texto do botão.
|
|
92
|
+
* @param {string} [backgroundButton='transparent'] Fundo do botão principal.
|
|
93
|
+
* @param {string} [backgroundHoverButton='transparent'] Fundo do botão no hover.
|
|
94
|
+
* @param {string} [colorButton='#000'] Cor do texto do botão.
|
|
95
|
+
* @param {string} [colorHoverButton='#000'] Cor do texto do botão no hover.
|
|
96
|
+
* @param {string} [borderRadiusButton='0'] Raio da borda do botão.
|
|
97
|
+
* @param {string} [borderButton='none'] Borda do botão.
|
|
98
|
+
* @param {string} [boxShadowButton='none'] Sombra do botão.
|
|
99
|
+
* @param {string} [widthButton='auto'] Largura do botão.
|
|
100
|
+
* @param {string} [heightButton='auto'] Altura do botão.
|
|
101
|
+
* @param {string} [paddingButton='4px 24px'] Padding do botão.
|
|
102
|
+
* @param {string} [marginButton='0'] Margem do botão.
|
|
103
|
+
*
|
|
104
|
+
* @param {string} color_message_sucess Cor padrão para mensagem de sucesso (caso `onClick` não retorne `color`). Obrigatório.
|
|
105
|
+
* @param {string} color_message_erro Cor padrão para mensagem de erro (caso `onClick` não retorne `color`). Obrigatório.
|
|
106
|
+
* @param {string} color_link Cor aplicada nos links "Esqueceu sua senha?" e "Criar conta". Obrigatório.
|
|
107
|
+
* @param {string} color_separador Cor da linha separadora (Divider). Obrigatório.
|
|
108
|
+
*
|
|
109
|
+
* @param {(data: { email: string; password: string }) => Promise<ClickResult> | ClickResult} [onClick]
|
|
110
|
+
* Handler chamado ao submeter o formulário. Recebe `{ email, password }` e deve retornar um `ClickResult`.
|
|
111
|
+
* - Se `success` for `true`, exibe `message` com `color_message_sucess` (ou `result.color` se fornecida)
|
|
112
|
+
* - Se `success` for `false`, exibe `message` com `color_message_erro` (ou `result.color` se fornecida)
|
|
113
|
+
* Se não for informado, o componente exibirá a mensagem: "Nenhuma ação foi configurada para o botão.".
|
|
114
|
+
*
|
|
115
|
+
* @param {React.ReactNode} [children] Conteúdo extra renderizado ao final do container (abaixo da mensagem).
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```tsx
|
|
119
|
+
* import LoginForm from '@/components/LoginForm';
|
|
120
|
+
* import LockOutlinedIcon from '@mui/icons-material/LockOutlined';
|
|
121
|
+
* import { Button } from '@mui/material';
|
|
122
|
+
*
|
|
123
|
+
* export default function Example() {
|
|
124
|
+
* return (
|
|
125
|
+
* <LoginForm
|
|
126
|
+
* urlRecuperarConta="/recuperar"
|
|
127
|
+
* urlCriarConta="/cadastro"
|
|
128
|
+
* Icon={LockOutlinedIcon}
|
|
129
|
+
* titulo={() => <h2>Entrar</h2>}
|
|
130
|
+
* googleButton={() => <Button variant="outlined">Continuar com Google</Button>}
|
|
131
|
+
* color="#111"
|
|
132
|
+
* background="#fff"
|
|
133
|
+
* borderRadius="12px"
|
|
134
|
+
* boxShadow="0 10px 30px rgba(0,0,0,0.08)"
|
|
135
|
+
* backgroundField="#fafafa"
|
|
136
|
+
* borderColorField="#e0e0e0"
|
|
137
|
+
* paddingField="10px 12px"
|
|
138
|
+
* textButton="Acessar"
|
|
139
|
+
* backgroundButton="#111"
|
|
140
|
+
* backgroundHoverButton="#000"
|
|
141
|
+
* colorButton="#fff"
|
|
142
|
+
* colorHoverButton="#fff"
|
|
143
|
+
* borderRadiusButton="10px"
|
|
144
|
+
* paddingButton="10px 16px"
|
|
145
|
+
* color_message_sucess="#1b5e20"
|
|
146
|
+
* color_message_erro="#b71c1c"
|
|
147
|
+
* color_link="#1976d2"
|
|
148
|
+
* color_separador="#e0e0e0"
|
|
149
|
+
* onClick={async ({ email, password }) => {
|
|
150
|
+
* if (email === 'teste@exemplo.com' && password === '123') {
|
|
151
|
+
* return { success: true, message: 'Login realizado com sucesso!' };
|
|
152
|
+
* }
|
|
153
|
+
* return { success: false, message: 'Email ou senha inválidos.' };
|
|
154
|
+
* }}
|
|
155
|
+
* />
|
|
156
|
+
* );
|
|
157
|
+
* }
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
28
160
|
declare const LoginForm: React.FC<LoginFormProps>;
|
|
29
161
|
export default LoginForm;
|