@akad/form-builder 1.0.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/components/FormBuilder/FormBuilder.config.d.ts +333 -0
- package/components/FormBuilder/FormBuilder.d.ts +31 -0
- package/components/FormBuilder/components/AddressFormGroup/AddressFormGroup.d.ts +53 -0
- package/components/FormBuilder/components/AddressFormGroup/AddressFormGroup.test.d.ts +1 -0
- package/components/FormBuilder/components/AddressFormGroup/index.d.ts +4 -0
- package/components/FormBuilder/components/FieldRenderer/FieldRenderer.d.ts +39 -0
- package/components/FormBuilder/components/FieldRenderer/FieldRenderer.test.d.ts +1 -0
- package/components/FormBuilder/components/FieldRenderer/index.d.ts +3 -0
- package/components/FormBuilder/components/GenericWrapper/GenericWrapper.d.ts +61 -0
- package/components/FormBuilder/components/GenericWrapper/GenericWrapper.test.d.ts +1 -0
- package/components/FormBuilder/components/GenericWrapper/index.d.ts +4 -0
- package/components/FormBuilder/components/RadioGroup/RadioGroup.d.ts +67 -0
- package/components/FormBuilder/components/RadioGroup/RadioGroup.test.d.ts +1 -0
- package/components/FormBuilder/components/RadioGroup/index.d.ts +4 -0
- package/components/FormBuilder/hooks/useForm.d.ts +30 -0
- package/components/FormBuilder/hooks/useForm.test.d.ts +1 -0
- package/components/FormBuilder/hooks/useFormParser.d.ts +7 -0
- package/components/FormBuilder/hooks/useFormParser.test.d.ts +1 -0
- package/components/FormBuilder/hooks/useFormState.d.ts +28 -0
- package/components/FormBuilder/hooks/useFormState.test.d.ts +1 -0
- package/components/FormBuilder/hooks/useFormStepper.d.ts +64 -0
- package/components/FormBuilder/hooks/useFormStepper.test.d.ts +1 -0
- package/components/FormBuilder/hooks/useFormValidation.d.ts +7 -0
- package/components/FormBuilder/hooks/useFormValidation.test.d.ts +1 -0
- package/components/FormBuilder/index.d.ts +27 -0
- package/components/FormBuilder/utils/ajv/formats.d.ts +27 -0
- package/components/FormBuilder/utils/ajv/formats.test.d.ts +1 -0
- package/components/FormBuilder/utils/ajv/instance.d.ts +2 -0
- package/components/FormBuilder/utils/ajv/instance.test.d.ts +1 -0
- package/components/FormBuilder/utils/componentDetection.d.ts +24 -0
- package/components/FormBuilder/utils/componentDetection.test.d.ts +1 -0
- package/components/FormBuilder/utils/componentRegistry.d.ts +10 -0
- package/components/FormBuilder/utils/componentRegistry.test.d.ts +1 -0
- package/components/FormBuilder/utils/facade/AddressFormLegacy.d.ts +20 -0
- package/components/FormBuilder/utils/facade/AddressFormLegacy.test.d.ts +1 -0
- package/components/FormBuilder/utils/facade/PaymentOptionsLegacy.d.ts +22 -0
- package/components/FormBuilder/utils/facade/PaymentOptionsLegacy.test.d.ts +1 -0
- package/components/FormBuilder/utils/facade/index.d.ts +6 -0
- package/components/FormBuilder/utils/facade/makeFullFormHookFacade.d.ts +111 -0
- package/components/FormBuilder/utils/facade/makeFullFormHookFacade.test.d.ts +1 -0
- package/components/FormBuilder/utils/facade/useLegacyFormHook.d.ts +45 -0
- package/components/FormBuilder/utils/facade/useLegacyFormHook.test.d.ts +1 -0
- package/components/FormBuilder/utils/fieldExtractors.d.ts +68 -0
- package/components/FormBuilder/utils/fieldExtractors.test.d.ts +1 -0
- package/components/FormBuilder/utils/generateFieldsFromSchema.d.ts +67 -0
- package/components/FormBuilder/utils/generateFieldsFromSchema.test.d.ts +1 -0
- package/components/FormBuilder/utils/objectAccess.d.ts +7 -0
- package/components/FormBuilder/utils/objectAccess.test.d.ts +1 -0
- package/components/FormBuilder/utils/schemaUtils.d.ts +113 -0
- package/components/FormBuilder/utils/schemaUtils.test.d.ts +1 -0
- package/components/FormBuilder/utils/typeCoercion.d.ts +57 -0
- package/components/FormBuilder/utils/typeCoercion.test.d.ts +1 -0
- package/components/index.d.ts +2 -0
- package/main.d.ts +1 -0
- package/main.test.d.ts +1 -0
- package/package.json +13 -0
- package/react-lib.css +1 -0
- package/react-lib.js +72330 -0
- package/react-lib.umd.cjs +215 -0
- package/vite.svg +1 -0
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
import { JSONSchema7 } from 'json-schema';
|
|
2
|
+
export declare const ValidationMode: {
|
|
3
|
+
readonly OnChange: "onChange";
|
|
4
|
+
readonly OnBlur: "onBlur";
|
|
5
|
+
readonly OnSubmit: "onSubmit";
|
|
6
|
+
readonly Eager: "eager";
|
|
7
|
+
};
|
|
8
|
+
export type ValidationMode = (typeof ValidationMode)[keyof typeof ValidationMode];
|
|
9
|
+
export declare const ComponentType: {
|
|
10
|
+
readonly Input: "Input";
|
|
11
|
+
readonly Select: "Select";
|
|
12
|
+
readonly TextArea: "TextArea";
|
|
13
|
+
readonly Checkbox: "Checkbox";
|
|
14
|
+
readonly Button: "Button";
|
|
15
|
+
readonly EditableSelect: "EditableSelect";
|
|
16
|
+
readonly CoverageList: "CoverageList";
|
|
17
|
+
readonly RadioGroup: "RadioGroup";
|
|
18
|
+
readonly MultiSelect: "MultiSelect";
|
|
19
|
+
readonly CheckboxGroup: "CheckboxGroup";
|
|
20
|
+
readonly DatePicker: "DatePicker";
|
|
21
|
+
readonly FileUpload: "FileUpload";
|
|
22
|
+
readonly ArrayInput: "ArrayInput";
|
|
23
|
+
readonly ObjectInput: "ObjectInput";
|
|
24
|
+
};
|
|
25
|
+
export type ComponentType = (typeof ComponentType)[keyof typeof ComponentType];
|
|
26
|
+
export declare const FieldType: {
|
|
27
|
+
readonly String: "string";
|
|
28
|
+
readonly Number: "number";
|
|
29
|
+
readonly Integer: "integer";
|
|
30
|
+
readonly Boolean: "boolean";
|
|
31
|
+
readonly Array: "array";
|
|
32
|
+
readonly Object: "object";
|
|
33
|
+
};
|
|
34
|
+
export type FieldType = (typeof FieldType)[keyof typeof FieldType];
|
|
35
|
+
export declare const LayoutType: {
|
|
36
|
+
readonly Grid: "grid";
|
|
37
|
+
readonly Flex: "flex";
|
|
38
|
+
readonly Custom: "custom";
|
|
39
|
+
};
|
|
40
|
+
export type LayoutType = (typeof LayoutType)[keyof typeof LayoutType];
|
|
41
|
+
export interface FieldOption {
|
|
42
|
+
value: string | number | boolean;
|
|
43
|
+
label: string;
|
|
44
|
+
description?: string;
|
|
45
|
+
disabled?: boolean;
|
|
46
|
+
icon?: string;
|
|
47
|
+
group?: string;
|
|
48
|
+
data?: Record<string, unknown>;
|
|
49
|
+
}
|
|
50
|
+
export interface ValidationRules {
|
|
51
|
+
type?: FieldType;
|
|
52
|
+
required?: boolean;
|
|
53
|
+
minLength?: number;
|
|
54
|
+
maxLength?: number;
|
|
55
|
+
minimum?: number;
|
|
56
|
+
maximum?: number;
|
|
57
|
+
multipleOf?: number;
|
|
58
|
+
pattern?: string;
|
|
59
|
+
format?: string;
|
|
60
|
+
enum?: (string | number | boolean)[];
|
|
61
|
+
minItems?: number;
|
|
62
|
+
maxItems?: number;
|
|
63
|
+
uniqueItems?: boolean;
|
|
64
|
+
customValidators?: string[];
|
|
65
|
+
crossField?: CrossFieldValidationRule[];
|
|
66
|
+
}
|
|
67
|
+
export interface CrossFieldValidationRule {
|
|
68
|
+
field: string;
|
|
69
|
+
affects: string[];
|
|
70
|
+
rule: string;
|
|
71
|
+
}
|
|
72
|
+
export interface GridConfig {
|
|
73
|
+
col?: number;
|
|
74
|
+
offset?: number;
|
|
75
|
+
row?: number;
|
|
76
|
+
rowSpan?: number;
|
|
77
|
+
colSpan?: number;
|
|
78
|
+
sm?: Partial<GridConfig>;
|
|
79
|
+
md?: Partial<GridConfig>;
|
|
80
|
+
lg?: Partial<GridConfig>;
|
|
81
|
+
xl?: Partial<GridConfig>;
|
|
82
|
+
xxl?: Partial<GridConfig>;
|
|
83
|
+
}
|
|
84
|
+
export interface FlexConfig {
|
|
85
|
+
grow?: number;
|
|
86
|
+
shrink?: number;
|
|
87
|
+
basis?: string;
|
|
88
|
+
align?: 'start' | 'center' | 'end' | 'stretch';
|
|
89
|
+
}
|
|
90
|
+
export interface ConditionalConfig {
|
|
91
|
+
field: string;
|
|
92
|
+
operator: ConditionalOperator;
|
|
93
|
+
value: unknown;
|
|
94
|
+
and?: ConditionalConfig[];
|
|
95
|
+
or?: ConditionalConfig[];
|
|
96
|
+
not?: ConditionalConfig;
|
|
97
|
+
}
|
|
98
|
+
export type ConditionalOperator = '==' | '!=' | '>' | '<' | '>=' | '<=' | 'in' | 'not_in' | 'exists' | 'empty' | 'contains' | 'starts_with' | 'ends_with';
|
|
99
|
+
export interface FieldConfig {
|
|
100
|
+
name: string;
|
|
101
|
+
type: FieldType;
|
|
102
|
+
component: ComponentType;
|
|
103
|
+
label?: string;
|
|
104
|
+
placeholder?: string;
|
|
105
|
+
help?: string;
|
|
106
|
+
options?: FieldOption[];
|
|
107
|
+
required: boolean;
|
|
108
|
+
validation: ValidationRules;
|
|
109
|
+
layout: {
|
|
110
|
+
grid?: GridConfig;
|
|
111
|
+
flex?: FlexConfig;
|
|
112
|
+
spacing?: string;
|
|
113
|
+
};
|
|
114
|
+
props: Record<string, unknown>;
|
|
115
|
+
conditional?: ConditionalConfig;
|
|
116
|
+
order?: number;
|
|
117
|
+
disabled?: boolean;
|
|
118
|
+
hidden?: boolean;
|
|
119
|
+
nullable?: boolean;
|
|
120
|
+
}
|
|
121
|
+
export interface FieldError {
|
|
122
|
+
message: string;
|
|
123
|
+
type: string;
|
|
124
|
+
value: unknown;
|
|
125
|
+
severity?: 'error' | 'warning' | 'info';
|
|
126
|
+
schemaPath?: string;
|
|
127
|
+
data?: Record<string, unknown>;
|
|
128
|
+
}
|
|
129
|
+
export interface ValidationResult {
|
|
130
|
+
isValid: boolean;
|
|
131
|
+
errors: Record<string, FieldError>;
|
|
132
|
+
validFields: string[];
|
|
133
|
+
invalidFields: string[];
|
|
134
|
+
warnings?: Record<string, FieldError>;
|
|
135
|
+
}
|
|
136
|
+
export interface FieldValidationResult {
|
|
137
|
+
isValid: boolean;
|
|
138
|
+
error?: FieldError;
|
|
139
|
+
}
|
|
140
|
+
export type ValidatorFunction = (value: unknown, data?: Record<string, unknown>) => ValidationResult | Promise<ValidationResult>;
|
|
141
|
+
export interface ComponentRegistry {
|
|
142
|
+
[componentName: string]: React.ComponentType<ComponentProps>;
|
|
143
|
+
}
|
|
144
|
+
export interface ComponentProps {
|
|
145
|
+
name: string;
|
|
146
|
+
value: unknown;
|
|
147
|
+
onChange: (value: unknown) => void;
|
|
148
|
+
onBlur?: () => void;
|
|
149
|
+
onFocus?: () => void;
|
|
150
|
+
error?: string | FieldError;
|
|
151
|
+
disabled?: boolean;
|
|
152
|
+
readonly?: boolean;
|
|
153
|
+
required?: boolean;
|
|
154
|
+
label?: string;
|
|
155
|
+
placeholder?: string;
|
|
156
|
+
help?: string;
|
|
157
|
+
options?: FieldOption[];
|
|
158
|
+
[key: string]: unknown;
|
|
159
|
+
}
|
|
160
|
+
export interface UseFormStateConfig {
|
|
161
|
+
initialData?: Record<string, unknown>;
|
|
162
|
+
deepEqual?: boolean;
|
|
163
|
+
}
|
|
164
|
+
export interface UseFormStateReturn {
|
|
165
|
+
formData: Record<string, unknown>;
|
|
166
|
+
setFormData: (data: Record<string, unknown>) => void;
|
|
167
|
+
updateFormData: (data: Partial<Record<string, unknown>>) => void;
|
|
168
|
+
setField: (fieldName: string, value: unknown) => void;
|
|
169
|
+
clearForm: () => void;
|
|
170
|
+
resetForm: () => void;
|
|
171
|
+
isDirty: boolean;
|
|
172
|
+
touched: Record<string, boolean>;
|
|
173
|
+
setTouched: (fieldName: string, touched?: boolean) => void;
|
|
174
|
+
}
|
|
175
|
+
export interface UseFormValidationConfig {
|
|
176
|
+
schema: JSONSchema7;
|
|
177
|
+
mode?: ValidationMode;
|
|
178
|
+
customValidators?: Record<string, ValidatorFunction>;
|
|
179
|
+
errorMessages?: Record<string, string>;
|
|
180
|
+
debounce?: number;
|
|
181
|
+
}
|
|
182
|
+
export interface UseFormValidationReturn {
|
|
183
|
+
validateForm: (data: Record<string, unknown>) => Promise<ValidationResult>;
|
|
184
|
+
validateFields: (data: Record<string, unknown>, fieldNames: string[]) => ValidationResult;
|
|
185
|
+
validateField: (fieldName: string, value: unknown, fullFormData?: Record<string, unknown>) => FieldValidationResult;
|
|
186
|
+
validateSilent: (data: Record<string, unknown>) => boolean;
|
|
187
|
+
isValid: boolean;
|
|
188
|
+
errors: Record<string, FieldError>;
|
|
189
|
+
isValidating: boolean;
|
|
190
|
+
clearErrors: () => void;
|
|
191
|
+
clearFieldError: (fieldName: string) => void;
|
|
192
|
+
}
|
|
193
|
+
export interface UseFormParserConfig {
|
|
194
|
+
schema: JSONSchema7;
|
|
195
|
+
}
|
|
196
|
+
export interface UseFormParserReturn {
|
|
197
|
+
parseToObject: (data: Record<string, unknown>) => Record<string, unknown>;
|
|
198
|
+
parseField: (fieldName: string, value: unknown) => unknown;
|
|
199
|
+
getFieldType: (fieldName: string) => string;
|
|
200
|
+
}
|
|
201
|
+
export interface UseFormConfig {
|
|
202
|
+
schema: JSONSchema7;
|
|
203
|
+
initialData?: Record<string, unknown>;
|
|
204
|
+
mode?: ValidationMode;
|
|
205
|
+
customValidators?: Record<string, ValidatorFunction>;
|
|
206
|
+
errorMessages?: Record<string, string>;
|
|
207
|
+
validationDebounce?: number;
|
|
208
|
+
}
|
|
209
|
+
export interface UseFormReturn {
|
|
210
|
+
data: Record<string, unknown>;
|
|
211
|
+
setData: (data: Record<string, unknown>) => void;
|
|
212
|
+
setField: (fieldName: string, value: unknown) => void;
|
|
213
|
+
getFieldErrorMessage: (field: FieldConfig, state: UseFormReturn) => string | undefined;
|
|
214
|
+
clear: () => void;
|
|
215
|
+
reset: () => void;
|
|
216
|
+
isDirty: boolean;
|
|
217
|
+
touched: Record<string, boolean>;
|
|
218
|
+
validate: () => Promise<ValidationResult>;
|
|
219
|
+
validateFields: (fieldNames: string[]) => ValidationResult;
|
|
220
|
+
validateField: (fieldName: string, fullFormData?: Record<string, unknown>) => FieldValidationResult;
|
|
221
|
+
validateSilent: (data: Record<string, unknown>) => boolean;
|
|
222
|
+
clearErrors: () => void;
|
|
223
|
+
isValid: boolean;
|
|
224
|
+
errors: Record<string, FieldError>;
|
|
225
|
+
isValidating: boolean;
|
|
226
|
+
parse: () => Record<string, unknown>;
|
|
227
|
+
onBlur: (fieldName: string) => void;
|
|
228
|
+
}
|
|
229
|
+
export interface UISchema {
|
|
230
|
+
[stepId: string]: UISchemaStep;
|
|
231
|
+
}
|
|
232
|
+
export interface UISchemaStep {
|
|
233
|
+
'ui:layout'?: LayoutType;
|
|
234
|
+
'ui:columns'?: number;
|
|
235
|
+
'ui:gap'?: string;
|
|
236
|
+
'ui:spacing'?: string;
|
|
237
|
+
'ui:className'?: string;
|
|
238
|
+
'ui:style'?: React.CSSProperties;
|
|
239
|
+
'ui:responsive'?: ResponsiveConfig;
|
|
240
|
+
[fieldName: string]: UISchemaField | unknown;
|
|
241
|
+
}
|
|
242
|
+
export interface UISchemaField {
|
|
243
|
+
'ui:component'?: ComponentType;
|
|
244
|
+
'ui:grid'?: GridConfig;
|
|
245
|
+
'ui:flex'?: FlexConfig;
|
|
246
|
+
'ui:spacing'?: string;
|
|
247
|
+
'ui:props'?: Record<string, unknown>;
|
|
248
|
+
'ui:options'?: Array<{
|
|
249
|
+
label: string;
|
|
250
|
+
value: string | number | boolean;
|
|
251
|
+
detail?: string;
|
|
252
|
+
disabled?: boolean;
|
|
253
|
+
}>;
|
|
254
|
+
'ui:show'?: ConditionalConfig;
|
|
255
|
+
'ui:className'?: string;
|
|
256
|
+
'ui:style'?: React.CSSProperties;
|
|
257
|
+
'ui:order'?: number;
|
|
258
|
+
}
|
|
259
|
+
export interface ResponsiveConfig {
|
|
260
|
+
sm?: Partial<UISchemaStep>;
|
|
261
|
+
md?: Partial<UISchemaStep>;
|
|
262
|
+
lg?: Partial<UISchemaStep>;
|
|
263
|
+
xl?: Partial<UISchemaStep>;
|
|
264
|
+
xxl?: Partial<UISchemaStep>;
|
|
265
|
+
}
|
|
266
|
+
export interface FormBuilderProps {
|
|
267
|
+
schema: JSONSchema7;
|
|
268
|
+
uiSchema: UISchema;
|
|
269
|
+
form: UseFormReturn;
|
|
270
|
+
components?: ComponentRegistry;
|
|
271
|
+
className?: string;
|
|
272
|
+
style?: React.CSSProperties;
|
|
273
|
+
testId?: string;
|
|
274
|
+
disabled?: boolean;
|
|
275
|
+
readonly?: boolean;
|
|
276
|
+
}
|
|
277
|
+
export interface FieldRendererProps {
|
|
278
|
+
field: FieldConfig;
|
|
279
|
+
form: UseFormReturn;
|
|
280
|
+
uiConfig: UISchemaField;
|
|
281
|
+
components?: ComponentRegistry;
|
|
282
|
+
className?: string;
|
|
283
|
+
disabled?: boolean;
|
|
284
|
+
readonly?: boolean;
|
|
285
|
+
}
|
|
286
|
+
export interface ComponentDetectionRule {
|
|
287
|
+
default: ComponentType;
|
|
288
|
+
props?: Record<string, unknown>;
|
|
289
|
+
conditions?: ComponentCondition[];
|
|
290
|
+
}
|
|
291
|
+
export interface ComponentCondition {
|
|
292
|
+
when: (schema: JSONSchema7) => boolean;
|
|
293
|
+
use: ComponentType;
|
|
294
|
+
props?: Record<string, unknown>;
|
|
295
|
+
}
|
|
296
|
+
export interface FormBuilderConfigType {
|
|
297
|
+
name: string;
|
|
298
|
+
class: string;
|
|
299
|
+
props: {
|
|
300
|
+
schema: {
|
|
301
|
+
type: ObjectConstructor;
|
|
302
|
+
required: boolean;
|
|
303
|
+
};
|
|
304
|
+
uiSchema: {
|
|
305
|
+
type: ObjectConstructor;
|
|
306
|
+
required: boolean;
|
|
307
|
+
};
|
|
308
|
+
form: {
|
|
309
|
+
type: ObjectConstructor;
|
|
310
|
+
required: boolean;
|
|
311
|
+
};
|
|
312
|
+
components: {
|
|
313
|
+
type: ObjectConstructor;
|
|
314
|
+
required: boolean;
|
|
315
|
+
default: ComponentRegistry;
|
|
316
|
+
};
|
|
317
|
+
mode: {
|
|
318
|
+
type: StringConstructor;
|
|
319
|
+
default: ValidationMode;
|
|
320
|
+
options: ValidationMode[];
|
|
321
|
+
};
|
|
322
|
+
disabled: {
|
|
323
|
+
type: BooleanConstructor;
|
|
324
|
+
default: boolean;
|
|
325
|
+
};
|
|
326
|
+
readonly: {
|
|
327
|
+
type: BooleanConstructor;
|
|
328
|
+
default: boolean;
|
|
329
|
+
};
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
declare const FormBuilderConfig: FormBuilderConfigType;
|
|
333
|
+
export default FormBuilderConfig;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { FormBuilderProps } from './FormBuilder.config';
|
|
3
|
+
/**
|
|
4
|
+
* Main FormBuilder component
|
|
5
|
+
* @description Transforms JSON Schema and UI Schema into fully rendered form with validation, layout, and component integration
|
|
6
|
+
* @param schema JSONSchema7 defining field types, validation rules, and data structure
|
|
7
|
+
* @param uiSchema UI Schema defining layout, components, and presentation
|
|
8
|
+
* @param form Form state object from useForm hook containing data and validation
|
|
9
|
+
* @param components Optional custom component registry to override built-in components
|
|
10
|
+
* @param className Optional additional CSS classes for form container
|
|
11
|
+
* @param style Optional inline styles for form container
|
|
12
|
+
* @param testId Optional test identifier for form container
|
|
13
|
+
* @param disabled Optional global disabled state for all fields
|
|
14
|
+
* @param readonly Optional global readonly state for all fields
|
|
15
|
+
* @returns React element with complete rendered form
|
|
16
|
+
* @example
|
|
17
|
+
* ```tsx
|
|
18
|
+
* const form = FormBuilder.useForm({ schema: contactSchema, mode: 'onChange' });
|
|
19
|
+
*
|
|
20
|
+
* <FormBuilder
|
|
21
|
+
* schema={contactSchema}
|
|
22
|
+
* uiSchema={contactUISchema}
|
|
23
|
+
* form={form}
|
|
24
|
+
* components={{ CustomInput: MyInput }}
|
|
25
|
+
* className="my-form"
|
|
26
|
+
* testId="contact-form"
|
|
27
|
+
* />
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare const FormBuilder: React.FC<FormBuilderProps>;
|
|
31
|
+
export default FormBuilder;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { ComponentProps } from '../../FormBuilder.config';
|
|
3
|
+
/**
|
|
4
|
+
* AddressFormGroup - Native FormBuilder field group component
|
|
5
|
+
*
|
|
6
|
+
* @description Renders individual address fields that work directly with FormBuilder's
|
|
7
|
+
* field-by-field validation system. Unlike components that return objects, this renders
|
|
8
|
+
* multiple FormBuilder-compatible fields (address.postCode, address.state, etc).
|
|
9
|
+
*
|
|
10
|
+
* Key design:
|
|
11
|
+
* - Renders 7 individual fields, each validated independently
|
|
12
|
+
* - Each field uses form.setField() for native FormBuilder integration
|
|
13
|
+
* - Errors appear on the correct field automatically
|
|
14
|
+
* - No object conversion or validation hacks needed
|
|
15
|
+
* - Works in any fill order (not dependent on CEP being filled first)
|
|
16
|
+
*/
|
|
17
|
+
interface AddressResponse {
|
|
18
|
+
cep?: string;
|
|
19
|
+
uf?: string;
|
|
20
|
+
localidade?: string;
|
|
21
|
+
bairro?: string;
|
|
22
|
+
logradouro?: string;
|
|
23
|
+
complemento?: string;
|
|
24
|
+
erro?: boolean;
|
|
25
|
+
[key: string]: unknown;
|
|
26
|
+
}
|
|
27
|
+
export interface AddressFormGroupProps extends ComponentProps {
|
|
28
|
+
name: string;
|
|
29
|
+
__form?: {
|
|
30
|
+
data: Record<string, unknown>;
|
|
31
|
+
setField: (name: string, value: unknown) => void;
|
|
32
|
+
errors: Record<string, {
|
|
33
|
+
message?: string;
|
|
34
|
+
}>;
|
|
35
|
+
};
|
|
36
|
+
getAddress?: (postCode: string) => Promise<AddressResponse>;
|
|
37
|
+
title?: string;
|
|
38
|
+
labels?: {
|
|
39
|
+
postCode?: string;
|
|
40
|
+
state?: string;
|
|
41
|
+
city?: string;
|
|
42
|
+
suburb?: string;
|
|
43
|
+
street?: string;
|
|
44
|
+
number?: string;
|
|
45
|
+
complement?: string;
|
|
46
|
+
};
|
|
47
|
+
masks?: {
|
|
48
|
+
postCode?: string;
|
|
49
|
+
};
|
|
50
|
+
disabled?: boolean;
|
|
51
|
+
}
|
|
52
|
+
declare const AddressFormGroup: React.FC<AddressFormGroupProps>;
|
|
53
|
+
export default AddressFormGroup;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { FieldConfig, FieldRendererProps } from '../../FormBuilder.config';
|
|
3
|
+
/**
|
|
4
|
+
* Check if field should be rendered based on conditional logic
|
|
5
|
+
* @description Evaluates ui:show conditions and hidden flag to determine field visibility
|
|
6
|
+
* @param field FieldConfig containing conditional logic and hidden flag
|
|
7
|
+
* @param formData Current form data to evaluate conditions against
|
|
8
|
+
* @returns boolean indicating if field should be rendered
|
|
9
|
+
* @example
|
|
10
|
+
* ```tsx
|
|
11
|
+
* const shouldShow = shouldRenderField(
|
|
12
|
+
* { conditional: { field: 'userType', operator: '==', value: 'business' } },
|
|
13
|
+
* { userType: 'business' }
|
|
14
|
+
* ); // returns true
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare const shouldRenderField: (field: FieldConfig, formData: Record<string, unknown>) => boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Individual field renderer component
|
|
20
|
+
* @description Main component that renders form fields with component resolution and error handling
|
|
21
|
+
* @param field FieldConfig containing field configuration and layout
|
|
22
|
+
* @param form UseFormReturn with form state and validation
|
|
23
|
+
* @param components Optional custom component registry
|
|
24
|
+
* @param className Optional additional CSS classes
|
|
25
|
+
* @param disabled Optional global disabled state
|
|
26
|
+
* @param readonly Optional global readonly state
|
|
27
|
+
* @returns React element with rendered field component
|
|
28
|
+
* @example
|
|
29
|
+
* ```tsx
|
|
30
|
+
* <FieldRenderer
|
|
31
|
+
* field={fieldConfig}
|
|
32
|
+
* form={form}
|
|
33
|
+
* components={{ CustomInput: MyInput }}
|
|
34
|
+
* disabled={false}
|
|
35
|
+
* />
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare const FieldRenderer: React.FC<FieldRendererProps>;
|
|
39
|
+
export default FieldRenderer;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { ComponentProps, ComponentRegistry, FieldConfig, UISchemaField, UseFormReturn } from '../../FormBuilder.config';
|
|
3
|
+
/**
|
|
4
|
+
* Interface for GenericWrapper props
|
|
5
|
+
* @description Props for GenericWrapper component that renders a container with nested fields
|
|
6
|
+
*/
|
|
7
|
+
export interface GenericWrapperProps extends ComponentProps {
|
|
8
|
+
/** The wrapper component name (e.g., 'DsCard', 'DsNotification') */
|
|
9
|
+
__wrapperComponent?: string;
|
|
10
|
+
/** Child fields configuration to render inside the wrapper */
|
|
11
|
+
children?: Record<string, FieldConfig>;
|
|
12
|
+
/** Custom component registry for child fields */
|
|
13
|
+
components?: ComponentRegistry;
|
|
14
|
+
/** Form instance for managing child fields state */
|
|
15
|
+
__form?: UseFormReturn;
|
|
16
|
+
/** JSON Schema for legacy component integration */
|
|
17
|
+
__schema?: Record<string, unknown>;
|
|
18
|
+
/** UI Schema for child fields */
|
|
19
|
+
__uiSchema?: Record<string, UISchemaField>;
|
|
20
|
+
/** Horizontal gap spacing for grid layout (Design System spacing tokens: quark, nano, xs, sm, md, lg, xl, etc.) */
|
|
21
|
+
hGapSpacing?: string;
|
|
22
|
+
/** Vertical gap spacing for grid layout (Design System spacing tokens: quark, nano, xs, sm, md, lg, xl, etc.) */
|
|
23
|
+
vGapSpacing?: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* GenericWrapper Component
|
|
27
|
+
* @description Generic wrapper that can render any container component with nested FormBuilder fields as children
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```tsx
|
|
31
|
+
* // In UI Schema:
|
|
32
|
+
* riskInfo: {
|
|
33
|
+
* 'ui:component': 'GenericWrapper',
|
|
34
|
+
* 'ui:grid': { col: 12 },
|
|
35
|
+
* 'ui:props': {
|
|
36
|
+
* wrapperComponent: 'DsCard',
|
|
37
|
+
* elevation: 2,
|
|
38
|
+
* children: {
|
|
39
|
+
* effectiveDate: {
|
|
40
|
+
* name: 'effectiveDate',
|
|
41
|
+
* component: 'Input',
|
|
42
|
+
* type: 'string',
|
|
43
|
+
* label: 'Data de vigência',
|
|
44
|
+
* layout: { grid: { col: 6 } },
|
|
45
|
+
* // ... other FieldConfig properties
|
|
46
|
+
* },
|
|
47
|
+
* retroactivity: {
|
|
48
|
+
* name: 'retroactivity',
|
|
49
|
+
* component: 'Select',
|
|
50
|
+
* type: 'string',
|
|
51
|
+
* label: 'Retroatividade',
|
|
52
|
+
* layout: { grid: { col: 6 } },
|
|
53
|
+
* // ... other FieldConfig properties
|
|
54
|
+
* }
|
|
55
|
+
* }
|
|
56
|
+
* }
|
|
57
|
+
* }
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export declare const GenericWrapper: React.FC<GenericWrapperProps>;
|
|
61
|
+
export default GenericWrapper;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Option type for RadioGroup
|
|
4
|
+
*/
|
|
5
|
+
export interface RadioOption {
|
|
6
|
+
label: string | React.ReactNode;
|
|
7
|
+
value: string | number | boolean;
|
|
8
|
+
detail?: string;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Props for RadioGroup component
|
|
13
|
+
*/
|
|
14
|
+
export interface RadioGroupProps {
|
|
15
|
+
/** Field name */
|
|
16
|
+
name: string;
|
|
17
|
+
/** Array of options to render */
|
|
18
|
+
options: RadioOption[];
|
|
19
|
+
/** Current selected value */
|
|
20
|
+
value?: string | number | boolean;
|
|
21
|
+
/** Change handler */
|
|
22
|
+
onChange?: (value: string | number | boolean) => void;
|
|
23
|
+
/** Blur handler */
|
|
24
|
+
onBlur?: () => void;
|
|
25
|
+
/** Label for the radio group */
|
|
26
|
+
label?: string;
|
|
27
|
+
/** Error message */
|
|
28
|
+
error?: string;
|
|
29
|
+
/** Disabled state */
|
|
30
|
+
disabled?: boolean;
|
|
31
|
+
/** Flex direction: 'row' (horizontal) or 'column' (vertical) */
|
|
32
|
+
direction?: 'row' | 'column';
|
|
33
|
+
/** Justify content using Design System CSS classes */
|
|
34
|
+
justifyContent?: 'start' | 'end' | 'center' | 'beetwen' | 'around' | 'evenly';
|
|
35
|
+
/** Align items using Design System CSS classes */
|
|
36
|
+
alignItems?: 'start' | 'center' | 'end' | 'stretch';
|
|
37
|
+
/** Gap between options using Design System spacing */
|
|
38
|
+
gap?: 'none' | 'quark' | 'nano' | 'xxxs' | 'xxs' | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'xxl' | 'xxxl';
|
|
39
|
+
/** Test ID */
|
|
40
|
+
testId?: string;
|
|
41
|
+
/** Custom class name */
|
|
42
|
+
className?: string;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* RadioGroup Component
|
|
46
|
+
* @description Wrapper for DsOption that renders a radio group with flexbox layout control using Design System CSS classes
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```tsx
|
|
50
|
+
* <RadioGroup
|
|
51
|
+
* name="userType"
|
|
52
|
+
* label="Tipo de Usuário"
|
|
53
|
+
* options={[
|
|
54
|
+
* { label: 'Pessoa Física', value: 'PF' },
|
|
55
|
+
* { label: 'Pessoa Jurídica', value: 'PJ', detail: 'CNPJ obrigatório' },
|
|
56
|
+
* ]}
|
|
57
|
+
* value={formData.userType}
|
|
58
|
+
* onChange={(value) => setFormData({ ...formData, userType: value })}
|
|
59
|
+
* direction="row"
|
|
60
|
+
* justifyContent="start"
|
|
61
|
+
* alignItems="center"
|
|
62
|
+
* gap="md"
|
|
63
|
+
* />
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export declare const RadioGroup: React.FC<RadioGroupProps>;
|
|
67
|
+
export default RadioGroup;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { UseFormConfig, UseFormReturn } from '../FormBuilder.config';
|
|
2
|
+
/**
|
|
3
|
+
* Main form hook that composes state, validation, and parsing functionality
|
|
4
|
+
* @description Comprehensive form management hook combining state, validation, and parsing through composition
|
|
5
|
+
* @param config UseFormConfig with schema, initialData, validation mode, and custom validators
|
|
6
|
+
* @returns UseFormReturn with complete form interface including state, validation, and parsing methods
|
|
7
|
+
* @example
|
|
8
|
+
* ```tsx
|
|
9
|
+
* const form = useForm({
|
|
10
|
+
* schema: contactSchema,
|
|
11
|
+
* initialData: { name: '', email: '' },
|
|
12
|
+
* mode: ValidationMode.OnChange,
|
|
13
|
+
* customValidators: {
|
|
14
|
+
* uniqueEmail: async (value) => ({ isValid: !await emailExists(value), message: 'Email already exists' })
|
|
15
|
+
* }
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* // Use in component
|
|
19
|
+
* <FormBuilder schema={schema} uiSchema={uiSchema} form={form} />
|
|
20
|
+
*
|
|
21
|
+
* // Manual usage
|
|
22
|
+
* form.setField('name', 'John');
|
|
23
|
+
* const validation = await form.validate();
|
|
24
|
+
* if (validation.isValid) {
|
|
25
|
+
* const data = form.parse(); // Type-converted data
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare const useForm: (config: UseFormConfig) => UseFormReturn;
|
|
30
|
+
export default useForm;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { UseFormParserConfig, UseFormParserReturn } from '../FormBuilder.config';
|
|
2
|
+
/**
|
|
3
|
+
* Hook for parsing and type conversion based on JSON Schema
|
|
4
|
+
* Handles data transformation from string inputs to proper types
|
|
5
|
+
*/
|
|
6
|
+
export declare const useFormParser: (config: UseFormParserConfig) => UseFormParserReturn;
|
|
7
|
+
export default useFormParser;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|