|
1 | | -/* eslint-disable */ |
2 | | -import React from "react"; |
3 | | -import ReactDOM from "react-dom"; |
| 1 | +import React from 'react'; |
| 2 | +import { createRoot } from 'react-dom/client'; |
4 | 3 | import { FormRenderer } from '@data-driven-forms/react-form-renderer'; |
5 | 4 | import { arraySchemaDDF } from './demo-schemas/widget-schema'; |
6 | 5 | import { componentMapper, FormTemplate } from '../src'; |
7 | | -import { Title, Button, Toolbar, ToolbarGroup, ToolbarItem, Modal } from '@patternfly/react-core'; |
8 | | -import { wizardSchema, wizardSchemaWithFunction, wizardSchemaSimple, wizardSchemaSubsteps, wizardSchemaMoreSubsteps } from './demo-schemas/wizard-schema'; |
| 6 | +import { Title, Button, Toolbar, ToolbarGroup, ToolbarItem } from '@patternfly/react-core'; |
| 7 | +import { |
| 8 | + wizardSchema, |
| 9 | + wizardSchemaWithFunction, |
| 10 | + wizardSchemaSimple, |
| 11 | + wizardSchemaSubsteps, |
| 12 | + wizardSchemaMoreSubsteps, |
| 13 | +} from './demo-schemas/wizard-schema'; |
9 | 14 | import sandboxSchema from './demo-schemas/sandbox'; |
10 | 15 | import dualSchema from './demo-schemas/dual-list-schema'; |
11 | 16 | import demoSchema from '../../../shared/demoschema'; |
12 | 17 | import selectSchema from './demo-schemas/select-schema'; |
13 | 18 |
|
14 | | -const Summary = props => <div>Custom summary component.</div>; |
| 19 | +const Summary = (props) => <div>Custom summary component.</div>; |
15 | 20 |
|
16 | | -const fieldArrayState = { schema: arraySchemaDDF, additionalOptions: { |
| 21 | +const fieldArrayState = { |
| 22 | + schema: arraySchemaDDF, |
| 23 | + additionalOptions: { |
17 | 24 | initialValues: { |
18 | | - number: [1,2,3,4], |
19 | | - minMax: [null, null, null, null] |
20 | | - } |
21 | | -}}; |
| 25 | + number: [1, 2, 3, 4], |
| 26 | + minMax: [null, null, null, null], |
| 27 | + }, |
| 28 | + }, |
| 29 | +}; |
22 | 30 |
|
23 | 31 | class App extends React.Component { |
24 | | - constructor(props) { |
25 | | - super(props); |
26 | | - this.state = {schema: wizardSchema, additionalOptions: {}} |
27 | | - } |
| 32 | + constructor(props) { |
| 33 | + super(props); |
| 34 | + this.state = { schema: wizardSchema, additionalOptions: {} }; |
| 35 | + } |
28 | 36 |
|
29 | | - render() { |
30 | | - return (<div style={{ widht: '100%' }}> |
| 37 | + render() { |
| 38 | + return ( |
| 39 | + <div style={{ widht: '100%' }}> |
31 | 40 | <div style={{ maxWidth: 800, marginLeft: 'auto', marginRight: 'auto' }}> |
32 | | - <Title headingLevel="h2" size="4xl">Pf4 component mapper</Title> |
33 | | - <Toolbar style={{ marginBottom: 20, marginTop: 20 }}> |
34 | | - <ToolbarGroup> |
35 | | - <ToolbarItem> |
36 | | - <Button onClick={() => this.setState(state => ({schema: selectSchema, additionalOptions: {}}))}>select schema</Button> |
37 | | - </ToolbarItem> |
38 | | - <ToolbarItem> |
39 | | - <Button onClick={() => this.setState(state => ({ schema: wizardSchema, additionalOptions: { showFormControls: false, wizard: true } }))}>Wizard</Button> |
40 | | - </ToolbarItem> |
41 | | - <ToolbarItem> |
42 | | - <Button onClick={() => this.setState(state => fieldArrayState)}>arraySchema</Button> |
43 | | - </ToolbarItem> |
44 | | - <ToolbarItem> |
45 | | - <Button onClick={() => this.setState(state => ({ schema: sandboxSchema, additionalOptions: {}}))}>Sandbox</Button> |
46 | | - </ToolbarItem> |
47 | | - <ToolbarItem> |
48 | | - <Button onClick={() => this.setState(state => ({ schema: demoSchema, additionalOptions: {}}))}>Super schema</Button> |
49 | | - </ToolbarItem> |
50 | | - <ToolbarItem> |
51 | | - <Button onClick={() => this.setState(state => ({ schema: dualSchema, additionalOptions: {} }))}>Dual List</Button> |
52 | | - </ToolbarItem> |
53 | | - </ToolbarGroup> |
54 | | - </Toolbar> |
55 | | - <FormRenderer |
| 41 | + <Title headingLevel="h2" size="4xl"> |
| 42 | + Pf4 component mapper |
| 43 | + </Title> |
| 44 | + <Toolbar style={{ marginBottom: 20, marginTop: 20 }}> |
| 45 | + <ToolbarGroup> |
| 46 | + <ToolbarItem> |
| 47 | + <Button onClick={() => this.setState((state) => ({ schema: selectSchema, additionalOptions: {} }))}>select schema</Button> |
| 48 | + </ToolbarItem> |
| 49 | + <ToolbarItem> |
| 50 | + <Button |
| 51 | + onClick={() => this.setState((state) => ({ schema: wizardSchema, additionalOptions: { showFormControls: false, wizard: true } }))} |
| 52 | + > |
| 53 | + Wizard |
| 54 | + </Button> |
| 55 | + </ToolbarItem> |
| 56 | + <ToolbarItem> |
| 57 | + <Button onClick={() => this.setState((state) => fieldArrayState)}>arraySchema</Button> |
| 58 | + </ToolbarItem> |
| 59 | + <ToolbarItem> |
| 60 | + <Button onClick={() => this.setState((state) => ({ schema: sandboxSchema, additionalOptions: {} }))}>Sandbox</Button> |
| 61 | + </ToolbarItem> |
| 62 | + <ToolbarItem> |
| 63 | + <Button onClick={() => this.setState((state) => ({ schema: demoSchema, additionalOptions: {} }))}>Super schema</Button> |
| 64 | + </ToolbarItem> |
| 65 | + <ToolbarItem> |
| 66 | + <Button onClick={() => this.setState((state) => ({ schema: dualSchema, additionalOptions: {} }))}>Dual List</Button> |
| 67 | + </ToolbarItem> |
| 68 | + </ToolbarGroup> |
| 69 | + </Toolbar> |
| 70 | + <FormRenderer |
| 71 | + onSubmit={console.log} |
| 72 | + initialValues={{ |
| 73 | + 'simple-select': 'Kay', |
| 74 | + 'simple-async-select': 'Jenifer', |
| 75 | + 'simple-searchable-async-select': 'Jenifer', |
| 76 | + 'simple-portal-select': 'Jenifer', |
| 77 | + }} |
| 78 | + componentMapper={{ |
| 79 | + ...componentMapper, |
| 80 | + 'dual-list-select': { |
| 81 | + component: componentMapper['dual-list-select'], |
| 82 | + renderStatus: ({ selected, options }) => `selected ${selected} from ${options}`, |
| 83 | + }, |
| 84 | + summary: Summary, |
| 85 | + }} |
| 86 | + FormTemplate={(props) => <FormTemplate {...props} showFormControls={this.state.additionalOptions.showFormControls} />} |
| 87 | + onCancel={console.log} |
| 88 | + schema={this.state.schema} |
| 89 | + uiSchema={this.state.ui} |
| 90 | + {...this.state.additionalOptions} |
| 91 | + /> |
| 92 | + {this.state.additionalOptions.wizard && ( |
| 93 | + <> |
| 94 | + <div>Nextstep function</div> |
| 95 | + <FormRenderer |
56 | 96 | onSubmit={console.log} |
57 | | - initialValues={{ |
58 | | - 'simple-select': 'Kay', |
59 | | - 'simple-async-select': 'Jenifer', |
60 | | - 'simple-searchable-async-select': 'Jenifer', |
61 | | - 'simple-portal-select': 'Jenifer' |
| 97 | + componentMapper={{ |
| 98 | + ...componentMapper, |
| 99 | + summary: Summary, |
| 100 | + }} |
| 101 | + onCancel={() => console.log('Cancel action')} |
| 102 | + FormTemplate={(props) => <FormTemplate {...props} showFormControls={this.state.additionalOptions.showFormControls} />} |
| 103 | + schema={wizardSchemaWithFunction} |
| 104 | + {...this.state.additionalOptions} |
| 105 | + /> |
| 106 | + <div>Substeps</div> |
| 107 | + <FormRenderer |
| 108 | + onSubmit={console.log} |
| 109 | + componentMapper={{ |
| 110 | + ...componentMapper, |
| 111 | + summary: Summary, |
| 112 | + }} |
| 113 | + onCancel={() => console.log('Cancel action')} |
| 114 | + schema={wizardSchemaSubsteps} |
| 115 | + FormTemplate={(props) => <FormTemplate {...props} showFormControls={this.state.additionalOptions.showFormControls} />} |
| 116 | + {...this.state.additionalOptions} |
| 117 | + /> |
| 118 | + <div>More substep</div> |
| 119 | + <FormRenderer |
| 120 | + onSubmit={console.log} |
| 121 | + componentMapper={{ |
| 122 | + ...componentMapper, |
| 123 | + summary: Summary, |
62 | 124 | }} |
| 125 | + onCancel={() => console.log('Cancel action')} |
| 126 | + schema={wizardSchemaMoreSubsteps} |
| 127 | + FormTemplate={(props) => <FormTemplate {...props} showFormControls={this.state.additionalOptions.showFormControls} />} |
| 128 | + {...this.state.additionalOptions} |
| 129 | + /> |
| 130 | + <div>Simple wizard</div> |
| 131 | + <FormRenderer |
| 132 | + onSubmit={console.log} |
63 | 133 | componentMapper={{ |
64 | | - ...componentMapper, |
65 | | - 'dual-list-select': { |
66 | | - component: componentMapper['dual-list-select'], |
67 | | - renderStatus: ({selected, options}) => `selected ${selected} from ${options}` |
68 | | - }, |
69 | | - summary: Summary |
| 134 | + ...componentMapper, |
| 135 | + summary: Summary, |
70 | 136 | }} |
| 137 | + onCancel={() => console.log('Cancel action')} |
| 138 | + schema={wizardSchemaSimple} |
71 | 139 | FormTemplate={(props) => <FormTemplate {...props} showFormControls={this.state.additionalOptions.showFormControls} />} |
72 | | - onCancel={console.log} |
73 | | - schema={this.state.schema} |
74 | | - uiSchema={this.state.ui} |
75 | 140 | {...this.state.additionalOptions} |
76 | | - /> |
77 | | - {this.state.additionalOptions.wizard && <> |
78 | | - <div>Nextstep function</div> |
79 | | - <FormRenderer |
80 | | - onSubmit={console.log} |
81 | | - componentMapper={{ |
82 | | - ...componentMapper, |
83 | | - summary: Summary |
84 | | - }} |
85 | | - onCancel={() => console.log('Cancel action')} |
86 | | - FormTemplate={(props) => <FormTemplate {...props} showFormControls={this.state.additionalOptions.showFormControls} />} |
87 | | - schema={wizardSchemaWithFunction} |
88 | | - {...this.state.additionalOptions} |
89 | | - /> |
90 | | - <div>Substeps</div> |
91 | | - <FormRenderer |
92 | | - onSubmit={console.log} |
93 | | - componentMapper={{ |
94 | | - ...componentMapper, |
95 | | - summary: Summary |
96 | | - }} |
97 | | - onCancel={() => console.log('Cancel action')} |
98 | | - schema={wizardSchemaSubsteps} |
99 | | - FormTemplate={(props) => <FormTemplate {...props} showFormControls={this.state.additionalOptions.showFormControls} />} |
100 | | - {...this.state.additionalOptions} |
101 | | - /> |
102 | | - <div>More substep</div> |
103 | | - <FormRenderer |
104 | | - onSubmit={console.log} |
105 | | - componentMapper={{ |
106 | | - ...componentMapper, |
107 | | - summary: Summary |
108 | | - }} |
109 | | - onCancel={() => console.log('Cancel action')} |
110 | | - schema={wizardSchemaMoreSubsteps} |
111 | | - FormTemplate={(props) => <FormTemplate {...props} showFormControls={this.state.additionalOptions.showFormControls} />} |
112 | | - {...this.state.additionalOptions} |
113 | | - /> |
114 | | - <div>Simple wizard</div> |
115 | | - <FormRenderer |
116 | | - onSubmit={console.log} |
117 | | - componentMapper={{ |
118 | | - ...componentMapper, |
119 | | - summary: Summary |
120 | | - }} |
121 | | - onCancel={() => console.log('Cancel action')} |
122 | | - schema={wizardSchemaSimple} |
123 | | - FormTemplate={(props) => <FormTemplate {...props} showFormControls={this.state.additionalOptions.showFormControls} />} |
124 | | - {...this.state.additionalOptions} |
125 | | - /> |
126 | | - </>} |
| 141 | + /> |
| 142 | + </> |
| 143 | + )} |
127 | 144 | </div> |
128 | | - </div>) |
129 | | - }; |
| 145 | + </div> |
| 146 | + ); |
| 147 | + } |
130 | 148 | } |
131 | 149 |
|
132 | | -ReactDOM.render(<App />, document.getElementById('root')); |
| 150 | +const container = document.getElementById('root'); |
| 151 | +const root = createRoot(container); |
| 152 | +root.render(<App />); |
0 commit comments