Skip to content

Commit b198fd5

Browse files
committed
Update dependencies, Switch to TS
1 parent b921c64 commit b198fd5

10 files changed

+4265
-1828
lines changed

package-lock.json

Lines changed: 4117 additions & 1727 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,23 @@
33
"version": "0.1.0",
44
"private": true,
55
"dependencies": {
6-
"@jsonforms/core": "^2.0.12-rc.3",
7-
"@jsonforms/material-renderers": "^2.0.12-rc.3",
8-
"@material-ui/core": "^3.5.1",
9-
"react": "^16.3.0",
10-
"react-dom": "^16.3.0",
11-
"redux": "^3.7.2"
6+
"@jsonforms/core": "2.2.0",
7+
"@jsonforms/material-renderers": "2.2.0",
8+
"@jsonforms/react": "2.2.0",
9+
"@material-ui/core": "^3.9.0",
10+
"@types/jest": "^23.3.12",
11+
"@types/node": "^10.12.18",
12+
"@types/react": "^16.4.14",
13+
"@types/react-dom": "^16.0.11",
14+
"@types/react-redux": "^5.0.19",
15+
"react": "^16.4.0",
16+
"react-dom": "^16.4.0",
17+
"react-redux": "^6.0.0",
18+
"redux": "^3.7.2",
19+
"typescript": "^3.2.2"
1220
},
1321
"devDependencies": {
14-
"react-scripts": "^2.1.1"
22+
"react-scripts": "^2.1.3"
1523
},
1624
"scripts": {
1725
"start": "react-scripts start",

src/App.js

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

src/App.tsx

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

src/Rating.js renamed to src/Rating.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import * as React from 'react';
22

3-
export class Rating extends React.Component {
3+
// TODO: typings
4+
export class Rating extends React.Component<any, any> {
45

5-
constructor(props) {
6+
constructor(props: any) {
67
super(props);
78
this.state = {
89
rating: props.value,
910
hoverAt: null
1011
};
1112
}
1213

13-
static getDerivedStateFromProps = (nextProps, prevState) => {
14+
static getDerivedStateFromProps = (nextProps: any, prevState: any) => {
1415
if (prevState.rating !== nextProps.value) {
1516
return {
1617
rating: nextProps.value,
@@ -20,7 +21,7 @@ export class Rating extends React.Component {
2021
return null;
2122
};
2223

23-
handleMouseOver(idx) {
24+
handleMouseOver(idx: number) {
2425
this.setState({
2526
hoverAt: idx + 1
2627
});
@@ -32,7 +33,7 @@ export class Rating extends React.Component {
3233
});
3334
}
3435

35-
handleClick(idx) {
36+
handleClick(idx: number) {
3637
this.setState({
3738
rating: idx + 1
3839
});

src/RatingControl.js

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

src/RatingControl.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import * as React from 'react';
2+
import {mapDispatchToControlProps, mapStateToControlProps} from '@jsonforms/core';
3+
import {connect} from 'react-redux';
4+
import {Rating} from './Rating';
5+
6+
interface RatingControlProps {
7+
data: any;
8+
handleChange(path: string, value: any): void;
9+
path: string
10+
}
11+
12+
const RatingControl = ({ data, handleChange, path }: RatingControlProps) => (
13+
<Rating
14+
value={data}
15+
onClick={(ev: any) => handleChange(path, Number(ev.value))}
16+
/>
17+
);
18+
19+
export default connect(
20+
mapStateToControlProps,
21+
mapDispatchToControlProps,
22+
)(RatingControl as any);
File renamed without changes.

src/react-app-env.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference types="react-scripts" />

tsconfig.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es5",
4+
"allowJs": true,
5+
"lib": ["es2015", "dom"],
6+
"skipLibCheck": false,
7+
"esModuleInterop": true,
8+
"allowSyntheticDefaultImports": true,
9+
"strict": true,
10+
"forceConsistentCasingInFileNames": true,
11+
"module": "esnext",
12+
"moduleResolution": "node",
13+
"resolveJsonModule": true,
14+
"isolatedModules": true,
15+
"noEmit": true,
16+
"jsx": "preserve"
17+
},
18+
"include": [
19+
"src"
20+
]
21+
}

0 commit comments

Comments
 (0)