react-smart-fields 1.1.5 → 2.1.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.
@@ -0,0 +1,129 @@
1
+ import React from 'react';
2
+
3
+ type Primitive = string | number | boolean | null | undefined;
4
+ type FieldType = "text" | "number" | "select" | "radio" | "checkbox" | "textarea" | "email" | "password" | "tel" | "url" | "date";
5
+ interface FieldOption {
6
+ label: string;
7
+ value: Primitive;
8
+ disabled?: boolean;
9
+ }
10
+ interface StateClassNames {
11
+ invalid?: string;
12
+ disabled?: string;
13
+ readonly?: string;
14
+ dirty?: string;
15
+ touched?: string;
16
+ }
17
+ interface UiClassMap {
18
+ wrapper?: string;
19
+ title?: string;
20
+ description?: string;
21
+ field?: string;
22
+ label?: string;
23
+ help?: string;
24
+ control?: string;
25
+ textarea?: string;
26
+ select?: string;
27
+ option?: string;
28
+ checkbox?: string;
29
+ radio?: string;
30
+ error?: string;
31
+ fieldsContainer?: string;
32
+ }
33
+ type ValidatorResult = string | undefined | null;
34
+ interface FieldConfig {
35
+ name: string;
36
+ label?: string;
37
+ type: FieldType;
38
+ options?: FieldOption[];
39
+ loadOptions?: (context: {
40
+ values: Record<string, any>;
41
+ field: FieldConfig;
42
+ }) => Promise<FieldOption[]>;
43
+ loadOptionsOn?: "mount" | "change";
44
+ required?: boolean;
45
+ requiredWhen?: (values: Record<string, any>) => boolean;
46
+ requiredMessage?: string;
47
+ placeholder?: string;
48
+ description?: string;
49
+ disabled?: boolean;
50
+ readOnly?: boolean;
51
+ defaultValue?: any;
52
+ showWhen?: (values: Record<string, any>) => boolean;
53
+ disableWhen?: (values: Record<string, any>) => boolean;
54
+ min?: number;
55
+ max?: number;
56
+ minLength?: number;
57
+ maxLength?: number;
58
+ pattern?: RegExp;
59
+ patternMessage?: string;
60
+ validate?: (value: any, values: Record<string, any>) => ValidatorResult;
61
+ transformOut?: (rawValue: any, values: Record<string, any>) => any;
62
+ transformIn?: (storedValue: any, values: Record<string, any>) => any;
63
+ className?: string;
64
+ inputClassName?: string;
65
+ labelClassName?: string;
66
+ errorClassName?: string;
67
+ ui?: UiClassMap;
68
+ renderControl?: (context: RenderControlContext) => React.ReactNode;
69
+ }
70
+ interface RenderControlContext {
71
+ field: FieldConfig;
72
+ value: any;
73
+ values: Record<string, any>;
74
+ error?: string;
75
+ isTouched: boolean;
76
+ isDirty: boolean;
77
+ disabled: boolean;
78
+ readOnly: boolean;
79
+ options: FieldOption[];
80
+ isLoadingOptions: boolean;
81
+ classes: Required<UiClassMap>;
82
+ handleChange: (nextValue: any) => void;
83
+ handleBlur: () => void;
84
+ }
85
+ interface RenderFieldContext extends RenderControlContext {
86
+ labelNode: React.ReactNode;
87
+ helpNode: React.ReactNode;
88
+ errorNode: React.ReactNode;
89
+ controlNode: React.ReactNode;
90
+ }
91
+ interface ChangeMeta {
92
+ errors: Record<string, string>;
93
+ touched: Record<string, boolean>;
94
+ dirty: Record<string, boolean>;
95
+ }
96
+ interface DynamicFieldsProps {
97
+ fields: FieldConfig[];
98
+ onChange: (data: Record<string, any>, meta?: ChangeMeta) => void;
99
+ value?: Record<string, any>;
100
+ defaultValues?: Record<string, any>;
101
+ resolver?: (values: Record<string, any>) => Record<string, string> | Promise<Record<string, string>>;
102
+ validateMode?: "change" | "blur";
103
+ showErrorWhen?: "always" | "touched" | "dirty";
104
+ headless?: boolean;
105
+ theme?: "default" | "minimal" | "filled" | "underline";
106
+ size?: "sm" | "md" | "lg";
107
+ ui?: UiClassMap;
108
+ stateClassNames?: StateClassNames;
109
+ className?: string;
110
+ inputClassName?: string;
111
+ labelClassName?: string;
112
+ mainFieldClassName?: string;
113
+ fieldClassName?: string;
114
+ errorClassName?: string;
115
+ selectClassName?: string;
116
+ optionClassName?: string;
117
+ checkboxClassName?: string;
118
+ radioClassName?: string;
119
+ title?: string;
120
+ description?: string;
121
+ renderLabel?: (context: RenderControlContext) => React.ReactNode;
122
+ renderDescription?: (context: RenderControlContext) => React.ReactNode;
123
+ renderError?: (context: RenderControlContext) => React.ReactNode;
124
+ renderControl?: (context: RenderControlContext) => React.ReactNode;
125
+ renderField?: (context: RenderFieldContext) => React.ReactNode;
126
+ }
127
+ declare const DynamicFields: React.FC<DynamicFieldsProps>;
128
+
129
+ export { type ChangeMeta, DynamicFields, type DynamicFieldsProps, type FieldConfig, type FieldOption, type FieldType, type RenderControlContext, type RenderFieldContext, type StateClassNames, type UiClassMap };
package/dist/index.d.ts CHANGED
@@ -1,2 +1,129 @@
1
- export { DynamicFields } from "./components/DynamicFields";
2
- export type { FieldConfig, FieldOption } from "./components/DynamicFields";
1
+ import React from 'react';
2
+
3
+ type Primitive = string | number | boolean | null | undefined;
4
+ type FieldType = "text" | "number" | "select" | "radio" | "checkbox" | "textarea" | "email" | "password" | "tel" | "url" | "date";
5
+ interface FieldOption {
6
+ label: string;
7
+ value: Primitive;
8
+ disabled?: boolean;
9
+ }
10
+ interface StateClassNames {
11
+ invalid?: string;
12
+ disabled?: string;
13
+ readonly?: string;
14
+ dirty?: string;
15
+ touched?: string;
16
+ }
17
+ interface UiClassMap {
18
+ wrapper?: string;
19
+ title?: string;
20
+ description?: string;
21
+ field?: string;
22
+ label?: string;
23
+ help?: string;
24
+ control?: string;
25
+ textarea?: string;
26
+ select?: string;
27
+ option?: string;
28
+ checkbox?: string;
29
+ radio?: string;
30
+ error?: string;
31
+ fieldsContainer?: string;
32
+ }
33
+ type ValidatorResult = string | undefined | null;
34
+ interface FieldConfig {
35
+ name: string;
36
+ label?: string;
37
+ type: FieldType;
38
+ options?: FieldOption[];
39
+ loadOptions?: (context: {
40
+ values: Record<string, any>;
41
+ field: FieldConfig;
42
+ }) => Promise<FieldOption[]>;
43
+ loadOptionsOn?: "mount" | "change";
44
+ required?: boolean;
45
+ requiredWhen?: (values: Record<string, any>) => boolean;
46
+ requiredMessage?: string;
47
+ placeholder?: string;
48
+ description?: string;
49
+ disabled?: boolean;
50
+ readOnly?: boolean;
51
+ defaultValue?: any;
52
+ showWhen?: (values: Record<string, any>) => boolean;
53
+ disableWhen?: (values: Record<string, any>) => boolean;
54
+ min?: number;
55
+ max?: number;
56
+ minLength?: number;
57
+ maxLength?: number;
58
+ pattern?: RegExp;
59
+ patternMessage?: string;
60
+ validate?: (value: any, values: Record<string, any>) => ValidatorResult;
61
+ transformOut?: (rawValue: any, values: Record<string, any>) => any;
62
+ transformIn?: (storedValue: any, values: Record<string, any>) => any;
63
+ className?: string;
64
+ inputClassName?: string;
65
+ labelClassName?: string;
66
+ errorClassName?: string;
67
+ ui?: UiClassMap;
68
+ renderControl?: (context: RenderControlContext) => React.ReactNode;
69
+ }
70
+ interface RenderControlContext {
71
+ field: FieldConfig;
72
+ value: any;
73
+ values: Record<string, any>;
74
+ error?: string;
75
+ isTouched: boolean;
76
+ isDirty: boolean;
77
+ disabled: boolean;
78
+ readOnly: boolean;
79
+ options: FieldOption[];
80
+ isLoadingOptions: boolean;
81
+ classes: Required<UiClassMap>;
82
+ handleChange: (nextValue: any) => void;
83
+ handleBlur: () => void;
84
+ }
85
+ interface RenderFieldContext extends RenderControlContext {
86
+ labelNode: React.ReactNode;
87
+ helpNode: React.ReactNode;
88
+ errorNode: React.ReactNode;
89
+ controlNode: React.ReactNode;
90
+ }
91
+ interface ChangeMeta {
92
+ errors: Record<string, string>;
93
+ touched: Record<string, boolean>;
94
+ dirty: Record<string, boolean>;
95
+ }
96
+ interface DynamicFieldsProps {
97
+ fields: FieldConfig[];
98
+ onChange: (data: Record<string, any>, meta?: ChangeMeta) => void;
99
+ value?: Record<string, any>;
100
+ defaultValues?: Record<string, any>;
101
+ resolver?: (values: Record<string, any>) => Record<string, string> | Promise<Record<string, string>>;
102
+ validateMode?: "change" | "blur";
103
+ showErrorWhen?: "always" | "touched" | "dirty";
104
+ headless?: boolean;
105
+ theme?: "default" | "minimal" | "filled" | "underline";
106
+ size?: "sm" | "md" | "lg";
107
+ ui?: UiClassMap;
108
+ stateClassNames?: StateClassNames;
109
+ className?: string;
110
+ inputClassName?: string;
111
+ labelClassName?: string;
112
+ mainFieldClassName?: string;
113
+ fieldClassName?: string;
114
+ errorClassName?: string;
115
+ selectClassName?: string;
116
+ optionClassName?: string;
117
+ checkboxClassName?: string;
118
+ radioClassName?: string;
119
+ title?: string;
120
+ description?: string;
121
+ renderLabel?: (context: RenderControlContext) => React.ReactNode;
122
+ renderDescription?: (context: RenderControlContext) => React.ReactNode;
123
+ renderError?: (context: RenderControlContext) => React.ReactNode;
124
+ renderControl?: (context: RenderControlContext) => React.ReactNode;
125
+ renderField?: (context: RenderFieldContext) => React.ReactNode;
126
+ }
127
+ declare const DynamicFields: React.FC<DynamicFieldsProps>;
128
+
129
+ export { type ChangeMeta, DynamicFields, type DynamicFieldsProps, type FieldConfig, type FieldOption, type FieldType, type RenderControlContext, type RenderFieldContext, type StateClassNames, type UiClassMap };