-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathReactForm.tsx
More file actions
74 lines (64 loc) · 2.04 KB
/
ReactForm.tsx
File metadata and controls
74 lines (64 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import * as React from 'react';
import { MLFormBuilder, RowSchema, IFormActionProps, BuilderSettingsProps } from './ml-form-builder';
import { Formik, FormikConfig, FormikValues } from 'formik';
export * from './ml-form-builder';
export * from './ml-form-builder/lib';
export * from './ml-form-builder/Utils'
/**
* type1 - (text, password, email, number) will render text field with respective type, default text
* type2 - select/multiselect - options([{key:val}] or [string])
* type3 - checkbox/toggle - options([{key:val}] or [string])
* type4 - radio/switch - options([{key:val}] or [string])
*
*/
/**
* condition:{
* defaultState:'disable/hide',
* defaultProps:{},
* logicOpn 'AND|OR',
* postEffect:'enable',
* postEffectProps:{},
* valueFn:Function,
* values:[{
* key:'xyz',
* compareValue:'abc',
* operator:'==',
* },{
* key:'abc',
* compareValue:4,
* operator:'>='
* }]
* }
*/
export interface IReactFormProps<T = any> extends FormikValues {
config: Array<RowSchema>,
formId: string,
innerRef?: FormikConfig<T>['innerRef']
actionConfig: IFormActionProps
formSettings?: BuilderSettingsProps
isInProgress?: boolean
isReadOnly?: boolean
}
export function ReactForm<T>(props: IReactFormProps<T>) {
const { config, innerRef, formId, initialValues = {}, onSubmit, actionConfig, formSettings, isInProgress = false, isReadOnly = false, ...formikProps } = props;
return (
<Formik<T>
innerRef={innerRef}
initialValues={initialValues}
onSubmit={onSubmit}
{...formikProps}
>
{
formProps => (<MLFormBuilder
schema={config}
formId={formId}
actionConfig={actionConfig}
settings={{ ...formSettings, isReadOnly }}
formikProps={formProps}
isInProgress={isInProgress}
/>)
}
</Formik>
)
}
export default ReactForm;