|
1 | 1 | - [Data Driven Forms Editor Pro](#data-driven-forms-editor-pro) |
| 2 | +- [Props](#props) |
| 3 | + - [fields](#fields) |
| 4 | + - [componentMapper](#componentmapper) |
| 5 | + - [componentInitialProps](#componentinitialprops) |
| 6 | + - [initialSchema](#initialschema) |
2 | 7 |
|
3 | 8 | # Data Driven Forms Editor Pro |
4 | 9 |
|
5 | | -Data Driven Forms Editor is editor to build complex Data Driven Forms. |
| 10 | +Data Driven Forms Editor is editor to build complex Data Driven Forms. |
| 11 | + |
| 12 | +# Props |
| 13 | + |
| 14 | +## fields |
| 15 | + |
| 16 | +A schema of the properties editor. You can use our predefined helper functions to create subsections. Check [`public/index.tsx`](./public/index.tsx) for an example |
| 17 | + |
| 18 | +```tsx |
| 19 | +const fields: Schema = { |
| 20 | + fields: [{ |
| 21 | + name: 'component', |
| 22 | + component: 'select', |
| 23 | + label: 'Component', |
| 24 | + description: 'Component type.', |
| 25 | + isRequired: true, |
| 26 | + validate: [{ type: 'required' }], |
| 27 | + options: Object.keys(componentMapper).map(key => ({ |
| 28 | + label: key.replaceAll('-', ' '), |
| 29 | + value: key |
| 30 | + })) |
| 31 | + }, { |
| 32 | + name: 'name', |
| 33 | + component: 'text-field', |
| 34 | + label: 'Name', |
| 35 | + description: 'Name of the field. You can use dot notation to nest variables.', |
| 36 | + isRequired: true, |
| 37 | + validate: [{ type: 'required' }] |
| 38 | + }] |
| 39 | +} |
| 40 | +``` |
| 41 | + |
| 42 | +## componentMapper |
| 43 | + |
| 44 | +A mapper of components you want to be able to edit. |
| 45 | + |
| 46 | +**Example** |
| 47 | + |
| 48 | +```tsx |
| 49 | +import { componentMapper } from '@data-driven-forms/mui-component-mapper'; |
| 50 | +``` |
| 51 | + |
| 52 | +## componentInitialProps |
| 53 | + |
| 54 | +An object to set initial props for components. For example, some components required props to be initialized. |
| 55 | + |
| 56 | +**Example** |
| 57 | + |
| 58 | +```tsx |
| 59 | +const componentInitialProps: AnyObject = { |
| 60 | + 'dual-list-select': { |
| 61 | + options: [] |
| 62 | + }, |
| 63 | + 'sub-form': { |
| 64 | + title: 'Sub form', |
| 65 | + fields: [] |
| 66 | + }, |
| 67 | + 'field-array': { |
| 68 | + fields: [] |
| 69 | + }, |
| 70 | + wizard: { |
| 71 | + fields: [{ name: 'step-1', fields: [] }] |
| 72 | + }, |
| 73 | + tabs: { |
| 74 | + fields: [] |
| 75 | + } |
| 76 | +}; |
| 77 | +``` |
| 78 | + |
| 79 | +## initialSchema |
| 80 | + |
| 81 | +Initial schema to be put in the editor. |
| 82 | + |
| 83 | +**Example** |
| 84 | + |
| 85 | +```tsx |
| 86 | +const initialSchema: Schema = { |
| 87 | + fields: [{ |
| 88 | + component: componentTypes.TEXT_FIELD, |
| 89 | + name: 'name', |
| 90 | + label: 'Your name', |
| 91 | + isRequired: true, |
| 92 | + validate: [{ type: validatorTypes.REQUIRED }] |
| 93 | + }, { |
| 94 | + component: componentTypes.TEXT_FIELD, |
| 95 | + name: 'email', |
| 96 | + label: 'Email', |
| 97 | + isRequired: true, |
| 98 | + validate: [ |
| 99 | + { type: validatorTypes.REQUIRED }, |
| 100 | + { |
| 101 | + type: validatorTypes.PATTERN, |
| 102 | + pattern: '[a-z0-9._%+-]+@[a-z0-9.-]+.[a-z]{2,}$', |
| 103 | + message: 'Not valid email' |
| 104 | + } |
| 105 | + ] |
| 106 | + },{ |
| 107 | + component: componentTypes.TEXT_FIELD, |
| 108 | + name: 'confirm-email', |
| 109 | + label: 'Confirm email', |
| 110 | + type: 'email', |
| 111 | + isRequired: true, |
| 112 | + },{ |
| 113 | + component: componentTypes.CHECKBOX, |
| 114 | + name: 'newsletters', |
| 115 | + label: 'I want to receive newsletter' |
| 116 | + }, { |
| 117 | + component: componentTypes.SUB_FORM, |
| 118 | + name: 'subform1', |
| 119 | + title: 'Additional info', |
| 120 | + fields: [ |
| 121 | + { |
| 122 | + component: componentTypes.TEXTAREA, |
| 123 | + name: 'address', |
| 124 | + label: 'Your address', |
| 125 | + } |
| 126 | + ] |
| 127 | + } |
| 128 | + ] |
| 129 | +}; |
| 130 | +``` |
0 commit comments