@grazziotin/react-components 1.0.0
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/.editorconfig +13 -0
- package/.eslintignore +3 -0
- package/.eslintrc.json +16 -0
- package/.prettierrc +6 -0
- package/.vscode/settings.json +18 -0
- package/README.md +1 -0
- package/dist/components/Inputs/Input/constants.d.ts +1 -0
- package/dist/components/Inputs/Input/constants.js +1 -0
- package/dist/components/Inputs/Input/index.d.ts +20 -0
- package/dist/components/Inputs/Input/index.js +59 -0
- package/dist/functions/mascaras/index.d.ts +169 -0
- package/dist/functions/mascaras/index.js +381 -0
- package/dist/hooks/index.d.ts +20 -0
- package/dist/hooks/index.js +49 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.LICENSE.txt +28 -0
- package/dist/lib/utils.d.ts +2 -0
- package/dist/lib/utils.js +9 -0
- package/dist/styles/sx.d.ts +106 -0
- package/dist/styles/sx.js +143 -0
- package/package.json +216 -0
- package/src/components/Inputs/Input/constants.ts +25 -0
- package/src/components/Inputs/Input/index.tsx +94 -0
- package/src/env.d.ts +16 -0
- package/src/functions/mascaras/index.ts +432 -0
- package/src/hooks/index.ts +60 -0
- package/src/index.tsx +2 -0
- package/src/lib/utils.ts +6 -0
- package/src/styles/sx.ts +148 -0
- package/tailwind.config.js +234 -0
- package/tsconfig.json +37 -0
- package/webpack.config.js +32 -0
package/.editorconfig
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# EditorConfig is awesome: https://EditorConfig.org
|
|
2
|
+
|
|
3
|
+
# top-most EditorConfig file
|
|
4
|
+
root = true
|
|
5
|
+
|
|
6
|
+
[*]
|
|
7
|
+
indent_style = space
|
|
8
|
+
indent_size = 2
|
|
9
|
+
insert_final_newline = true
|
|
10
|
+
end_of_line = crlf
|
|
11
|
+
charset = utf-8
|
|
12
|
+
trim_trailing_whitespace = false
|
|
13
|
+
insert_final_newline = false
|
package/.eslintignore
ADDED
package/.eslintrc.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"plugins": [
|
|
3
|
+
"@tanstack/query"
|
|
4
|
+
],
|
|
5
|
+
"extends": [
|
|
6
|
+
"@rocketseat/eslint-config/react",
|
|
7
|
+
"plugin:@tanstack/eslint-plugin-query/recommended"
|
|
8
|
+
],
|
|
9
|
+
"rules": {
|
|
10
|
+
"@typescript-eslint/no-explicit-any": "off",
|
|
11
|
+
"@typescript-eslint/no-unused-vars": "warn",
|
|
12
|
+
"@tanstack/query/exhaustive-deps": "warn",
|
|
13
|
+
"@tanstack/query/no-rest-destructuring": "warn",
|
|
14
|
+
"@tanstack/query/stable-query-client": "warn"
|
|
15
|
+
}
|
|
16
|
+
}
|
package/.prettierrc
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"editor.tabSize": 2,
|
|
3
|
+
"files.eol": "\r\n",
|
|
4
|
+
"workbench.colorCustomizations": {
|
|
5
|
+
"activityBar.background": "#6a1b9a",
|
|
6
|
+
"titleBar.activeBackground": "#6a1b9a",
|
|
7
|
+
"titleBar.inactiveBackground": "#6a1b9a",
|
|
8
|
+
"titleBar.activeForeground": "#ffffff"
|
|
9
|
+
},
|
|
10
|
+
"eslint.format.enable": true,
|
|
11
|
+
"[typescriptreact]": {
|
|
12
|
+
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
|
|
13
|
+
},
|
|
14
|
+
"editor.formatOnSave": true,
|
|
15
|
+
"[typescript]": {
|
|
16
|
+
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
|
|
17
|
+
}
|
|
18
|
+
}
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# react-components
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type InputPropsCustomTypes = 'button' | 'checkbox' | 'color' | 'date' | 'datetime-local' | 'email' | 'file' | 'hidden' | 'image' | 'month' | 'number' | 'password' | 'radio' | 'range' | 'reset' | 'search' | 'submit' | 'tel' | 'text' | 'time' | 'url' | 'week' | 'float' | 'real';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { TextFieldProps } from '@mui/material';
|
|
2
|
+
import { InputPropsCustomTypes } from './constants';
|
|
3
|
+
export type InputProps = TextFieldProps & {
|
|
4
|
+
shrink?: boolean;
|
|
5
|
+
readOnly?: boolean;
|
|
6
|
+
xs?: number;
|
|
7
|
+
onKeyEnter?: () => void;
|
|
8
|
+
order?: number;
|
|
9
|
+
render?: boolean;
|
|
10
|
+
qtdSolicitada?: number;
|
|
11
|
+
qtdSeparada?: number;
|
|
12
|
+
onQtdSeparadaChange?: (newValue: number) => void;
|
|
13
|
+
type?: InputPropsCustomTypes;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Input personalizado Mui
|
|
17
|
+
* @version 2.0.1
|
|
18
|
+
* @ViniciusCLoeblein
|
|
19
|
+
*/
|
|
20
|
+
export default function Input({ shrink, readOnly, onKeyEnter, size, type, ...rest }: Readonly<InputProps>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
+
var t = {};
|
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
+
t[p] = s[p];
|
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
+
t[p[i]] = s[p[i]];
|
|
20
|
+
}
|
|
21
|
+
return t;
|
|
22
|
+
};
|
|
23
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
24
|
+
import { TextField, ThemeProvider } from '@mui/material';
|
|
25
|
+
import { sx, standard, theme } from 'src/styles/sx';
|
|
26
|
+
import { cn } from 'src/lib/utils';
|
|
27
|
+
import { limitDecimais, mascaradorInputMoeda } from 'src/functions/mascaras';
|
|
28
|
+
/**
|
|
29
|
+
* Input personalizado Mui
|
|
30
|
+
* @version 2.0.1
|
|
31
|
+
* @ViniciusCLoeblein
|
|
32
|
+
*/
|
|
33
|
+
export default function Input(_a) {
|
|
34
|
+
var shrink = _a.shrink, readOnly = _a.readOnly, onKeyEnter = _a.onKeyEnter, _b = _a.size, size = _b === void 0 ? 'small' : _b, _c = _a.type, type = _c === void 0 ? 'text' : _c, rest = __rest(_a, ["shrink", "readOnly", "onKeyEnter", "size", "type"]);
|
|
35
|
+
function onEnter(e) {
|
|
36
|
+
if (e.key === 'Enter' && onKeyEnter) {
|
|
37
|
+
onKeyEnter();
|
|
38
|
+
}
|
|
39
|
+
rest.onKeyDown && rest.onKeyDown(e);
|
|
40
|
+
}
|
|
41
|
+
var handleChange = function (e) {
|
|
42
|
+
var value = e.target.value;
|
|
43
|
+
if (['real', 'float'].includes(type)) {
|
|
44
|
+
value = value.replace(',', '.');
|
|
45
|
+
if (type === 'real') {
|
|
46
|
+
value = mascaradorInputMoeda(value);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
value = limitDecimais(value, 8);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
rest.onChange &&
|
|
53
|
+
rest.onChange(__assign(__assign({}, e), { target: __assign(__assign({}, e.target), { value: value }) }));
|
|
54
|
+
};
|
|
55
|
+
var InputProps = __assign({ readOnly: readOnly }, rest.InputProps);
|
|
56
|
+
return (_jsx(ThemeProvider, { theme: theme, children: _jsx(TextField, __assign({}, rest, { sx: rest.variant === 'standard' ? standard : sx, onKeyDown: onEnter, InputLabelProps: __assign(__assign({}, rest.InputLabelProps), { shrink: shrink }), InputProps: InputProps, size: size, className: cn('select-none', rest.className), type: ['real', 'float'].includes(type) ? 'text' : type, onChange: handleChange, inputProps: __assign(__assign({}, rest.inputProps), { step: (type === 'real' && '0.01') ||
|
|
57
|
+
(type === 'float' && '0.0000001') ||
|
|
58
|
+
'1' }) })) }));
|
|
59
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
interface MascaradorCPFCNPJProps {
|
|
2
|
+
v: string | number;
|
|
3
|
+
autoComplete?: boolean;
|
|
4
|
+
ignoreCNPJ?: boolean;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Função para formatar um CPF ou CNPJ, adicionando as pontuações adequadas.
|
|
8
|
+
*
|
|
9
|
+
* @param {string} v - O valor do CPF ou CNPJ a ser formatado (como string ou number).
|
|
10
|
+
* @returns {string} O valor formatado com as pontuações de CPF ou CNPJ.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const cpfCnpjFormatado = mascaradorCPFCNPJ('12345678901'); // Retorna '123.456.789-01'
|
|
14
|
+
* @author Flaviasoz, Nicolasfmc
|
|
15
|
+
* @version 1.6.0
|
|
16
|
+
*/
|
|
17
|
+
export declare const mascaradorCPFCNPJ: ({ v, autoComplete, ignoreCNPJ, }: MascaradorCPFCNPJProps) => string;
|
|
18
|
+
/**
|
|
19
|
+
* Função para formatar um número de telefone, adicionando as pontuações adequadas.
|
|
20
|
+
*
|
|
21
|
+
* @param {string | number} v - O número de telefone a ser formatado (como string ou number).
|
|
22
|
+
* @returns {string} O número de telefone formatado com as pontuações adequadas.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* const telefoneFormatado = mascaradorTelefone('1234567890'); // Retorna '(12) 3456-7890'
|
|
26
|
+
* @author Flaviasoz
|
|
27
|
+
* @version 1.2.0
|
|
28
|
+
*/
|
|
29
|
+
export declare const mascaradorTelefone: (v: string | number) => string;
|
|
30
|
+
/**
|
|
31
|
+
* Função para adicionar pontos de separação de milhar em um número.
|
|
32
|
+
*
|
|
33
|
+
* @param {string | number} valor - O valor numérico a ser formatado com pontos de separação de milhar.
|
|
34
|
+
* @returns {string} - O valor formatado com pontos de separação de milhar.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* const numeroFormatado = mascaradorMilhar(1234567); // Retorna '1.234.567'
|
|
38
|
+
* @author Flaviasoz
|
|
39
|
+
* @version 1.0.0
|
|
40
|
+
*/
|
|
41
|
+
export declare const mascaradorMilhar: (valor: string | number) => string;
|
|
42
|
+
/**
|
|
43
|
+
* Função para adicionar pontos de separação de milhar e decimais em um número.
|
|
44
|
+
*
|
|
45
|
+
* @param {string | number} v - O valor numérico a ser formatado com pontos de separação de milhar.
|
|
46
|
+
* @returns {string} - O valor formatado com pontos de separação de milhar e duas casas decimais após a vírgula.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* const numeroFormatado = mascaradorMilharDecimal(1234567); // Retorna '1.234.567,00'
|
|
50
|
+
* @author Nicolasfmc
|
|
51
|
+
* @version 1.0.0
|
|
52
|
+
*/
|
|
53
|
+
export declare const mascaradorMilharDecimal: (v: string | number) => string;
|
|
54
|
+
/**
|
|
55
|
+
* Função para formatar um valor numérico como moeda brasileira (BRL).
|
|
56
|
+
*
|
|
57
|
+
* @param {string | number} v - O valor a ser formatado como moeda brasileira.
|
|
58
|
+
* @returns {string} O valor formatado como moeda brasileira (BRL), no formato de string.
|
|
59
|
+
* @example
|
|
60
|
+
* style: 'currency', // Estilo de formatação de moeda
|
|
61
|
+
* currency: 'BRL', // Tipo de moeda (Real brasileiro)
|
|
62
|
+
* const valorFormatado = mascaradorValorReal(12345.67); // Retorna 'R$ 12.345,67'
|
|
63
|
+
* @author Flaviasoz
|
|
64
|
+
* @version 1.0.0
|
|
65
|
+
*/
|
|
66
|
+
export declare const mascaradorValorReal: (v?: string | number | null) => string;
|
|
67
|
+
/**
|
|
68
|
+
* Função para formatar uma data no formato 'YYYY-MM-DD' para 'DD/MM/YYYY'.
|
|
69
|
+
*
|
|
70
|
+
* @param {Date | string} data - A data a ser formatada (como objeto Date ou string).
|
|
71
|
+
* @returns {string} A data formatada no formato 'DD/MM/YYYY' ou '' se a entrada for inválida.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* const dataFormatada = formatarDataBR('2021-09-26'); // Retorna '26/09/2021'
|
|
75
|
+
* @author Flaviasoz
|
|
76
|
+
* @version 1.0.0
|
|
77
|
+
*/
|
|
78
|
+
export declare function formatarDataBR(data: Date | string): string;
|
|
79
|
+
/**
|
|
80
|
+
* Função para formatar uma data no formato 'yyyy-mm' e um dia para 'DD/MM/YYYY'.
|
|
81
|
+
*
|
|
82
|
+
* @param {string} anoMes - A string no formato 'yyyy-mm'.
|
|
83
|
+
* @param {string} [dia='01'] - A string representando o dia (opcional, padrão é '01' se não informado).
|
|
84
|
+
* @returns {string} A data formatada no formato 'DD/MM/YYYY' ou '' se a entrada for inválida.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* const dataFormatada = formatarMesAno('2023-01'); // Retorna '01/01/2023'
|
|
88
|
+
* const dataFormatadaComDia = formatarMesAno('2023-01', '10'); // Retorna '10/01/2023'
|
|
89
|
+
* @author Nicolasfmc
|
|
90
|
+
* @version 1.1.0
|
|
91
|
+
*/
|
|
92
|
+
export declare function formatarMesAno(anoMes: string, dia?: string): string;
|
|
93
|
+
/**
|
|
94
|
+
* Formata um valor numérico para uma string no formato de moeda brasileira (BRL).
|
|
95
|
+
*
|
|
96
|
+
* @param {string} v - Valor numérico a ser formatado.
|
|
97
|
+
* @returns {string} - Valor formatado como moeda brasileira.
|
|
98
|
+
* @example
|
|
99
|
+
* const valorFormatado = mascaradorInputMoeda('123456'); // Resultado: 'R$ 1.234,56'
|
|
100
|
+
* @author Flaviasoz
|
|
101
|
+
* @version 1.0.0
|
|
102
|
+
*/
|
|
103
|
+
export declare function mascaradorInputMoeda(v: string): string;
|
|
104
|
+
/**
|
|
105
|
+
* Converte uma string formatada como moeda brasileira para um número decimal.
|
|
106
|
+
*
|
|
107
|
+
* @param {string} valor - String no formato de moeda brasileira a ser convertida.
|
|
108
|
+
* @returns {number} - Valor convertido para número decimal.
|
|
109
|
+
* @example
|
|
110
|
+
* const valorDecimal = formatarInputMoedaFloat('R$1.234,56'); // Resultado: 1234.56
|
|
111
|
+
* @author Flaviasoz
|
|
112
|
+
* @version 1.0.0
|
|
113
|
+
*/
|
|
114
|
+
export declare function formatarInputMoedaFloat(valor: string): number;
|
|
115
|
+
/**
|
|
116
|
+
* Função para formatar uma string numérica no formato '00.00.00.0.000'.
|
|
117
|
+
*
|
|
118
|
+
* @param {string} v - A string numérica a ser formatada.
|
|
119
|
+
* @returns {string} A string formatada no formato '00.00.00.0.000'.
|
|
120
|
+
* @example
|
|
121
|
+
* const stringFormatada = formatarStringNumerica('1234567890'); // Retorna '12.34.56.7.890'
|
|
122
|
+
* @author Nicolasfmc
|
|
123
|
+
* @version 1.0.0
|
|
124
|
+
*/
|
|
125
|
+
export declare function mascaradorCodItem(v?: string | undefined): string | undefined;
|
|
126
|
+
/**
|
|
127
|
+
* Função para formatar uma string numérica no formato dinâmico até '50.50.20.20.5.510'.
|
|
128
|
+
*
|
|
129
|
+
* @param {string} v - A string numérica a ser formatada.
|
|
130
|
+
* @returns {string} A string formatada dinamicamente conforme o número de dígitos.
|
|
131
|
+
* @example
|
|
132
|
+
* const stringFormatada = mascaradorCodItemRede('1010'); // Retorna '10.10'
|
|
133
|
+
* const stringFormatadaComNoveDigitos = mascaradorCodItemRede('505020205'); // Retorna '50.50.20.20.5'
|
|
134
|
+
* const stringFormatadaComDozeDigitos = mascaradorCodItemRede('505020205510'); // Retorna '50.50.20.20.5.510'
|
|
135
|
+
* @author Flaviasoz
|
|
136
|
+
* @version 1.0.1
|
|
137
|
+
*/
|
|
138
|
+
export declare function mascaradorCodItemRede(v: string): string;
|
|
139
|
+
/**
|
|
140
|
+
* Formata uma data para uma string no formato 'dia de mês de ano, hora'.
|
|
141
|
+
*
|
|
142
|
+
* @param {Date} data - A data a ser formatada.
|
|
143
|
+
* @returns {string} A data formatada no formato 'dia de mês de ano, hora'.
|
|
144
|
+
* @author Flaviasoz
|
|
145
|
+
*/
|
|
146
|
+
export declare function formatarDataParaString(data: Date): string;
|
|
147
|
+
/**
|
|
148
|
+
* Mascara um CPF, adicionando pontos e traço.
|
|
149
|
+
*
|
|
150
|
+
* @param {string} cpf - O CPF a ser mascarado.
|
|
151
|
+
* @param {boolean} autoComplete - Indica se deve completar com zeros à esquerda.
|
|
152
|
+
* @returns {string} O CPF mascarado.
|
|
153
|
+
*/
|
|
154
|
+
interface MascararCPF {
|
|
155
|
+
cpfCnpj: string | number;
|
|
156
|
+
autoComplete?: boolean;
|
|
157
|
+
}
|
|
158
|
+
export declare function mascararCPF({ cpfCnpj, autoComplete, }: MascararCPF): string;
|
|
159
|
+
/**
|
|
160
|
+
* Mascara um CNPJ, adicionando pontos, barra e traço.
|
|
161
|
+
*
|
|
162
|
+
* @param {string} cnpj - O CNPJ a ser mascarado.
|
|
163
|
+
* @param {boolean} autoComplete - Indica se deve completar com zeros à esquerda.
|
|
164
|
+
* @returns {string} O CNPJ mascarado.
|
|
165
|
+
*/
|
|
166
|
+
export declare function mascararCNPJ({ cpfCnpj, autoComplete, }: MascararCPF): string;
|
|
167
|
+
export declare function formatValuesToMoney<T>(obj: T, fieldsToFormat: (keyof T)[]): T;
|
|
168
|
+
export declare function limitDecimais(value: string, limit: number): string;
|
|
169
|
+
export {};
|