|
1 | | -import {connect} from 'react-redux'; |
2 | | -import React, {Component} from 'react'; |
3 | | -import logo from './logo.svg'; |
4 | | -import './App.css'; |
| 1 | +import { connect } from 'react-redux'; |
| 2 | +import React from 'react'; |
| 3 | +import Grid from "@material-ui/core/Grid"; |
| 4 | +import Typography from "@material-ui/core/Typography"; |
| 5 | +import withStyles from "@material-ui/core/styles/withStyles"; |
5 | 6 | import { getData } from '@jsonforms/core'; |
6 | 7 | import { JsonForms } from '@jsonforms/react'; |
| 8 | +import logo from './logo.svg'; |
| 9 | +import './App.css'; |
7 | 10 |
|
| 11 | +const styles = { |
| 12 | + container: { |
| 13 | + padding: '2em' |
| 14 | + }, |
| 15 | + title: { |
| 16 | + textAlign: 'center', |
| 17 | + padding: '0.25em' |
| 18 | + }, |
| 19 | + dataContent: { |
| 20 | + display: 'flex', |
| 21 | + justifyContent: 'center', |
| 22 | + borderRadius: '0.25em' |
| 23 | + }, |
| 24 | + demoform: { |
| 25 | + margin: 'auto' |
| 26 | + } |
| 27 | +}; |
8 | 28 |
|
9 | | -class App extends Component { |
10 | | - render() { |
11 | | - return ( |
12 | | - <div> |
13 | | - <div className="App"> |
14 | | - <header className="App-header"> |
15 | | - <img src={logo} className="App-logo" alt="logo" /> |
16 | | - <h1 className="App-title">Welcome to JSON Forms with React</h1> |
17 | | - <p className="App-intro">More Forms. Less Code.</p> |
18 | | - </header> |
19 | | - </div> |
20 | 29 |
|
21 | | - <h4 className="data-title">Bound data</h4> |
22 | | - <div className="data-content"> |
23 | | - <pre>{this.props.dataAsString}</pre> |
24 | | - </div> |
| 30 | +const App = ({ classes, dataAsString }) => ( |
| 31 | + <div> |
| 32 | + <div className="App"> |
| 33 | + <header className="App-header"> |
| 34 | + <img src={logo} className="App-logo" alt="logo" /> |
| 35 | + <h1 className="App-title">Welcome to JSON Forms with React</h1> |
| 36 | + <p className="App-intro">More Forms. Less Code.</p> |
| 37 | + </header> |
| 38 | + </div> |
25 | 39 |
|
26 | | - <div className="demoform"> |
| 40 | + <Grid container justify={'center'} spacing={24} className={classes.container}> |
| 41 | + <Grid item sm={3}> |
| 42 | + <Typography |
| 43 | + variant={'display1'} |
| 44 | + className={classes.title} |
| 45 | + > |
| 46 | + Bound data |
| 47 | + </Typography> |
| 48 | + <div className={classes.dataContent} style={{ backgroundColor: '#cecece'}}> |
| 49 | + <pre>{dataAsString}</pre> |
| 50 | + </div> |
| 51 | + </Grid> |
| 52 | + <Grid item sm={6}> |
| 53 | + <Typography |
| 54 | + variant={'display1'} |
| 55 | + className={classes.title} |
| 56 | + > |
| 57 | + Rendered form |
| 58 | + </Typography> |
| 59 | + <div className={classes.demoform}> |
27 | 60 | <JsonForms /> |
28 | 61 | </div> |
29 | | - </div> |
30 | | - ); |
31 | | - } |
32 | | - |
33 | | -} |
| 62 | + </Grid> |
| 63 | + </Grid> |
| 64 | + </div> |
| 65 | +); |
34 | 66 |
|
35 | 67 | const mapStateToProps = state => { |
36 | 68 | return { dataAsString: JSON.stringify(getData(state), null, 2) } |
37 | 69 | }; |
38 | 70 |
|
39 | | -export default connect(mapStateToProps, null)(App); |
| 71 | +export default connect(mapStateToProps, null)(withStyles(styles)(App)); |
40 | 72 |
|
0 commit comments