@visiion/forms-library 1.1.0 → 1.1.2
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 +84 -105
- package/dist/index.esm.js +10205 -213
- package/dist/index.js +10211 -219
- package/package.json +1 -1
- package/dist/index.esm.js.map +0 -1
- package/dist/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -12,16 +12,6 @@ npm install @visiion/forms-library
|
|
|
12
12
|
yarn add @visiion/forms-library
|
|
13
13
|
```
|
|
14
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
15
|
## Uso Básico
|
|
26
16
|
|
|
27
17
|
### GenericForm
|
|
@@ -29,76 +19,76 @@ yarn add @visiion/forms-library
|
|
|
29
19
|
El componente principal para crear formularios dinámicos:
|
|
30
20
|
|
|
31
21
|
```tsx
|
|
32
|
-
import React from
|
|
33
|
-
import { GenericForm, IFormConfig } from
|
|
22
|
+
import React from "react";
|
|
23
|
+
import { GenericForm, IFormConfig } from "@visiion/forms-library";
|
|
34
24
|
|
|
35
25
|
const config: IFormConfig = {
|
|
36
|
-
id:
|
|
37
|
-
title:
|
|
38
|
-
subtitle:
|
|
26
|
+
id: "example-form",
|
|
27
|
+
title: "Formulario de Ejemplo",
|
|
28
|
+
subtitle: "Complete la información solicitada",
|
|
39
29
|
fields: [
|
|
40
30
|
{
|
|
41
|
-
id:
|
|
42
|
-
name:
|
|
43
|
-
type:
|
|
44
|
-
label:
|
|
45
|
-
placeholder:
|
|
31
|
+
id: "name",
|
|
32
|
+
name: "name",
|
|
33
|
+
type: "text",
|
|
34
|
+
label: "Nombre completo",
|
|
35
|
+
placeholder: "Ingrese su nombre",
|
|
46
36
|
required: true,
|
|
47
37
|
validations: [
|
|
48
|
-
{ type:
|
|
49
|
-
{ type:
|
|
50
|
-
]
|
|
38
|
+
{ type: "required", params: ["El nombre es requerido"] },
|
|
39
|
+
{ type: "min", params: ["3", "Mínimo 3 caracteres"] },
|
|
40
|
+
],
|
|
51
41
|
},
|
|
52
42
|
{
|
|
53
|
-
id:
|
|
54
|
-
name:
|
|
55
|
-
type:
|
|
56
|
-
label:
|
|
57
|
-
placeholder:
|
|
43
|
+
id: "email",
|
|
44
|
+
name: "email",
|
|
45
|
+
type: "text",
|
|
46
|
+
label: "Correo electrónico",
|
|
47
|
+
placeholder: "ejemplo@correo.com",
|
|
58
48
|
required: true,
|
|
59
49
|
validations: [
|
|
60
|
-
{ type:
|
|
61
|
-
{ type:
|
|
62
|
-
]
|
|
50
|
+
{ type: "required", params: ["El email es requerido"] },
|
|
51
|
+
{ type: "email", params: ["Email inválido"] },
|
|
52
|
+
],
|
|
63
53
|
},
|
|
64
54
|
{
|
|
65
|
-
id:
|
|
66
|
-
name:
|
|
67
|
-
type:
|
|
68
|
-
label:
|
|
69
|
-
placeholder:
|
|
55
|
+
id: "rut",
|
|
56
|
+
name: "rut",
|
|
57
|
+
type: "rut",
|
|
58
|
+
label: "RUT",
|
|
59
|
+
placeholder: "12.345.678-9",
|
|
70
60
|
required: true,
|
|
71
61
|
validations: [
|
|
72
|
-
{ type:
|
|
73
|
-
{ type:
|
|
74
|
-
]
|
|
75
|
-
}
|
|
62
|
+
{ type: "required", params: ["El RUT es requerido"] },
|
|
63
|
+
{ type: "custom", params: ["rut", "RUT inválido"] },
|
|
64
|
+
],
|
|
65
|
+
},
|
|
76
66
|
],
|
|
77
67
|
navigation: {
|
|
78
|
-
containerClass:
|
|
68
|
+
containerClass: "flex justify-between",
|
|
79
69
|
buttons: [
|
|
80
70
|
{
|
|
81
|
-
key:
|
|
82
|
-
direction:
|
|
83
|
-
label:
|
|
84
|
-
onClick:
|
|
85
|
-
show: true
|
|
71
|
+
key: "back",
|
|
72
|
+
direction: "back",
|
|
73
|
+
label: "Volver",
|
|
74
|
+
onClick: "handleBack",
|
|
75
|
+
show: true,
|
|
86
76
|
},
|
|
87
77
|
{
|
|
88
|
-
key:
|
|
89
|
-
direction:
|
|
90
|
-
label:
|
|
91
|
-
onClick:
|
|
92
|
-
show: true
|
|
93
|
-
}
|
|
94
|
-
]
|
|
78
|
+
key: "next",
|
|
79
|
+
direction: "next",
|
|
80
|
+
label: "Siguiente",
|
|
81
|
+
onClick: "handleNext",
|
|
82
|
+
show: true,
|
|
83
|
+
},
|
|
84
|
+
],
|
|
95
85
|
},
|
|
96
86
|
onNext: (formData) => {
|
|
97
|
-
console.log(
|
|
87
|
+
console.log("Datos del formulario:", formData);
|
|
98
88
|
},
|
|
99
89
|
onBack: () => {
|
|
100
|
-
console.log(
|
|
101
|
-
}
|
|
90
|
+
console.log("Volver");
|
|
91
|
+
},
|
|
102
92
|
};
|
|
103
93
|
|
|
104
94
|
function App() {
|
|
@@ -117,20 +107,20 @@ export default App;
|
|
|
117
107
|
También puedes usar los componentes individualmente:
|
|
118
108
|
|
|
119
109
|
```tsx
|
|
120
|
-
import React, { useState } from
|
|
121
|
-
import { TextInput, RutInput, SelectInput } from
|
|
110
|
+
import React, { useState } from "react";
|
|
111
|
+
import { TextInput, RutInput, SelectInput } from "@visiion/forms-library";
|
|
122
112
|
|
|
123
113
|
function MyForm() {
|
|
124
114
|
const [formData, setFormData] = useState({
|
|
125
|
-
name:
|
|
126
|
-
rut:
|
|
127
|
-
country:
|
|
115
|
+
name: "",
|
|
116
|
+
rut: "",
|
|
117
|
+
country: "",
|
|
128
118
|
});
|
|
129
119
|
|
|
130
120
|
const handleChange = (e) => {
|
|
131
121
|
setFormData({
|
|
132
122
|
...formData,
|
|
133
|
-
[e.target.name]: e.target.value
|
|
123
|
+
[e.target.name]: e.target.value,
|
|
134
124
|
});
|
|
135
125
|
};
|
|
136
126
|
|
|
@@ -138,39 +128,39 @@ function MyForm() {
|
|
|
138
128
|
<form className="space-y-4">
|
|
139
129
|
<TextInput
|
|
140
130
|
field={{
|
|
141
|
-
id:
|
|
142
|
-
name:
|
|
143
|
-
type:
|
|
144
|
-
label:
|
|
145
|
-
placeholder:
|
|
131
|
+
id: "name",
|
|
132
|
+
name: "name",
|
|
133
|
+
type: "text",
|
|
134
|
+
label: "Nombre",
|
|
135
|
+
placeholder: "Ingrese su nombre",
|
|
146
136
|
}}
|
|
147
137
|
value={formData.name}
|
|
148
138
|
onChange={handleChange}
|
|
149
139
|
/>
|
|
150
|
-
|
|
140
|
+
|
|
151
141
|
<RutInput
|
|
152
142
|
field={{
|
|
153
|
-
id:
|
|
154
|
-
name:
|
|
155
|
-
type:
|
|
156
|
-
label:
|
|
157
|
-
placeholder:
|
|
143
|
+
id: "rut",
|
|
144
|
+
name: "rut",
|
|
145
|
+
type: "rut",
|
|
146
|
+
label: "RUT",
|
|
147
|
+
placeholder: "12.345.678-9",
|
|
158
148
|
}}
|
|
159
149
|
value={formData.rut}
|
|
160
150
|
onChange={handleChange}
|
|
161
151
|
/>
|
|
162
|
-
|
|
152
|
+
|
|
163
153
|
<SelectInput
|
|
164
154
|
field={{
|
|
165
|
-
id:
|
|
166
|
-
name:
|
|
167
|
-
type:
|
|
168
|
-
label:
|
|
155
|
+
id: "country",
|
|
156
|
+
name: "country",
|
|
157
|
+
type: "select",
|
|
158
|
+
label: "País",
|
|
169
159
|
options: [
|
|
170
|
-
{ value:
|
|
171
|
-
{ value:
|
|
172
|
-
{ value:
|
|
173
|
-
]
|
|
160
|
+
{ value: "cl", label: "Chile" },
|
|
161
|
+
{ value: "ar", label: "Argentina" },
|
|
162
|
+
{ value: "pe", label: "Perú" },
|
|
163
|
+
],
|
|
174
164
|
}}
|
|
175
165
|
value={formData.country}
|
|
176
166
|
onChange={handleChange}
|
|
@@ -196,12 +186,12 @@ La librería soporta múltiples tipos de validación:
|
|
|
196
186
|
|
|
197
187
|
```tsx
|
|
198
188
|
const validations = [
|
|
199
|
-
{ type:
|
|
200
|
-
{ type:
|
|
201
|
-
{ type:
|
|
202
|
-
{ type:
|
|
203
|
-
{ type:
|
|
204
|
-
{ type:
|
|
189
|
+
{ type: "required", params: ["Campo requerido"] },
|
|
190
|
+
{ type: "min", params: ["5", "Mínimo 5 caracteres"] },
|
|
191
|
+
{ type: "max", params: ["100", "Máximo 100 caracteres"] },
|
|
192
|
+
{ type: "email", params: ["Email inválido"] },
|
|
193
|
+
{ type: "pattern", params: ["^[0-9]+$", "Solo números"] },
|
|
194
|
+
{ type: "custom", params: ["rut", "RUT inválido"] },
|
|
205
195
|
];
|
|
206
196
|
```
|
|
207
197
|
|
|
@@ -210,12 +200,12 @@ const validations = [
|
|
|
210
200
|
### Validación de RUT
|
|
211
201
|
|
|
212
202
|
```tsx
|
|
213
|
-
import { validateRut, formatRut, cleanRut } from
|
|
203
|
+
import { validateRut, formatRut, cleanRut } from "@visiion/forms-library";
|
|
214
204
|
|
|
215
|
-
const rut =
|
|
205
|
+
const rut = "12345678-9";
|
|
216
206
|
const isValid = validateRut(rut); // true/false
|
|
217
|
-
const formatted = formatRut(
|
|
218
|
-
const clean = cleanRut(
|
|
207
|
+
const formatted = formatRut("123456789"); // '12.345.678-9'
|
|
208
|
+
const clean = cleanRut("12.345.678-9"); // '123456789'
|
|
219
209
|
```
|
|
220
210
|
|
|
221
211
|
## Personalización
|
|
@@ -223,10 +213,7 @@ const clean = cleanRut('12.345.678-9'); // '123456789'
|
|
|
223
213
|
La librería usa Tailwind CSS para los estilos. Puedes personalizar los componentes pasando clases CSS personalizadas:
|
|
224
214
|
|
|
225
215
|
```tsx
|
|
226
|
-
<GenericForm
|
|
227
|
-
config={config}
|
|
228
|
-
className="my-custom-form"
|
|
229
|
-
/>
|
|
216
|
+
<GenericForm config={config} className="my-custom-form" />
|
|
230
217
|
```
|
|
231
218
|
|
|
232
219
|
## Desarrollo
|
|
@@ -248,14 +235,6 @@ pnpm run lint
|
|
|
248
235
|
pnpm run format
|
|
249
236
|
```
|
|
250
237
|
|
|
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
238
|
## Licencia
|
|
260
239
|
|
|
261
|
-
MIT © [Visiion Team]
|
|
240
|
+
MIT © [Visiion Team]
|