finform-react-builder 1.14.0 → 1.16.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.
@@ -6,5 +6,6 @@ export { CustomButtons } from './CustomButtons';
6
6
  export { generateSchema } from './generateSchema';
7
7
  export { fetchApiData, hasApiConfig, getApiConfig, shouldShowField, useApiData } from './apiUtils';
8
8
  export * from './inputs';
9
- export type { FieldConfig, AutomationFieldConfig, ValidationRule, FormButton, ButtonGroup, FormTitle, FormTheme, FinFormProps, ApiConfig, } from './types';
9
+ export * from './utils/phoneUtils';
10
+ export type { FieldConfig, MobileField, AutomationFieldConfig, ValidationRule, FormButton, ButtonGroup, FormTitle, FormTheme, FinFormProps, ApiConfig, } from './types';
10
11
  export { buildFinformTestIds, resolveFieldTestIds } from './testIds';
@@ -1,12 +1,36 @@
1
1
  import { default as React } from 'react';
2
- import { TextFieldProps } from '@mui/material';
3
- export type FinDateFieldProps = TextFieldProps & {
2
+ export declare const DEFAULT_DATE_FORMAT = "DD-MM-YYYY";
3
+ /** Map dayjs format tokens to a human placeholder (DD/MM/YYYY, etc.). */
4
+ export declare function dateFormatToPlaceholder(format: string): string;
5
+ export type FinDateFieldProps = {
6
+ value?: string | null;
7
+ onChange?: (value: string) => void;
8
+ onBlur?: () => void;
9
+ name?: string;
10
+ /** Dayjs format for typed input + display (e.g. DD-MM-YYYY). */
11
+ dateFormat?: string;
12
+ minDate?: string;
13
+ maxDate?: string;
4
14
  label?: React.ReactNode;
5
15
  labelPosition?: 'inner' | 'top' | 'none';
6
16
  labelVariant?: 'caption' | 'body2' | 'subtitle2' | 'h6';
17
+ disabled?: boolean;
18
+ error?: boolean;
19
+ helperText?: React.ReactNode;
20
+ fullWidth?: boolean;
21
+ size?: 'small' | 'medium';
22
+ placeholder?: string;
23
+ sx?: any;
7
24
  inputTestId?: string;
8
25
  labelTestId?: string;
9
26
  errorTestId?: string;
10
- [key: string]: any;
27
+ /** @deprecated Use minDate / maxDate props. Kept for FieldRenderer backward compat. */
28
+ inputProps?: {
29
+ min?: string;
30
+ max?: string;
31
+ [key: string]: unknown;
32
+ };
33
+ id?: string;
34
+ required?: boolean;
11
35
  };
12
36
  export declare const FinDateField: React.FC<FinDateFieldProps>;
@@ -45,6 +45,8 @@ export type GridColumn = {
45
45
  };
46
46
  sx?: any;
47
47
  cellSx?: any;
48
+ /** Per-column dayjs format override for date columns. */
49
+ dateFormat?: string;
48
50
  };
49
51
  export interface FinEditableGridProps {
50
52
  name: string;
@@ -68,6 +70,8 @@ export interface FinEditableGridProps {
68
70
  setValue?: (name: string, value: any, options?: any) => void;
69
71
  rowSelectionMode?: "single" | "multi";
70
72
  rowSelectionKey?: string;
73
+ /** Form-level dayjs date format for date columns. */
74
+ dateFormat?: string;
71
75
  }
72
76
  export declare const FinEditableGrid: React.FC<FinEditableGridProps>;
73
77
  export default FinEditableGrid;
@@ -0,0 +1,31 @@
1
+ import { default as React } from 'react';
2
+ import { DialCodeOption } from '../utils/phoneUtils';
3
+ export type FinMobileFieldProps = {
4
+ id?: string;
5
+ value?: any;
6
+ onChange?: (val: string) => void;
7
+ onBlur?: () => void;
8
+ labelText?: string;
9
+ label?: string;
10
+ labelVariant?: 'caption' | 'body2' | 'subtitle2' | 'h6';
11
+ placeholder?: string;
12
+ disabled?: boolean;
13
+ hasError?: boolean;
14
+ helperText?: string;
15
+ dialCodes?: DialCodeOption[];
16
+ defaultDialCode?: string;
17
+ mobilePrefixes?: string[];
18
+ storeFormat?: string;
19
+ phoneExamples?: string[];
20
+ name?: string;
21
+ inputTestId?: string;
22
+ labelTestId?: string;
23
+ errorTestId?: string;
24
+ };
25
+ /**
26
+ * Mobile phone field: dial-code select + national number.
27
+ * Visual tokens match FinTextField (8px radius, outlined, theme input tokens).
28
+ * Stored value is national store-format string (not E.164).
29
+ */
30
+ export declare const FinMobileField: React.FC<FinMobileFieldProps>;
31
+ export default FinMobileField;
@@ -1,4 +1,5 @@
1
1
  export * from './FinTextField';
2
+ export * from './FinMobileField';
2
3
  export * from './FinSelect';
3
4
  export * from './FinAutocomplete';
4
5
  export * from './FinCheckbox';
@@ -35,7 +35,7 @@ export interface BaseField {
35
35
  title?: string;
36
36
  name: string;
37
37
  label: string;
38
- type: 'text' | 'email' | 'password' | 'number' | 'tel' | 'select' | 'checkbox' | 'checkboxGroup' | 'toggle' | 'radio' | 'switch' | 'autocomplete' | 'date' | 'textarea' | 'image' | 'title' | 'section' | 'component' | 'finuiHeader' | 'tabs' | 'grid' | 'listcards' | 'dragdroplist';
38
+ type: 'text' | 'email' | 'password' | 'number' | 'tel' | 'mobile' | 'select' | 'checkbox' | 'checkboxGroup' | 'toggle' | 'radio' | 'switch' | 'autocomplete' | 'date' | 'textarea' | 'image' | 'title' | 'section' | 'component' | 'finuiHeader' | 'tabs' | 'grid' | 'listcards' | 'dragdroplist';
39
39
  placeholder?: string;
40
40
  labelPosition?: 'inner' | 'top' | 'none';
41
41
  labelVariant?: 'caption' | 'body2' | 'subtitle2' | 'h6';
@@ -80,6 +80,27 @@ export interface NumberField extends BaseField {
80
80
  min?: number;
81
81
  max?: number;
82
82
  }
83
+ /** Mobile phone with dial-code dropdown; store value is national store-format string (not E.164). */
84
+ export interface MobileField extends BaseField {
85
+ type: 'mobile';
86
+ minLength?: number;
87
+ maxLength?: number;
88
+ pattern?: string;
89
+ /** Dial-code options (digits without "+"), e.g. [{ dial_code: "260", label: "ZM" }] */
90
+ dialCodes?: Array<{
91
+ dial_code: string;
92
+ label?: string;
93
+ iso?: string;
94
+ }>;
95
+ /** Default dial code digits without "+" */
96
+ defaultDialCode?: string;
97
+ /** Optional national prefix allowlist */
98
+ mobilePrefixes?: string[];
99
+ /** Expected store shape, e.g. "0XXXXXXXXX" */
100
+ storeFormat?: string;
101
+ /** Example strings for helper / paste hints */
102
+ phoneExamples?: string[];
103
+ }
83
104
  export interface SelectField extends BaseField {
84
105
  type: 'select';
85
106
  options?: Array<{
@@ -153,6 +174,8 @@ export interface DateField extends BaseField {
153
174
  type: 'date';
154
175
  minDate?: string;
155
176
  maxDate?: string;
177
+ /** Per-field dayjs format override (e.g. DD-MM-YYYY). Falls back to FinForm dateFormat. */
178
+ dateFormat?: string;
156
179
  }
157
180
  export interface ImageField extends BaseField {
158
181
  type: 'image';
@@ -340,7 +363,7 @@ export interface DragDropListField extends Omit<BaseField, 'helperText'> {
340
363
  helperText?: React.ReactNode | string;
341
364
  sx?: any;
342
365
  }
343
- export type FieldConfig = TextField | NumberField | SelectField | CheckboxField | CheckboxGroupField | ToggleField | RadioField | SwitchField | AutocompleteField | DateField | ImageField | TitleField | SectionField | ComponentField | FinUiHeaderField | TabsField | GridField | ListCardsField | DragDropListField;
366
+ export type FieldConfig = TextField | NumberField | MobileField | SelectField | CheckboxField | CheckboxGroupField | ToggleField | RadioField | SwitchField | AutocompleteField | DateField | ImageField | TitleField | SectionField | ComponentField | FinUiHeaderField | TabsField | GridField | ListCardsField | DragDropListField;
344
367
  export type AutomationFieldConfig = FieldConfig & {
345
368
  testId?: string;
346
369
  automation?: {
@@ -422,6 +445,11 @@ export interface FinFormProps {
422
445
  };
423
446
  /** Prefix for stable data-testid attributes on generated form controls (e.g. "client-profile"). */
424
447
  testIdPrefix?: string;
448
+ /**
449
+ * Dayjs format for all date fields (e.g. DD-MM-YYYY, MM-DD-YYYY, YYYY-MM-DD).
450
+ * Host app should map company regional settings to this value.
451
+ */
452
+ dateFormat?: string;
425
453
  }
426
454
  export interface FieldRendererProps {
427
455
  field: FieldConfig;
@@ -432,6 +460,8 @@ export interface FieldRendererProps {
432
460
  formData?: Record<string, any>;
433
461
  setValue?: (name: string, value: any, options?: any) => void;
434
462
  testIdPrefix?: string;
463
+ /** Form-level dayjs date format inherited by date fields. */
464
+ dateFormat?: string;
435
465
  }
436
466
  export interface FinInputTestIdProps {
437
467
  inputTestId?: string;
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Generic phone normalize / display helpers for FinMobileField.
3
+ * Country rules come from field props — no country hardcoding.
4
+ */
5
+ export type DialCodeOption = {
6
+ dial_code: string;
7
+ label?: string;
8
+ iso?: string;
9
+ };
10
+ export type PhoneNormalizeOptions = {
11
+ dialCode?: string;
12
+ storeFormat?: string;
13
+ prefixes?: string[];
14
+ };
15
+ export type PhoneDisplayParts = {
16
+ dialCode: string;
17
+ national: string;
18
+ };
19
+ /** Digits only. */
20
+ export declare function digitsOnly(value: unknown): string;
21
+ /** Strip leading zeros from a dial code string ("0260" → "260", "+260" → "260"). */
22
+ export declare function normalizeDialCode(dialCode: unknown): string;
23
+ /**
24
+ * Parse storeFormat like "0XXXXXXXXX":
25
+ * - leadingDigits: literal digit prefix ("0")
26
+ * - xCount: number of X placeholders (9)
27
+ * - totalLen: expected national length (10)
28
+ */
29
+ export declare function parseStoreFormat(storeFormat?: string): {
30
+ leadingDigits: string;
31
+ xCount: number;
32
+ totalLen: number;
33
+ };
34
+ /**
35
+ * Normalize any common input shape into the national store format.
36
+ * Accepts: "+260971234567", "0971234567", "971234567", with spaces/dashes.
37
+ */
38
+ export declare function normalizePhoneToStoreFormat(raw: unknown, options?: PhoneNormalizeOptions): string;
39
+ /**
40
+ * Split a stored national value for UI: dial code + national digits.
41
+ */
42
+ export declare function parsePhoneDisplayParts(stored: unknown, options?: {
43
+ dialCode?: string;
44
+ dialCodes?: DialCodeOption[];
45
+ }): PhoneDisplayParts;
46
+ /**
47
+ * Validate a store-format national number.
48
+ */
49
+ export declare function validatePhone(storeValue: unknown, options?: {
50
+ pattern?: string | RegExp;
51
+ prefixes?: string[];
52
+ message?: string;
53
+ }): {
54
+ valid: boolean;
55
+ message?: string;
56
+ };