@visiion/forms-library 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/README.md +261 -0
- package/dist/components/Common/NavigationButton.d.ts +4 -0
- package/dist/components/Common/index.d.ts +1 -0
- package/dist/components/Forms/GenericForm.d.ts +12 -0
- package/dist/components/Forms/index.d.ts +1 -0
- package/dist/components/Inputs/Alert.d.ts +12 -0
- package/dist/components/Inputs/CheckboxInput.d.ts +10 -0
- package/dist/components/Inputs/DynamicInput.d.ts +10 -0
- package/dist/components/Inputs/InputWrapper.d.ts +4 -0
- package/dist/components/Inputs/RutInput.d.ts +15 -0
- package/dist/components/Inputs/SelectInput.d.ts +10 -0
- package/dist/components/Inputs/TextInput.d.ts +10 -0
- package/dist/components/Inputs/TextareaInput.d.ts +20 -0
- package/dist/components/Inputs/index.d.ts +8 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.esm.js +2822 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +2840 -0
- package/dist/index.js.map +1 -0
- package/dist/types/index.d.ts +118 -0
- package/dist/utils/rut.d.ts +13 -0
- package/dist/utils/validationSchemas.d.ts +8 -0
- package/package.json +73 -0
package/README.md
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
# @visiion/forms-library
|
|
2
|
+
|
|
3
|
+
Una librería de componentes de formularios reutilizables construida con React y TypeScript, diseñada para crear formularios dinámicos y flexibles.
|
|
4
|
+
|
|
5
|
+
## Instalación
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm install @visiion/forms-library
|
|
9
|
+
# o
|
|
10
|
+
npm install @visiion/forms-library
|
|
11
|
+
# o
|
|
12
|
+
yarn add @visiion/forms-library
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Características
|
|
16
|
+
|
|
17
|
+
- 📝 **Formularios dinámicos**: Crea formularios basados en configuración JSON
|
|
18
|
+
- 🎨 **Componentes personalizables**: Estilos con Tailwind CSS
|
|
19
|
+
- ✅ **Validación integrada**: Validación con Yup
|
|
20
|
+
- 🧩 **Modular**: Usa solo los componentes que necesites
|
|
21
|
+
- 🇨🇱 **Soporte para RUT**: Validación y formateo de RUT chileno
|
|
22
|
+
- 📱 **Responsive**: Diseño adaptable a diferentes pantallas
|
|
23
|
+
- 🔧 **TypeScript**: Tipado completo para mejor DX
|
|
24
|
+
|
|
25
|
+
## Uso Básico
|
|
26
|
+
|
|
27
|
+
### GenericForm
|
|
28
|
+
|
|
29
|
+
El componente principal para crear formularios dinámicos:
|
|
30
|
+
|
|
31
|
+
```tsx
|
|
32
|
+
import React from 'react';
|
|
33
|
+
import { GenericForm, IFormConfig } from '@visiion/forms-library';
|
|
34
|
+
|
|
35
|
+
const config: IFormConfig = {
|
|
36
|
+
id: 'example-form',
|
|
37
|
+
title: 'Formulario de Ejemplo',
|
|
38
|
+
subtitle: 'Complete la información solicitada',
|
|
39
|
+
fields: [
|
|
40
|
+
{
|
|
41
|
+
id: 'name',
|
|
42
|
+
name: 'name',
|
|
43
|
+
type: 'text',
|
|
44
|
+
label: 'Nombre completo',
|
|
45
|
+
placeholder: 'Ingrese su nombre',
|
|
46
|
+
required: true,
|
|
47
|
+
validations: [
|
|
48
|
+
{ type: 'required', params: ['El nombre es requerido'] },
|
|
49
|
+
{ type: 'min', params: ['3', 'Mínimo 3 caracteres'] }
|
|
50
|
+
]
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
id: 'email',
|
|
54
|
+
name: 'email',
|
|
55
|
+
type: 'text',
|
|
56
|
+
label: 'Correo electrónico',
|
|
57
|
+
placeholder: 'ejemplo@correo.com',
|
|
58
|
+
required: true,
|
|
59
|
+
validations: [
|
|
60
|
+
{ type: 'required', params: ['El email es requerido'] },
|
|
61
|
+
{ type: 'email', params: ['Email inválido'] }
|
|
62
|
+
]
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
id: 'rut',
|
|
66
|
+
name: 'rut',
|
|
67
|
+
type: 'rut',
|
|
68
|
+
label: 'RUT',
|
|
69
|
+
placeholder: '12.345.678-9',
|
|
70
|
+
required: true,
|
|
71
|
+
validations: [
|
|
72
|
+
{ type: 'required', params: ['El RUT es requerido'] },
|
|
73
|
+
{ type: 'custom', params: ['rut', 'RUT inválido'] }
|
|
74
|
+
]
|
|
75
|
+
}
|
|
76
|
+
],
|
|
77
|
+
navigation: {
|
|
78
|
+
containerClass: 'flex justify-between',
|
|
79
|
+
buttons: [
|
|
80
|
+
{
|
|
81
|
+
key: 'back',
|
|
82
|
+
direction: 'back',
|
|
83
|
+
label: 'Volver',
|
|
84
|
+
onClick: 'handleBack',
|
|
85
|
+
show: true
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
key: 'next',
|
|
89
|
+
direction: 'next',
|
|
90
|
+
label: 'Siguiente',
|
|
91
|
+
onClick: 'handleNext',
|
|
92
|
+
show: true
|
|
93
|
+
}
|
|
94
|
+
]
|
|
95
|
+
},
|
|
96
|
+
onNext: (formData) => {
|
|
97
|
+
console.log('Datos del formulario:', formData);
|
|
98
|
+
},
|
|
99
|
+
onBack: () => {
|
|
100
|
+
console.log('Volver');
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
function App() {
|
|
105
|
+
return (
|
|
106
|
+
<div className="max-w-4xl mx-auto p-6">
|
|
107
|
+
<GenericForm config={config} />
|
|
108
|
+
</div>
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export default App;
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Componentes Individuales
|
|
116
|
+
|
|
117
|
+
También puedes usar los componentes individualmente:
|
|
118
|
+
|
|
119
|
+
```tsx
|
|
120
|
+
import React, { useState } from 'react';
|
|
121
|
+
import { TextInput, RutInput, SelectInput } from '@visiion/forms-library';
|
|
122
|
+
|
|
123
|
+
function MyForm() {
|
|
124
|
+
const [formData, setFormData] = useState({
|
|
125
|
+
name: '',
|
|
126
|
+
rut: '',
|
|
127
|
+
country: ''
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
const handleChange = (e) => {
|
|
131
|
+
setFormData({
|
|
132
|
+
...formData,
|
|
133
|
+
[e.target.name]: e.target.value
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
return (
|
|
138
|
+
<form className="space-y-4">
|
|
139
|
+
<TextInput
|
|
140
|
+
field={{
|
|
141
|
+
id: 'name',
|
|
142
|
+
name: 'name',
|
|
143
|
+
type: 'text',
|
|
144
|
+
label: 'Nombre',
|
|
145
|
+
placeholder: 'Ingrese su nombre'
|
|
146
|
+
}}
|
|
147
|
+
value={formData.name}
|
|
148
|
+
onChange={handleChange}
|
|
149
|
+
/>
|
|
150
|
+
|
|
151
|
+
<RutInput
|
|
152
|
+
field={{
|
|
153
|
+
id: 'rut',
|
|
154
|
+
name: 'rut',
|
|
155
|
+
type: 'rut',
|
|
156
|
+
label: 'RUT',
|
|
157
|
+
placeholder: '12.345.678-9'
|
|
158
|
+
}}
|
|
159
|
+
value={formData.rut}
|
|
160
|
+
onChange={handleChange}
|
|
161
|
+
/>
|
|
162
|
+
|
|
163
|
+
<SelectInput
|
|
164
|
+
field={{
|
|
165
|
+
id: 'country',
|
|
166
|
+
name: 'country',
|
|
167
|
+
type: 'select',
|
|
168
|
+
label: 'País',
|
|
169
|
+
options: [
|
|
170
|
+
{ value: 'cl', label: 'Chile' },
|
|
171
|
+
{ value: 'ar', label: 'Argentina' },
|
|
172
|
+
{ value: 'pe', label: 'Perú' }
|
|
173
|
+
]
|
|
174
|
+
}}
|
|
175
|
+
value={formData.country}
|
|
176
|
+
onChange={handleChange}
|
|
177
|
+
/>
|
|
178
|
+
</form>
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## Tipos de Campos Disponibles
|
|
184
|
+
|
|
185
|
+
- `text`: Campo de texto simple
|
|
186
|
+
- `textarea`: Área de texto multilínea
|
|
187
|
+
- `select`: Lista desplegable
|
|
188
|
+
- `checkbox`: Casilla de verificación
|
|
189
|
+
- `rut`: Campo especializado para RUT chileno
|
|
190
|
+
- `alert`: Mensaje de alerta
|
|
191
|
+
- `subtitle`: Subtítulo de sección
|
|
192
|
+
|
|
193
|
+
## Validaciones
|
|
194
|
+
|
|
195
|
+
La librería soporta múltiples tipos de validación:
|
|
196
|
+
|
|
197
|
+
```tsx
|
|
198
|
+
const validations = [
|
|
199
|
+
{ type: 'required', params: ['Campo requerido'] },
|
|
200
|
+
{ type: 'min', params: ['5', 'Mínimo 5 caracteres'] },
|
|
201
|
+
{ type: 'max', params: ['100', 'Máximo 100 caracteres'] },
|
|
202
|
+
{ type: 'email', params: ['Email inválido'] },
|
|
203
|
+
{ type: 'pattern', params: ['^[0-9]+$', 'Solo números'] },
|
|
204
|
+
{ type: 'custom', params: ['rut', 'RUT inválido'] }
|
|
205
|
+
];
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## Utilidades
|
|
209
|
+
|
|
210
|
+
### Validación de RUT
|
|
211
|
+
|
|
212
|
+
```tsx
|
|
213
|
+
import { validateRut, formatRut, cleanRut } from '@visiion/forms-library';
|
|
214
|
+
|
|
215
|
+
const rut = '12345678-9';
|
|
216
|
+
const isValid = validateRut(rut); // true/false
|
|
217
|
+
const formatted = formatRut('123456789'); // '12.345.678-9'
|
|
218
|
+
const clean = cleanRut('12.345.678-9'); // '123456789'
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
## Personalización
|
|
222
|
+
|
|
223
|
+
La librería usa Tailwind CSS para los estilos. Puedes personalizar los componentes pasando clases CSS personalizadas:
|
|
224
|
+
|
|
225
|
+
```tsx
|
|
226
|
+
<GenericForm
|
|
227
|
+
config={config}
|
|
228
|
+
className="my-custom-form"
|
|
229
|
+
/>
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
## Desarrollo
|
|
233
|
+
|
|
234
|
+
```bash
|
|
235
|
+
# Instalar dependencias
|
|
236
|
+
pnpm install
|
|
237
|
+
|
|
238
|
+
# Desarrollo
|
|
239
|
+
pnpm run dev
|
|
240
|
+
|
|
241
|
+
# Build
|
|
242
|
+
pnpm run build
|
|
243
|
+
|
|
244
|
+
# Lint
|
|
245
|
+
pnpm run lint
|
|
246
|
+
|
|
247
|
+
# Formatear código
|
|
248
|
+
pnpm run format
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
## Contribuir
|
|
252
|
+
|
|
253
|
+
1. Fork del proyecto
|
|
254
|
+
2. Crea una rama para tu feature (`git checkout -b feature/AmazingFeature`)
|
|
255
|
+
3. Commit tus cambios (`git commit -m 'Add some AmazingFeature'`)
|
|
256
|
+
4. Push a la rama (`git push origin feature/AmazingFeature`)
|
|
257
|
+
5. Abre un Pull Request
|
|
258
|
+
|
|
259
|
+
## Licencia
|
|
260
|
+
|
|
261
|
+
MIT © [Visiion Team]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as NavigationButton } from './NavigationButton';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { IFormConfig } from '../../types';
|
|
3
|
+
interface IGenericFormProps {
|
|
4
|
+
config: IFormConfig;
|
|
5
|
+
stepperData?: any;
|
|
6
|
+
onStepComplete?: (stepNumber: number) => void;
|
|
7
|
+
changeActiveStep?: (step: number) => void;
|
|
8
|
+
loading?: boolean;
|
|
9
|
+
className?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare const GenericForm: React.FC<IGenericFormProps>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { GenericForm } from './GenericForm';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
type AlertType = 'info' | 'warning' | 'error';
|
|
3
|
+
interface CustomAlertProps {
|
|
4
|
+
type?: AlertType | 'warning' | 'info' | 'error' | string;
|
|
5
|
+
text: string | null;
|
|
6
|
+
icon?: React.FC<any> | string;
|
|
7
|
+
className?: string;
|
|
8
|
+
iconClassName?: string;
|
|
9
|
+
textClassName?: string;
|
|
10
|
+
}
|
|
11
|
+
declare const Alert: React.FC<CustomAlertProps>;
|
|
12
|
+
export default Alert;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { IFormField } from '../../types';
|
|
3
|
+
interface CheckboxInputProps {
|
|
4
|
+
field: IFormField;
|
|
5
|
+
value: boolean;
|
|
6
|
+
onChange: (e: React.ChangeEvent<HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement>) => void;
|
|
7
|
+
error?: string;
|
|
8
|
+
}
|
|
9
|
+
declare const CheckboxInput: React.FC<CheckboxInputProps>;
|
|
10
|
+
export default CheckboxInput;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { IFormField } from '../../types';
|
|
3
|
+
interface DynamicInputProps {
|
|
4
|
+
field: IFormField;
|
|
5
|
+
value: any;
|
|
6
|
+
onChange: (e: React.ChangeEvent<HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement>) => void;
|
|
7
|
+
error?: string;
|
|
8
|
+
}
|
|
9
|
+
declare const DynamicInput: React.FC<DynamicInputProps>;
|
|
10
|
+
export default DynamicInput;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { IFormField } from '../../types';
|
|
3
|
+
interface RutInputProps {
|
|
4
|
+
field: IFormField;
|
|
5
|
+
value: any;
|
|
6
|
+
onChange: (e: React.ChangeEvent<HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement>) => void;
|
|
7
|
+
error?: string;
|
|
8
|
+
onSearch?: (value: string | any) => void;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
placeholder?: string;
|
|
11
|
+
minLength?: number;
|
|
12
|
+
maxLength?: number;
|
|
13
|
+
}
|
|
14
|
+
declare const RutInput: React.FC<RutInputProps>;
|
|
15
|
+
export default RutInput;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { IFormField } from '../../types';
|
|
3
|
+
interface SelectInputProps {
|
|
4
|
+
field: IFormField;
|
|
5
|
+
value: string | number;
|
|
6
|
+
onChange: (e: React.ChangeEvent<HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement>) => void;
|
|
7
|
+
error?: string;
|
|
8
|
+
}
|
|
9
|
+
declare const SelectInput: React.FC<SelectInputProps>;
|
|
10
|
+
export default SelectInput;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { IFormField } from '../../types';
|
|
3
|
+
interface TextInputProps {
|
|
4
|
+
field: IFormField;
|
|
5
|
+
value: string | number;
|
|
6
|
+
onChange: (e: React.ChangeEvent<HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement>) => void;
|
|
7
|
+
error?: string;
|
|
8
|
+
}
|
|
9
|
+
declare const TextInput: React.FC<TextInputProps>;
|
|
10
|
+
export default TextInput;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { IFormField } from '../../types';
|
|
3
|
+
interface TextareaInputProps {
|
|
4
|
+
field?: IFormField;
|
|
5
|
+
value?: string;
|
|
6
|
+
onChange?: (e: React.ChangeEvent<HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement>) => void;
|
|
7
|
+
error?: string;
|
|
8
|
+
id?: string;
|
|
9
|
+
name?: string;
|
|
10
|
+
label?: string;
|
|
11
|
+
placeholder?: string;
|
|
12
|
+
className?: string;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
required?: boolean;
|
|
15
|
+
maxLength?: number;
|
|
16
|
+
rows?: number;
|
|
17
|
+
tooltip?: string;
|
|
18
|
+
}
|
|
19
|
+
declare const TextareaInput: React.FC<TextareaInputProps>;
|
|
20
|
+
export default TextareaInput;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { default as TextInput } from './TextInput';
|
|
2
|
+
export { default as SelectInput } from './SelectInput';
|
|
3
|
+
export { default as CheckboxInput } from './CheckboxInput';
|
|
4
|
+
export { default as TextareaInput } from './TextareaInput';
|
|
5
|
+
export { default as RutInput } from './RutInput';
|
|
6
|
+
export { default as Alert } from './Alert';
|
|
7
|
+
export { default as DynamicInput } from './DynamicInput';
|
|
8
|
+
export { default as InputWrapper } from './InputWrapper';
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { GenericForm } from './components/Forms';
|
|
2
|
+
export { TextInput, SelectInput, CheckboxInput, TextareaInput, RutInput, Alert, DynamicInput, InputWrapper, } from './components/Inputs';
|
|
3
|
+
export { NavigationButton } from './components/Common';
|
|
4
|
+
export type { IFormField, IFormConfig, IStepProps, ResponseOnSearch, NavigationButtonProps, DynamicInputProps, InputWrapperProps, StepperContextType, ValidationRule, CommonValidations, } from './types';
|
|
5
|
+
export { createValidationSchema, commonValidations, } from './utils/validationSchemas';
|
|
6
|
+
export { clean as cleanRut, formatRut, validate as validateRut, maskRut, validateOnlyNumbersAndLetters, } from './utils/rut';
|