Skip to content
This repository was archived by the owner on Jun 1, 2020. It is now read-only.

Commit 655d128

Browse files
committed
Delete radio-choice example
Fix MenuItems onClick function Add liveValidation option and disabled
1 parent 0c57167 commit 655d128

File tree

8 files changed

+44
-67
lines changed

8 files changed

+44
-67
lines changed

example/src/body/Example.tsx

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,32 @@ import React from 'react';
22

33
import Box from '@material-ui/core/Box';
44
import Button from '@material-ui/core/Button';
5-
import { createStyles, withStyles } from '@material-ui/core/styles';
65
import Paper from '@material-ui/core/Paper';
76
import Typography from '@material-ui/core/Typography';
7+
import { withStyles } from '@material-ui/core/styles';
8+
9+
import { JSONSchema6 } from 'json-schema';
810

911
import styles from './example-styles';
1012
import Source from './Source';
1113

1214
import Form from '../../../src';
1315

14-
const formStyles = theme =>
15-
createStyles({
16-
field: {
17-
paddingLeft: theme.spacing.unit * 4,
18-
},
19-
formButtons: {
20-
order: 2,
21-
},
22-
root: {
23-
display: 'flex',
24-
padding: theme.spacing.unit,
25-
},
26-
});
16+
const liveSettingsSchema: JSONSchema6 = {
17+
type: 'object',
18+
properties: {
19+
validate: { type: 'boolean', title: 'Live validation' },
20+
disabled: { type: 'boolean', title: 'Disable whole form' },
21+
},
22+
};
2723

2824
class Example extends React.Component<any, any> {
2925
state = {
3026
...this.props.data,
27+
liveSettings: {
28+
validate: true,
29+
disabled: false,
30+
},
3131
};
3232

3333
componentWillReceiveProps = ({ data }) => {
@@ -47,25 +47,39 @@ class Example extends React.Component<any, any> {
4747
};
4848

4949
onSubmit = value => {
50-
console.log('onSubmit:', value); // eslint-disable-line no-console
50+
console.log('onSubmit:', value);
5151
};
5252

5353
onCancel = () => {
5454
const { data } = this.props;
55+
5556
this.setState({
5657
...data,
5758
});
5859
};
5960

61+
setLiveSettings = ({ formData }: any) =>
62+
this.setState({ liveSettings: formData });
63+
6064
render() {
6165
const { data, classes } = this.props;
6266
const { title } = data;
63-
const { schema, uiSchema, formData } = this.state;
67+
const { schema, uiSchema, formData, liveSettings } = this.state;
68+
6469
return (
6570
<Paper className={classes.root}>
66-
<Typography component="h4" variant="h4">
67-
{title}
68-
</Typography>
71+
<>
72+
<Typography component="h4" variant="h4">
73+
{title}
74+
</Typography>
75+
<Form
76+
schema={liveSettingsSchema}
77+
formData={liveSettings}
78+
onChange={this.setLiveSettings}
79+
>
80+
<div />
81+
</Form>
82+
</>
6983
<br />
7084
<div className={classes.ctr}>
7185
<div className={classes.sourceCtr}>
@@ -98,8 +112,8 @@ class Example extends React.Component<any, any> {
98112
formData={formData}
99113
onSubmit={this.onSubmit}
100114
onChange={this.onFormChanged}
101-
//showErrorList={showErrorList}
102-
//showHelperError={showHelperError}
115+
liveValidate={liveSettings.validate}
116+
disabled={liveSettings.disabled}
103117
>
104118
<Box mt={2}>
105119
<Button

example/src/examples/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import budget from './budget';
33
import nested from './nested';
44
import numbers from './numbers';
55
import multipleChoice from './multiple-choice';
6-
import radioChoice from './radio-choice';
76
import simple from './simple';
87
import single from './single';
98
import validation from './validation';
@@ -14,8 +13,7 @@ export default {
1413
nested,
1514
numbers,
1615
multipleChoice,
17-
radioChoice,
1816
simple,
1917
single,
2018
validation,
21-
};
19+
};

example/src/examples/radio-choice/form-data.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

example/src/examples/radio-choice/index.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

example/src/examples/radio-choice/schema.json

Lines changed: 0 additions & 15 deletions
This file was deleted.

example/src/examples/radio-choice/ui-schema.json

Lines changed: 0 additions & 8 deletions
This file was deleted.

example/src/menu/LeftDrawer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import menuStyles from './menu-styles';
99

1010
export default withStyles(menuStyles)(
1111
({ classes, open, toggleDrawer, onSelectMenuItem }: any) => (
12-
<div>
12+
<>
1313
<Hidden only={['xs', 'sm', 'md']}>
1414
<Drawer variant={'permanent'} className={classes.permanentLeftDrawer}>
1515
<MenuItems
@@ -30,6 +30,6 @@ export default withStyles(menuStyles)(
3030
/>
3131
</Drawer>
3232
</Hidden>
33-
</div>
33+
</>
3434
)
3535
);

example/src/menu/MenuItems.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ export default withStyles(menuStyles)(
2323
>
2424
<List subheader={<ListSubheader component="div">Showcase</ListSubheader>}>
2525
{keys(examples).map(e => (
26-
<ListItem key={e} button>
27-
<ListItemText
28-
primary={examples[e].title}
29-
onClick={onSelectMenuItem(examples[e])}
30-
/>
26+
<ListItem
27+
key={e}
28+
button={true}
29+
onClick={onSelectMenuItem(examples[e])}
30+
>
31+
<ListItemText primary={examples[e].title} />
3132
</ListItem>
3233
))}
3334
</List>

0 commit comments

Comments
 (0)