react-form-dto 0.0.6 → 0.0.7

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 CHANGED
@@ -214,6 +214,143 @@ 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
+
217
354
  ## Custom Field Renderers
218
355
 
219
356
  Override any default renderer by supplying your own component:
@@ -0,0 +1,2 @@
1
+ import { FormDTO } from '../types';
2
+ export declare const profileFormI18n: FormDTO;
@@ -5,13 +5,18 @@ 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
+ };
8
13
  export type InputType = "text" | "email" | "password" | "textarea" | "number" | "select" | "checkbox" | "date" | "autocomplete" | "multi-autocomplete" | "radio";
9
14
  export type FieldDTO = {
10
15
  id: string;
11
16
  type: InputType;
12
- label: string;
13
- placeholder?: string;
14
- options?: string[];
17
+ label: I18nText;
18
+ placeholder?: I18nText;
19
+ options?: Array<I18nOption | I18nText>;
15
20
  rows?: number;
16
21
  disabled?: boolean;
17
22
  defaultValue?: any;
@@ -20,27 +25,27 @@ export type FieldDTO = {
20
25
  };
21
26
  export type SectionDTO = {
22
27
  id: string;
23
- heading?: string;
28
+ heading?: I18nText;
24
29
  headingFontSize?: number;
25
- description?: string;
30
+ description?: I18nText;
26
31
  descriptionFontSize?: number;
27
32
  layout?: LayoutDTO;
28
33
  fields: FieldDTO[];
29
34
  };
30
35
  export type FormDTO = {
31
- title?: string;
36
+ title?: I18nText;
32
37
  titleFontSize?: number;
33
- description?: string;
38
+ description?: I18nText;
34
39
  descriptionFontSize?: number;
35
40
  layout?: LayoutDTO;
36
41
  sections: SectionDTO[];
37
42
  };
38
43
  export type Validations = {
39
- required?: boolean | string;
44
+ required?: boolean | I18nText;
40
45
  min?: number;
41
46
  max?: number;
42
47
  minLength?: number;
43
48
  maxLength?: number;
44
49
  pattern?: RegExp;
45
- validate?: (value: any) => string | null;
50
+ validate?: (value: any) => I18nText | null;
46
51
  };
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.6",
4
+ "version": "0.0.7",
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",