react-form-dto 0.0.7 → 0.0.8
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 +0 -137
- package/dist/types/dto.d.ts +9 -14
- package/package.json +1 -1
- package/dist/examples/profileForm.i18n.d.ts +0 -2
package/README.md
CHANGED
|
@@ -214,143 +214,6 @@ const profileForm: FormDTO = {
|
|
|
214
214
|
|
|
215
215
|
---
|
|
216
216
|
|
|
217
|
-
## 🌍 Internationalization (I18n)
|
|
218
|
-
|
|
219
|
-
React Form DTO has built-in support for multi-language forms through `I18nText` and `I18nOption` types.
|
|
220
|
-
|
|
221
|
-
### Using I18nText
|
|
222
|
-
|
|
223
|
-
Any text property (`label`, `placeholder`, `title`, `description`, validation messages) can be either a plain string or a locale map:
|
|
224
|
-
|
|
225
|
-
```tsx
|
|
226
|
-
// Simple string (single language)
|
|
227
|
-
{
|
|
228
|
-
label: "First Name"
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
// Multi-language support
|
|
232
|
-
{
|
|
233
|
-
label: {
|
|
234
|
-
en: "First Name",
|
|
235
|
-
fr: "Prénom",
|
|
236
|
-
es: "Nombre",
|
|
237
|
-
de: "Vorname"
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
```
|
|
241
|
-
|
|
242
|
-
### Using I18nOption for Selections
|
|
243
|
-
|
|
244
|
-
For select, autocomplete, and multi-autocomplete fields, you can use `I18nOption` objects to provide translatable labels while maintaining stable values:
|
|
245
|
-
|
|
246
|
-
```tsx
|
|
247
|
-
{
|
|
248
|
-
id: "country",
|
|
249
|
-
type: "select",
|
|
250
|
-
label: { en: "Country", fr: "Pays" },
|
|
251
|
-
options: [
|
|
252
|
-
{
|
|
253
|
-
value: "us",
|
|
254
|
-
label: { en: "United States", fr: "États-Unis" }
|
|
255
|
-
},
|
|
256
|
-
{
|
|
257
|
-
value: "fr",
|
|
258
|
-
label: { en: "France", fr: "France" }
|
|
259
|
-
},
|
|
260
|
-
{
|
|
261
|
-
value: "de",
|
|
262
|
-
label: { en: "Germany", fr: "Allemagne" }
|
|
263
|
-
}
|
|
264
|
-
]
|
|
265
|
-
}
|
|
266
|
-
```
|
|
267
|
-
|
|
268
|
-
**Backward Compatibility:** Simple string arrays still work:
|
|
269
|
-
|
|
270
|
-
```tsx
|
|
271
|
-
options: ["USA", "France", "Germany"] // Still supported
|
|
272
|
-
```
|
|
273
|
-
|
|
274
|
-
### I18n Validation Messages
|
|
275
|
-
|
|
276
|
-
Validation messages also support I18n:
|
|
277
|
-
|
|
278
|
-
```tsx
|
|
279
|
-
validations: {
|
|
280
|
-
required: {
|
|
281
|
-
en: "This field is required",
|
|
282
|
-
fr: "Ce champ est obligatoire",
|
|
283
|
-
es: "Este campo es obligatorio"
|
|
284
|
-
},
|
|
285
|
-
validate: (value) => value.length < 2
|
|
286
|
-
? {
|
|
287
|
-
en: "Minimum 2 characters",
|
|
288
|
-
fr: "Minimum 2 caractères"
|
|
289
|
-
}
|
|
290
|
-
: null
|
|
291
|
-
}
|
|
292
|
-
```
|
|
293
|
-
|
|
294
|
-
### Complete I18n Example
|
|
295
|
-
|
|
296
|
-
```tsx
|
|
297
|
-
const multilingualForm: FormDTO = {
|
|
298
|
-
title: {
|
|
299
|
-
en: "User Registration",
|
|
300
|
-
fr: "Inscription de l'utilisateur",
|
|
301
|
-
es: "Registro de Usuario"
|
|
302
|
-
},
|
|
303
|
-
description: {
|
|
304
|
-
en: "Please fill in your details",
|
|
305
|
-
fr: "Veuillez remplir vos coordonnées",
|
|
306
|
-
es: "Por favor complete sus datos"
|
|
307
|
-
},
|
|
308
|
-
sections: [
|
|
309
|
-
{
|
|
310
|
-
id: "personal",
|
|
311
|
-
heading: {
|
|
312
|
-
en: "Personal Information",
|
|
313
|
-
fr: "Informations personnelles",
|
|
314
|
-
es: "Información Personal"
|
|
315
|
-
},
|
|
316
|
-
fields: [
|
|
317
|
-
{
|
|
318
|
-
id: "title",
|
|
319
|
-
type: "select",
|
|
320
|
-
label: { en: "Title", fr: "Titre", es: "Título" },
|
|
321
|
-
options: [
|
|
322
|
-
{ value: "mr", label: { en: "Mr", fr: "M.", es: "Sr." } },
|
|
323
|
-
{ value: "ms", label: { en: "Ms", fr: "Mme", es: "Sra." } },
|
|
324
|
-
{ value: "dr", label: { en: "Dr", fr: "Dr", es: "Dr." } }
|
|
325
|
-
]
|
|
326
|
-
},
|
|
327
|
-
{
|
|
328
|
-
id: "firstName",
|
|
329
|
-
type: "text",
|
|
330
|
-
label: { en: "First Name", fr: "Prénom", es: "Nombre" },
|
|
331
|
-
placeholder: {
|
|
332
|
-
en: "Enter your first name",
|
|
333
|
-
fr: "Entrez votre prénom",
|
|
334
|
-
es: "Ingrese su nombre"
|
|
335
|
-
},
|
|
336
|
-
validations: {
|
|
337
|
-
required: {
|
|
338
|
-
en: "First name is required",
|
|
339
|
-
fr: "Le prénom est obligatoire",
|
|
340
|
-
es: "El nombre es obligatorio"
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
]
|
|
345
|
-
}
|
|
346
|
-
]
|
|
347
|
-
};
|
|
348
|
-
```
|
|
349
|
-
|
|
350
|
-
> **Note:** The library provides the I18n structure. You'll need to implement locale selection and text resolution in your application layer.
|
|
351
|
-
|
|
352
|
-
---
|
|
353
|
-
|
|
354
217
|
## Custom Field Renderers
|
|
355
218
|
|
|
356
219
|
Override any default renderer by supplying your own component:
|
package/dist/types/dto.d.ts
CHANGED
|
@@ -5,18 +5,13 @@ export type LayoutDTO = {
|
|
|
5
5
|
align?: "start" | "center" | "end" | "stretch";
|
|
6
6
|
justify?: "start" | "center" | "end" | "space-between";
|
|
7
7
|
};
|
|
8
|
-
export type I18nText = string | Record<string, string>;
|
|
9
|
-
export type I18nOption = {
|
|
10
|
-
value: string;
|
|
11
|
-
label: I18nText;
|
|
12
|
-
};
|
|
13
8
|
export type InputType = "text" | "email" | "password" | "textarea" | "number" | "select" | "checkbox" | "date" | "autocomplete" | "multi-autocomplete" | "radio";
|
|
14
9
|
export type FieldDTO = {
|
|
15
10
|
id: string;
|
|
16
11
|
type: InputType;
|
|
17
|
-
label:
|
|
18
|
-
placeholder?:
|
|
19
|
-
options?:
|
|
12
|
+
label: string;
|
|
13
|
+
placeholder?: string;
|
|
14
|
+
options?: string[];
|
|
20
15
|
rows?: number;
|
|
21
16
|
disabled?: boolean;
|
|
22
17
|
defaultValue?: any;
|
|
@@ -25,27 +20,27 @@ export type FieldDTO = {
|
|
|
25
20
|
};
|
|
26
21
|
export type SectionDTO = {
|
|
27
22
|
id: string;
|
|
28
|
-
heading?:
|
|
23
|
+
heading?: string;
|
|
29
24
|
headingFontSize?: number;
|
|
30
|
-
description?:
|
|
25
|
+
description?: string;
|
|
31
26
|
descriptionFontSize?: number;
|
|
32
27
|
layout?: LayoutDTO;
|
|
33
28
|
fields: FieldDTO[];
|
|
34
29
|
};
|
|
35
30
|
export type FormDTO = {
|
|
36
|
-
title?:
|
|
31
|
+
title?: string;
|
|
37
32
|
titleFontSize?: number;
|
|
38
|
-
description?:
|
|
33
|
+
description?: string;
|
|
39
34
|
descriptionFontSize?: number;
|
|
40
35
|
layout?: LayoutDTO;
|
|
41
36
|
sections: SectionDTO[];
|
|
42
37
|
};
|
|
43
38
|
export type Validations = {
|
|
44
|
-
required?: boolean |
|
|
39
|
+
required?: boolean | string;
|
|
45
40
|
min?: number;
|
|
46
41
|
max?: number;
|
|
47
42
|
minLength?: number;
|
|
48
43
|
maxLength?: number;
|
|
49
44
|
pattern?: RegExp;
|
|
50
|
-
validate?: (value: any) =>
|
|
45
|
+
validate?: (value: any) => string | null;
|
|
51
46
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-form-dto",
|
|
3
3
|
"description": "A React library for building forms using DTOs with MUI and TypeScript.",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.8",
|
|
5
5
|
"main": "dist/react-form-dto.umd.js",
|
|
6
6
|
"module": "dist/react-form-dto.es.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|