forked from data-driven-forms/editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.tsx
83 lines (75 loc) · 1.83 KB
/
index.tsx
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
75
76
77
78
79
80
81
82
83
import React from 'react';
import ReactDOM from 'react-dom';
import { componentMapper } from '@data-driven-forms/mui-component-mapper';
import Editor from '../src/editor';
import propertiesFields from '../src/editor/properties-fields';
import { AnyObject } from '../src/types';
import { componentTypes, Schema, validatorTypes } from '@data-driven-forms/react-form-renderer';
const componentInitialProps: AnyObject = {
'dual-list-select': {
options: []
},
'sub-form': {
title: 'Sub form',
fields: []
},
'field-array': {
fields: []
},
wizard: {
fields: [{ name: 'step-1', fields: [] }]
},
tabs: {
fields: []
}
};
const fields = propertiesFields({ componentMapper });
const initialSchema: Schema = {
fields: [{
component: componentTypes.TEXT_FIELD,
name: 'name',
label: 'Your name',
isRequired: true,
validate: [{ type: validatorTypes.REQUIRED }]
}, {
component: componentTypes.TEXT_FIELD,
name: 'email',
label: 'Email',
isRequired: true,
validate: [
{ type: validatorTypes.REQUIRED },
{
type: validatorTypes.PATTERN,
pattern: '[a-z0-9._%+-]+@[a-z0-9.-]+.[a-z]{2,}$',
message: 'Not valid email'
}
]
},{
component: componentTypes.TEXT_FIELD,
name: 'confirm-email',
label: 'Confirm email',
type: 'email',
isRequired: true,
},{
component: componentTypes.CHECKBOX,
name: 'newsletters',
label: 'I want to receive newsletter'
}, {
component: componentTypes.SUB_FORM,
name: 'subform1',
title: 'Additional info',
fields: [
{
component: componentTypes.TEXTAREA,
name: 'address',
label: 'Your address',
}
]
}
]
};
const App = () => <Editor fields={fields} componentMapper={componentMapper} componentInitialProps={componentInitialProps} initialSchema={initialSchema} />;
ReactDOM.render(
<App />,
document.getElementById('root')
);