@processhub-lib/react 1.0.4 → 1.0.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.
Files changed (50) hide show
  1. package/dist/classnames-2Mts7qXW.js +29 -0
  2. package/dist/classnames-BqI3URgS.cjs +1 -0
  3. package/dist/index-B1vZ8U-f.cjs +88 -0
  4. package/dist/index-hkfwDYXz.js +3097 -0
  5. package/dist/index.cjs.js +1 -0
  6. package/dist/index.d.ts +3 -0
  7. package/dist/index.es.js +12 -0
  8. package/dist/scripts/generate-endpoints.d.ts +1 -0
  9. package/dist/style.css +1 -0
  10. package/dist/ui/Button/colors.d.ts +162 -0
  11. package/dist/ui/Button/index.d.ts +3 -0
  12. package/dist/ui/Button/types/button.d.ts +16 -0
  13. package/dist/ui/Input/index.d.ts +3 -0
  14. package/{src/ui/Input/types/input.ts → dist/ui/Input/types/input.d.ts} +6 -7
  15. package/dist/ui/Select/index.d.ts +3 -0
  16. package/dist/ui/Select/types/select.d.ts +17 -0
  17. package/dist/ui/index.d.ts +3 -0
  18. package/dist/ui.cjs.js +1 -0
  19. package/dist/ui.d.ts +1 -0
  20. package/dist/ui.es.js +6 -0
  21. package/dist/utils/applyMask.d.ts +9 -0
  22. package/dist/utils/classnames.d.ts +16 -0
  23. package/dist/utils/formatar.d.ts +62 -0
  24. package/dist/utils/index.d.ts +4 -0
  25. package/dist/utils/isDocumento.d.ts +11 -0
  26. package/dist/utils.cjs.js +1 -0
  27. package/dist/utils.d.ts +1 -0
  28. package/dist/utils.es.js +128 -0
  29. package/package.json +5 -1
  30. package/postcss.config.js +0 -5
  31. package/src/context/ThemeContext.tsx +0 -45
  32. package/src/index.ts +0 -4
  33. package/src/scripts/generate-endpoints.ts +0 -184
  34. package/src/style.css +0 -1
  35. package/src/ui/Button/colors.tsx +0 -163
  36. package/src/ui/Button/index.tsx +0 -45
  37. package/src/ui/Button/types/button.ts +0 -17
  38. package/src/ui/Input/index.tsx +0 -74
  39. package/src/ui/Select/index.tsx +0 -150
  40. package/src/ui/Select/types/select.ts +0 -16
  41. package/src/ui/index.ts +0 -3
  42. package/src/utils/applyMask.tsx +0 -49
  43. package/src/utils/classnames.tsx +0 -89
  44. package/src/utils/formatar.tsx +0 -173
  45. package/src/utils/index.ts +0 -4
  46. package/src/utils/isDocumento.tsx +0 -46
  47. package/tailwind.config.js +0 -13
  48. package/tsconfig.json +0 -26
  49. package/tsconfig.node.json +0 -10
  50. package/vite.config.ts +0 -31
@@ -1,49 +0,0 @@
1
- /**
2
- * Aplica uma máscara numérica ao valor informado.
3
- *
4
- * @param value - String com dígitos (ex: "12345678901")
5
- * @param tipo Opcional - Tipo de máscara ("cnpj" ou "cpf")
6
- * @param mask Opcional - Máscara no formato com 'x' para dígitos (ex: "xxx.xxx.xxx-xx")
7
- * @returns Valor formatado conforme máscara (ex: "123.456.789-01")
8
- */
9
- export function applyMask(
10
- value: string,
11
- tipo?: "cnpj" | "cpf" | "outro",
12
- mask?: string,
13
- ): string {
14
- if (tipo?.toLocaleLowerCase() === "cnpj") {
15
- return applyMask(value, "outro", "xx.xxx.xxx/xxxx-xx");
16
- }
17
-
18
- if (tipo?.toLocaleLowerCase() === "cpf") {
19
- return applyMask(value, "outro", "xxx.xxx.xxx-xx");
20
- }
21
-
22
- // Remove tudo que não for dígito
23
- const digits = value.replace(/\D/g, "");
24
- let result = "";
25
- let digitIndex = 0;
26
-
27
- if (mask) {
28
- for (let i = 0; i < mask.length; i++) {
29
- if (mask[i] === "x") {
30
- if (digitIndex < digits.length) {
31
- result += digits[digitIndex];
32
- digitIndex++;
33
- } else {
34
- // Se não tiver mais dígitos, não adiciona nada, mas não coloca os caracteres fixos
35
- break;
36
- }
37
- } else {
38
- // Adiciona o caractere fixo apenas se houver dígito correspondente depois dele
39
- if (digitIndex < digits.length) {
40
- result += mask[i];
41
- } else {
42
- break;
43
- }
44
- }
45
- }
46
- }
47
-
48
- return result;
49
- }
@@ -1,89 +0,0 @@
1
- const hasOwn = {}.hasOwnProperty;
2
-
3
- /**
4
- * Constrói uma string de classes CSS dinamicamente.
5
- *
6
- * Aceita qualquer número de argumentos do tipo string, boolean, null, undefined ou objeto:
7
- * - Strings são adicionadas diretamente.
8
- * - Objetos: chaves com valor truthy são incluídas como classes.
9
- * - Arrays são processados recursivamente.
10
- *
11
- * @example
12
- * classnames("btn", { active: isActive, disabled: false }, ["px-2", null])
13
- * // Resultado: "btn active px-2"
14
- *
15
- * @param {...(string | object | undefined | null | boolean)[]} args - Lista de classes e condições.
16
- * @returns {string} String final de classes separadas por espaço.
17
- */
18
- export function classnames(
19
- ...args: (string | object | undefined | null | boolean)[]
20
- ): string {
21
- let classes = "";
22
- for (let i = 0; i < args.length; i++) {
23
- const arg = args[i];
24
- if (arg) {
25
- classes = appendClass(classes, parseValue(arg));
26
- }
27
- }
28
-
29
- return classes;
30
- }
31
-
32
- /**
33
- * Converte um argumento em string de classes.
34
- *
35
- * - Strings são retornadas como estão.
36
- * - Objetos: inclui chaves com valor truthy.
37
- * - Arrays: processados recursivamente.
38
- *
39
- * @param arg - Argumento a ser processado.
40
- * @returns String de classes ou vazia.
41
- */
42
- function parseValue(arg: string | object | undefined | null | boolean): string {
43
- if (typeof arg === "string") {
44
- return arg;
45
- }
46
-
47
- if (typeof arg !== "object" || arg === null) {
48
- return "";
49
- }
50
-
51
- // Processa array de classes
52
- if (Array.isArray(arg)) {
53
- return classnames(...arg);
54
- }
55
-
56
- // Suporte a objetos com `toString()` customizados (não nativos)
57
- if (
58
- arg.toString !== Object.prototype.toString &&
59
- !arg.toString.toString().includes("[native code]")
60
- ) {
61
- return arg.toString();
62
- }
63
-
64
- // Processa objetos: adiciona chave se valor for truthy
65
- let classes = "";
66
-
67
- for (const key in arg) {
68
- if (hasOwn.call(arg, key) && (arg as Record<string, unknown>)[key]) {
69
- classes = appendClass(classes, key);
70
- }
71
- }
72
-
73
- return classes;
74
- }
75
-
76
- /**
77
- * Concatena duas strings de classe com espaço.
78
- *
79
- * @param value - String atual.
80
- * @param newClass - Nova classe a ser adicionada.
81
- * @returns String combinada.
82
- */
83
- function appendClass(value: string, newClass: string): string {
84
- if (!newClass) {
85
- return value;
86
- }
87
-
88
- return value ? `${value} ${newClass}` : newClass;
89
- }
@@ -1,173 +0,0 @@
1
-
2
- /**
3
- * @file formatar.tsx
4
- * @description Utilitário unificado para formatação de dados (Data, Massa, Moeda, Porcentagem).
5
- * Este módulo não possui dependências externas.
6
- */
7
-
8
- /** Unidades de massa suportadas para conversão e exibição */
9
- export type UnidadeMassa = "kg" | "t" | "kt" | "Mt";
10
-
11
- /** Fatores de conversão de massa tendo kg como base */
12
- const MASSA_FATOR: Record<UnidadeMassa, number> = {
13
- kg: 1,
14
- t: 1_000,
15
- kt: 1_000_000,
16
- Mt: 1_000_000_000,
17
- };
18
-
19
- /** Tipos de formatação disponíveis no sistema */
20
- export type TipoFormato = "data" | "massa" | "moeda" | "porcentagem";
21
-
22
- /**
23
- * Interface para as opções de configuração dos formatadores.
24
- * Permite personalizar a exibição de acordo com o tipo de dado.
25
- *
26
- * @property formato - Template para formatação de data (ex: "DD/MM/YYYY", "YYYY-MM-DD HH:mm"). Padrão: "DD/MM/YYYY"
27
- * @property unidade - Unidade de massa para conversão/exibição. Padrão: "t"
28
- * @property locale - Localidade para Intl (ex: "pt-BR", "en-US"). Padrão: "pt-BR"
29
- * @property minimumFractionDigits - Mínimo de casas decimais.
30
- * @property maximumFractionDigits - Máximo de casas decimais.
31
- * @property currency - Moeda para formatação monetária (ex: "BRL", "USD"). Padrão: "BRL"
32
- * @property notation - Notação numérica (standard, scientific, engineering, compact).
33
- * @property compactDisplay - Exibição compacta (short, long).
34
- */
35
- export interface FormatarOptions {
36
- formato?: string;
37
- unidade?: UnidadeMassa;
38
- locale?: string;
39
- minimumFractionDigits?: number;
40
- maximumFractionDigits?: number;
41
- currency?: string;
42
- notation?: "standard" | "scientific" | "engineering" | "compact";
43
- compactDisplay?: "short" | "long";
44
- }
45
-
46
- /**
47
- * Método unificado para formatação de diversos tipos de dados no sistema.
48
- * Suporta datas (nativamente), massa, moeda e porcentagem.
49
- *
50
- * @param tipo - O tipo de dado a ser formatado ("data", "massa", "moeda", "porcentagem")
51
- * @param valor - O valor bruto (String, Number ou Date)
52
- * @param opcoes - Opções de customização (locale, formato, unidade, etc)
53
- * @returns String formatada seguindo as regras do tipo e localidade
54
- *
55
- * @example
56
- * // Formatação de Moeda
57
- * formatar("moeda", 1500.5) // "R$ 1.500,50"
58
- * formatar("moeda", 1500.5, { notation: "compact" }) // "1,5 mil R$"
59
- *
60
- * @example
61
- * // Formatação de Data
62
- * formatar("data", new Date()) // "19/03/2026"
63
- * formatar("data", "2026-12-25", { formato: "DD/MM" }) // "25/12"
64
- * formatar("data", "25/12/2026 15:30", { formato: "YYYY-MM-DD HH:mm" }) // "2026-12-25 15:30"
65
- *
66
- * @example
67
- * // Formatação de Massa
68
- * formatar("massa", 5000) // "5,0000 t"
69
- * formatar("massa", 5000, { unidade: "kg" }) // "5.000,0000 kg"
70
- *
71
- * @example
72
- * // Formatação de Porcentagem
73
- * formatar("porcentagem", 75.5) // "75,5%"
74
- * formatar("porcentagem", 100) // "100%"
75
- */export const formatar = (
76
- tipo: TipoFormato,
77
- valor: any,
78
- opcoes: FormatarOptions = {},
79
- ): string => {
80
- const {
81
- locale = "pt-BR",
82
- formato = "DD/MM/YYYY",
83
- unidade = "t",
84
- minimumFractionDigits,
85
- maximumFractionDigits,
86
- currency = "BRL",
87
- } = opcoes;
88
-
89
- /** Converte valores para número, tratando vírgulas de strings como ponto decimal */
90
- const parseNumber = (v: any): number => {
91
- if (typeof v === "number") return v;
92
- if (typeof v === "string") return Number(v.replace(",", "."));
93
- return NaN;
94
- };
95
-
96
- switch (tipo) {
97
- case "data": {
98
- if (!valor) return "";
99
-
100
- const parseDate = (v: any): Date => {
101
- if (v instanceof Date) return v;
102
- if (typeof v === "string") {
103
- const match = v.match(
104
- /^(\d{2})\/(\d{2})\/(\d{4})(?: (\d{2}):(\d{2})(?::(\d{2}))?)?$/,
105
- );
106
- if (match) {
107
- const y = Number(match[3]);
108
- const m = Number(match[2]) - 1;
109
- const day = Number(match[1]);
110
- const h = Number(match[4] || 0);
111
- const min = Number(match[5] || 0);
112
- const s = Number(match[6] || 0);
113
- return new Date(y, m, day, h, min, s);
114
- }
115
- }
116
- return new Date(v);
117
- };
118
-
119
- const d = parseDate(valor);
120
- if (isNaN(d.getTime())) return "";
121
-
122
- const pad = (n: number) => String(n).padStart(2, "0");
123
- const tokens: Record<string, string> = {
124
- YYYY: String(d.getFullYear()),
125
- YY: String(d.getFullYear()).slice(-2),
126
- MM: pad(d.getMonth() + 1),
127
- DD: pad(d.getDate()),
128
- HH: pad(d.getHours()),
129
- mm: pad(d.getMinutes()),
130
- ss: pad(d.getSeconds()),
131
- };
132
-
133
- return formato.replace(
134
- /YYYY|YY|MM|DD|HH|mm|ss/g,
135
- (match) => tokens[match],
136
- );
137
- }
138
- case "massa": {
139
- const num = parseNumber(valor);
140
- if (isNaN(num)) return "Valor inválido";
141
- const valorConvertido = num / MASSA_FATOR[unidade];
142
- const formatado = new Intl.NumberFormat(locale, {
143
- minimumFractionDigits: minimumFractionDigits ?? 4,
144
- maximumFractionDigits: maximumFractionDigits ?? 4,
145
- }).format(valorConvertido);
146
- return `${formatado} ${unidade}`;
147
- }
148
-
149
- case "moeda": {
150
- const num = parseNumber(valor);
151
- if (isNaN(num)) return "Valor inválido";
152
- return new Intl.NumberFormat(locale, {
153
- notation: opcoes.notation ?? "standard",
154
- compactDisplay: opcoes.compactDisplay ?? "short",
155
- style: "currency",
156
- currency,
157
- }).format(num);
158
- }
159
-
160
- case "porcentagem": {
161
- const num = parseNumber(valor);
162
- if (isNaN(num)) return "0%";
163
- return new Intl.NumberFormat(locale, {
164
- style: "percent",
165
- minimumFractionDigits: minimumFractionDigits ?? 0,
166
- maximumFractionDigits: maximumFractionDigits ?? 1,
167
- }).format(num / 100);
168
- }
169
-
170
- default:
171
- return String(valor);
172
- }
173
- };
@@ -1,4 +0,0 @@
1
- export * from "./classnames";
2
- export * from "./applyMask";
3
- export * from "./isDocumento";
4
- export * from "./formatar";
@@ -1,46 +0,0 @@
1
- /**
2
- * Valida CPF ou CNPJ de forma unificada, identificando automaticamente o tipo pelo tamanho.
3
- *
4
- * @param documento - CPF ou CNPJ com ou sem formatação.
5
- * @returns `true` se válido, `false` caso contrário.
6
- *
7
- * @example
8
- * isDocumento("123.456.789-00") // true ou false
9
- * isDocumento("12.345.678/0001-90") // true ou false
10
- */
11
- export function isDocumento(documento: string): boolean {
12
- const doc = documento.replace(/[^\d]+/g, "");
13
-
14
- // Elimina documentos com todos os dígitos iguais
15
- if (/^(\d)\1+$/.test(doc)) return false;
16
-
17
- // Validação de CPF
18
- if (doc.length === 11) {
19
- for (let j = 9; j <= 10; j++) {
20
- let soma = 0;
21
- for (let i = 0; i < j; i++) {
22
- soma += parseInt(doc.charAt(i)) * (j + 1 - i);
23
- }
24
- let resto = (soma * 10) % 11;
25
- if (resto === 10 || resto === 11) resto = 0;
26
- if (resto !== parseInt(doc.charAt(j))) return false;
27
- }
28
- return true;
29
- }
30
-
31
- // Validação de CNPJ
32
- if (doc.length === 14) {
33
- const b = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];
34
- for (let i = 12; i <= 13; i++) {
35
- let n = 0;
36
- for (let j = 0; j < i; j++) {
37
- n += parseInt(doc.charAt(j)) * b[j + 13 - i];
38
- }
39
- const resultado = (n %= 11) < 2 ? 0 : 11 - n;
40
- if (parseInt(doc.charAt(i)) !== resultado) return false;
41
- }
42
- return true;
43
- }
44
-
45
- return false;
46
- }
@@ -1,13 +0,0 @@
1
- /** @type {import('tailwindcss').Config} */
2
- export default {
3
- prefix: "ph-",
4
- content: [
5
- "./index.html",
6
- "./src/**/*.{js,ts,jsx,tsx}",
7
- "../processhub-lib/src/**/*.{js,ts,jsx,tsx}",
8
- ],
9
- theme: {
10
- extend: {},
11
- },
12
- plugins: [],
13
- };
package/tsconfig.json DELETED
@@ -1,26 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2020",
4
- "useDefineForClassFields": true,
5
- "lib": ["ES2020", "DOM", "DOM.Iterable"],
6
- "module": "ESNext",
7
- "skipLibCheck": true,
8
-
9
- /* Bundler mode */
10
- "moduleResolution": "bundler",
11
- "allowImportingTsExtensions": true,
12
- "resolveJsonModule": true,
13
- "isolatedModules": true,
14
- "noEmit": true,
15
- "jsx": "react-jsx",
16
-
17
- /* Linting */
18
- "strict": true,
19
- "noUnusedLocals": true,
20
- "noUnusedParameters": true,
21
- "noFallthroughCasesInSwitch": true,
22
- "declaration": true
23
- },
24
- "include": ["src"],
25
- "references": [{ "path": "./tsconfig.node.json" }]
26
- }
@@ -1,10 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "composite": true,
4
- "skipLibCheck": true,
5
- "module": "ESNext",
6
- "moduleResolution": "bundler",
7
- "allowSyntheticDefaultImports": true
8
- },
9
- "include": ["vite.config.ts"]
10
- }
package/vite.config.ts DELETED
@@ -1,31 +0,0 @@
1
- import { defineConfig } from "vite";
2
- import path from "path";
3
- import tailwindcss from "@tailwindcss/vite";
4
- import dts from "vite-plugin-dts";
5
-
6
- export default defineConfig({
7
- build: {
8
- lib: {
9
- entry: {
10
- index: path.resolve(__dirname, "src/index.ts"),
11
- ui: path.resolve(__dirname, "src/ui/index.ts"),
12
- utils: path.resolve(__dirname, "src/utils/index.ts"),
13
- },
14
- name: "ProcessHubLib",
15
- formats: ["es", "cjs"],
16
- fileName: (format, entryName) => `${entryName}.${format}.js`,
17
- },
18
- rollupOptions: {
19
- external: ["react", "react-dom"],
20
- output: {
21
- globals: { react: "React" },
22
- },
23
- },
24
- },
25
- plugins: [
26
- tailwindcss(),
27
- dts({
28
- insertTypesEntry: true,
29
- }),
30
- ],
31
- });