Created
September 17, 2022 15:56
-
-
Save Santheepkumar/fb7ea60be2e85d8247cc06ba8b1813e2 to your computer and use it in GitHub Desktop.
Proudof.jsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { | |
| CheckboxInput, | |
| Creatable, | |
| MultiSelectInput, | |
| NumberInput, | |
| RadioInput, | |
| SelectInput, | |
| TextAreaInput, | |
| TextInput, | |
| } from "../widgets"; | |
| const fieldComponentMapper = { | |
| text: TextInput, | |
| number: NumberInput, | |
| password: TextInput, | |
| textarea: TextAreaInput, | |
| select: SelectInput, | |
| multiselect: MultiSelectInput, | |
| checkbox: CheckboxInput, | |
| radio: RadioInput, | |
| creatablemultiselect: Creatable, | |
| }; | |
| function GetComponentForConfig({ fieldConfig, values }) { | |
| const FieldComponent = fieldComponentMapper[fieldConfig.type]; | |
| const hConfig = fieldConfig.show || []; | |
| if (FieldComponent) { | |
| return ( | |
| <> | |
| <FieldComponent key={fieldConfig.id} {...fieldConfig} /> | |
| {/* Dependent Fields */} | |
| {hConfig.map((hFieldConfig) => { | |
| if (fieldConfig?.if === values?.[fieldConfig.name]) { | |
| return ( | |
| <GetComponentForConfig | |
| key={hFieldConfig.id} | |
| fieldConfig={hFieldConfig} | |
| values={values} | |
| /> | |
| ); | |
| } | |
| })} | |
| </> | |
| ); | |
| } | |
| return <div>Unknown config</div>; | |
| } | |
| function FieldBuilder({ config, values }) { | |
| return ( | |
| <> | |
| {config.map((fieldConfig) => ( | |
| <GetComponentForConfig | |
| fieldConfig={fieldConfig} | |
| key={fieldConfig.id} | |
| values={values} | |
| /> | |
| ))} | |
| </> | |
| ); | |
| } | |
| export default FieldBuilder; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment