finform-react-builder 1.3.2 → 1.5.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.
- package/dist/components/FinForm/ButtonGroup.d.ts +13 -0
- package/dist/components/FinForm/apiUtils.d.ts +38 -0
- package/dist/components/FinForm/index.d.ts +2 -1
- package/dist/components/FinForm/types.d.ts +86 -7
- package/dist/index.es.js +5677 -3495
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +28 -28
- package/dist/index.js.map +1 -1
- package/package.json +10 -3
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { ButtonGroup as ButtonGroupType } from './types';
|
|
3
|
+
interface ButtonGroupProps {
|
|
4
|
+
config: ButtonGroupType;
|
|
5
|
+
onSubmit?: (data: any) => void;
|
|
6
|
+
onStepChange?: (currentStep: number, totalSteps: number) => void;
|
|
7
|
+
currentStep?: number;
|
|
8
|
+
totalSteps?: number;
|
|
9
|
+
isMultiStep?: boolean;
|
|
10
|
+
formData?: any;
|
|
11
|
+
}
|
|
12
|
+
export declare const ButtonGroup: React.FC<ButtonGroupProps>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ApiConfig } from './types';
|
|
2
|
+
export interface ApiResponse<T = any> {
|
|
3
|
+
data: T;
|
|
4
|
+
status: number;
|
|
5
|
+
statusText: string;
|
|
6
|
+
}
|
|
7
|
+
export interface ApiError {
|
|
8
|
+
message: string;
|
|
9
|
+
status?: number;
|
|
10
|
+
statusText?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Fetches data from an API endpoint using React Query
|
|
14
|
+
*/
|
|
15
|
+
export declare function fetchApiData(apiConfig: ApiConfig, baseUrl?: string, defaultHeaders?: Record<string, string>, dependentValues?: Record<string, any>): Promise<Array<{
|
|
16
|
+
label: string;
|
|
17
|
+
value: string | number;
|
|
18
|
+
}>>;
|
|
19
|
+
/**
|
|
20
|
+
* React Query hook for fetching API data with caching - only fetches on user interaction
|
|
21
|
+
*/
|
|
22
|
+
export declare function useApiData(apiConfig: ApiConfig | null, baseUrl?: string, defaultHeaders?: Record<string, string>, dependentValues?: Record<string, any>, // Changed from formData to dependentValues
|
|
23
|
+
enabled?: boolean): import('@tanstack/react-query').UseQueryResult<{
|
|
24
|
+
label: string;
|
|
25
|
+
value: string | number;
|
|
26
|
+
}[], Error>;
|
|
27
|
+
/**
|
|
28
|
+
* Checks if a field has API configuration
|
|
29
|
+
*/
|
|
30
|
+
export declare function hasApiConfig(field: any): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Gets the API configuration from a field
|
|
33
|
+
*/
|
|
34
|
+
export declare function getApiConfig(field: any): ApiConfig | null;
|
|
35
|
+
/**
|
|
36
|
+
* Checks if a field should be shown based on conditional logic
|
|
37
|
+
*/
|
|
38
|
+
export declare function shouldShowField(field: any, formData: Record<string, any>): boolean;
|
|
@@ -4,4 +4,5 @@ export { StepNavigation } from './StepNavigation';
|
|
|
4
4
|
export { ImageComponent } from './ImageComponent';
|
|
5
5
|
export { CustomButtons } from './CustomButtons';
|
|
6
6
|
export { generateSchema } from './generateSchema';
|
|
7
|
-
export
|
|
7
|
+
export { fetchApiData, hasApiConfig, getApiConfig, shouldShowField, useApiData } from './apiUtils';
|
|
8
|
+
export type { FieldConfig, ValidationRule, FormButton, ButtonGroup, FormTitle, FormTheme, FinFormProps, ApiConfig, } from './types';
|
|
@@ -4,30 +4,53 @@ export interface ValidationRule {
|
|
|
4
4
|
required?: boolean;
|
|
5
5
|
minLength?: number;
|
|
6
6
|
maxLength?: number;
|
|
7
|
-
min?: number;
|
|
8
|
-
max?: number;
|
|
7
|
+
min?: number | string;
|
|
8
|
+
max?: number | string;
|
|
9
9
|
custom?: (value: any) => boolean | string;
|
|
10
10
|
}
|
|
11
|
+
export interface ApiConfig {
|
|
12
|
+
endpoint: string;
|
|
13
|
+
method?: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
14
|
+
valueField?: string;
|
|
15
|
+
labelField?: string;
|
|
16
|
+
headers?: Record<string, string>;
|
|
17
|
+
params?: Record<string, any>;
|
|
18
|
+
body?: any;
|
|
19
|
+
transform?: (data: any[]) => Array<{
|
|
20
|
+
label: string;
|
|
21
|
+
value: string | number;
|
|
22
|
+
}>;
|
|
23
|
+
dependsOn?: string;
|
|
24
|
+
conditional?: boolean;
|
|
25
|
+
}
|
|
11
26
|
export interface BaseField {
|
|
12
27
|
id?: string;
|
|
13
28
|
title?: string;
|
|
14
29
|
name: string;
|
|
15
30
|
label: string;
|
|
16
|
-
type: 'text' | 'email' | 'password' | 'number' | 'select' | 'checkbox' | 'date' | 'textarea' | 'image' | 'title' | 'section';
|
|
31
|
+
type: 'text' | 'email' | 'password' | 'number' | 'tel' | 'select' | 'checkbox' | 'toggle' | 'radio' | 'switch' | 'autocomplete' | 'date' | 'textarea' | 'image' | 'title' | 'section';
|
|
17
32
|
placeholder?: string;
|
|
18
33
|
required?: boolean;
|
|
19
34
|
disabled?: boolean;
|
|
20
35
|
validation?: ValidationRule;
|
|
21
36
|
step?: number;
|
|
37
|
+
value?: any;
|
|
22
38
|
col?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
|
|
23
39
|
xs?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
|
|
24
40
|
sm?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
|
|
25
41
|
md?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
|
|
26
42
|
lg?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
|
|
27
43
|
xl?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
|
|
44
|
+
api_endpoint?: string;
|
|
45
|
+
api_method?: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
46
|
+
value_field?: string;
|
|
47
|
+
label_field?: string;
|
|
48
|
+
depends_on?: string;
|
|
49
|
+
conditional?: boolean;
|
|
50
|
+
apiConfig?: ApiConfig;
|
|
28
51
|
}
|
|
29
52
|
export interface TextField extends BaseField {
|
|
30
|
-
type: 'text' | 'email' | 'password' | 'textarea';
|
|
53
|
+
type: 'text' | 'email' | 'password' | 'tel' | 'textarea';
|
|
31
54
|
minLength?: number;
|
|
32
55
|
maxLength?: number;
|
|
33
56
|
pattern?: string;
|
|
@@ -39,14 +62,56 @@ export interface NumberField extends BaseField {
|
|
|
39
62
|
}
|
|
40
63
|
export interface SelectField extends BaseField {
|
|
41
64
|
type: 'select';
|
|
42
|
-
options
|
|
65
|
+
options?: Array<{
|
|
43
66
|
label: string;
|
|
44
67
|
value: string | number;
|
|
45
68
|
}>;
|
|
69
|
+
default?: string | number;
|
|
70
|
+
api_endpoint?: string;
|
|
71
|
+
api_method?: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
72
|
+
value_field?: string;
|
|
73
|
+
label_field?: string;
|
|
74
|
+
depends_on?: string;
|
|
75
|
+
conditional?: boolean;
|
|
76
|
+
apiConfig?: ApiConfig;
|
|
46
77
|
}
|
|
47
78
|
export interface CheckboxField extends BaseField {
|
|
48
79
|
type: 'checkbox';
|
|
49
80
|
}
|
|
81
|
+
export interface ToggleField extends BaseField {
|
|
82
|
+
type: 'toggle';
|
|
83
|
+
options: Array<{
|
|
84
|
+
label: string;
|
|
85
|
+
value: string | number;
|
|
86
|
+
}>;
|
|
87
|
+
}
|
|
88
|
+
export interface RadioField extends BaseField {
|
|
89
|
+
type: 'radio';
|
|
90
|
+
options: Array<{
|
|
91
|
+
label: string;
|
|
92
|
+
value: string | number;
|
|
93
|
+
}>;
|
|
94
|
+
}
|
|
95
|
+
export interface SwitchField extends BaseField {
|
|
96
|
+
type: 'switch';
|
|
97
|
+
}
|
|
98
|
+
export interface AutocompleteField extends BaseField {
|
|
99
|
+
type: 'autocomplete';
|
|
100
|
+
options?: Array<{
|
|
101
|
+
label: string;
|
|
102
|
+
value: string | number;
|
|
103
|
+
}>;
|
|
104
|
+
multiple?: boolean;
|
|
105
|
+
freeSolo?: boolean;
|
|
106
|
+
filterOptions?: boolean;
|
|
107
|
+
api_endpoint?: string;
|
|
108
|
+
api_method?: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
109
|
+
value_field?: string;
|
|
110
|
+
label_field?: string;
|
|
111
|
+
depends_on?: string;
|
|
112
|
+
conditional?: boolean;
|
|
113
|
+
apiConfig?: ApiConfig;
|
|
114
|
+
}
|
|
50
115
|
export interface DateField extends BaseField {
|
|
51
116
|
type: 'date';
|
|
52
117
|
minDate?: string;
|
|
@@ -77,7 +142,7 @@ export interface SectionField extends BaseField {
|
|
|
77
142
|
align?: 'left' | 'center' | 'right';
|
|
78
143
|
sx?: any;
|
|
79
144
|
}
|
|
80
|
-
export type FieldConfig = TextField | NumberField | SelectField | CheckboxField | DateField | ImageField | TitleField | SectionField;
|
|
145
|
+
export type FieldConfig = TextField | NumberField | SelectField | CheckboxField | ToggleField | RadioField | SwitchField | AutocompleteField | DateField | ImageField | TitleField | SectionField;
|
|
81
146
|
export interface FormButton {
|
|
82
147
|
text: string;
|
|
83
148
|
color?: string;
|
|
@@ -85,7 +150,15 @@ export interface FormButton {
|
|
|
85
150
|
onClick?: () => void;
|
|
86
151
|
disabled?: boolean;
|
|
87
152
|
loading?: boolean;
|
|
88
|
-
position?:
|
|
153
|
+
position?: 'left' | 'center' | 'right' | 'space-between';
|
|
154
|
+
type?: 'submit' | 'button' | 'reset';
|
|
155
|
+
sx?: any;
|
|
156
|
+
}
|
|
157
|
+
export interface ButtonGroup {
|
|
158
|
+
buttons: FormButton[];
|
|
159
|
+
position?: 'left' | 'center' | 'right' | 'space-between';
|
|
160
|
+
layout?: 'horizontal' | 'vertical';
|
|
161
|
+
spacing?: number;
|
|
89
162
|
sx?: any;
|
|
90
163
|
}
|
|
91
164
|
export interface FormTitle {
|
|
@@ -119,6 +192,9 @@ export interface FinFormProps {
|
|
|
119
192
|
defaultValues?: Record<string, any>;
|
|
120
193
|
showSubmitButton?: boolean;
|
|
121
194
|
buttons?: FormButton[];
|
|
195
|
+
buttonGroup?: ButtonGroup;
|
|
196
|
+
baseUrl?: string;
|
|
197
|
+
apiHeaders?: Record<string, string>;
|
|
122
198
|
isMultiStep?: boolean;
|
|
123
199
|
currentStep?: number;
|
|
124
200
|
onStepChange?: (currentStep: number, totalSteps: number) => void;
|
|
@@ -132,6 +208,9 @@ export interface FieldRendererProps {
|
|
|
132
208
|
field: FieldConfig;
|
|
133
209
|
control: any;
|
|
134
210
|
errors: any;
|
|
211
|
+
baseUrl?: string;
|
|
212
|
+
apiHeaders?: Record<string, string>;
|
|
213
|
+
formData?: Record<string, any>;
|
|
135
214
|
}
|
|
136
215
|
export interface StepNavigationProps {
|
|
137
216
|
currentStep: number;
|