Skip to content

Commit a35ae60

Browse files
changed theme.js to theme.ts with interfaces
1 parent ff1511c commit a35ae60

File tree

9 files changed

+69
-46
lines changed

9 files changed

+69
-46
lines changed

src/components/App.jsx renamed to src/components/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { Component } from 'react';
22
import '../public/styles/style.css';
33
import { MuiThemeProvider } from '@material-ui/core/styles';
4-
import theme from './theme';
4+
import theme from './theme.ts';
55
import AppContainer from '../containers/AppContainer.jsx';
66

77
class App extends Component {

src/components/HTMLComponentPanel.jsx

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,43 @@
1-
import React, { Component } from "react";
2-
import { connect } from "react-redux";
3-
import { compose } from "redux";
4-
import { withStyles } from "@material-ui/core/styles";
5-
import TextField from "@material-ui/core/TextField";
6-
import IconButton from "@material-ui/core/IconButton";
7-
import ImageIcon from "@material-ui/icons/Image";
8-
import FormIcon from "@material-ui/icons/Description";
9-
import ButtonIcon from "@material-ui/icons/EditAttributes";
10-
import LinkIcon from "@material-ui/icons/Link";
11-
import ListIcon from "@material-ui/icons/List";
12-
import ParagraphIcon from "@material-ui/icons/LocalParking";
13-
import theme from "../components/theme";
1+
import React, { Component } from 'react';
2+
import { connect } from 'react-redux';
3+
import { compose } from 'redux';
4+
import { withStyles } from '@material-ui/core/styles';
5+
import TextField from '@material-ui/core/TextField';
6+
import IconButton from '@material-ui/core/IconButton';
7+
import ImageIcon from '@material-ui/icons/Image';
8+
import FormIcon from '@material-ui/icons/Description';
9+
import ButtonIcon from '@material-ui/icons/EditAttributes';
10+
import LinkIcon from '@material-ui/icons/Link';
11+
import ListIcon from '@material-ui/icons/List';
12+
import ParagraphIcon from '@material-ui/icons/LocalParking';
1413
import Typography from '@material-ui/core/Typography';
15-
import Grid from "@material-ui/core/Grid";
16-
import Paper from "@material-ui/core/Paper";
14+
import Grid from '@material-ui/core/Grid';
15+
import Paper from '@material-ui/core/Paper';
16+
import theme from './theme.ts';
1717
// import {HTMLelements,getSize} from "../utils/htmlElements.util";
1818

19-
2019
class HTMLComponentPanel extends Component {
2120
state = {
22-
HtmlComponentName: ""
21+
HtmlComponentName: '',
2322
};
2423

25-
handleChange = event => {
24+
handleChange = (event) => {
2625
this.setState({
27-
HtmlComponentName: event.target.value
26+
HtmlComponentName: event.target.value,
2827
});
2928
};
3029

31-
handleCreateHTMLChild = type => {
30+
handleCreateHTMLChild = (type) => {
3231
this.props.addChild({ title: type, childType: type, HTMLInfo: {} });
3332
};
3433

3534
render() {
3635
const { addChild } = this.props;
3736
return (
38-
<Paper className={"htmlPanelz"}>
37+
<Paper className={'htmlPanelz'}>
3938
<Typography variant="title" component="h3">
40-
Add HTML elements
41-
</Typography>
39+
Add HTML elements
40+
</Typography>
4241
{/* <TextField
4342
id="title-input"
4443
label="Add HTML component"
@@ -61,7 +60,7 @@ class HTMLComponentPanel extends Component {
6160
<IconButton
6261
aria-label="Image"
6362
onClick={() => {
64-
this.handleCreateHTMLChild("Image");
63+
this.handleCreateHTMLChild('Image');
6564
}}
6665

6766
// onClick={() => {
@@ -76,7 +75,7 @@ class HTMLComponentPanel extends Component {
7675
<IconButton
7776
aria-label="Form"
7877
onClick={() => {
79-
this.handleCreateHTMLChild("Form");
78+
this.handleCreateHTMLChild('Form');
8079
}}
8180
>
8281
<FormIcon />
@@ -86,7 +85,7 @@ class HTMLComponentPanel extends Component {
8685
<IconButton
8786
aria-label="Button"
8887
onClick={() => {
89-
this.handleCreateHTMLChild("Button");
88+
this.handleCreateHTMLChild('Button');
9089
}}
9190
>
9291
<ButtonIcon />
@@ -96,7 +95,7 @@ class HTMLComponentPanel extends Component {
9695
<IconButton
9796
aria-label="Link"
9897
onClick={() => {
99-
this.handleCreateHTMLChild("Link");
98+
this.handleCreateHTMLChild('Link');
10099
}}
101100
>
102101
<LinkIcon />
@@ -106,7 +105,7 @@ class HTMLComponentPanel extends Component {
106105
<IconButton
107106
aria-label="List"
108107
onClick={() => {
109-
this.handleCreateHTMLChild("List");
108+
this.handleCreateHTMLChild('List');
110109
}}
111110
>
112111
<ListIcon />
@@ -116,7 +115,7 @@ class HTMLComponentPanel extends Component {
116115
<IconButton
117116
aria-label="Paragraph"
118117
onClick={() => {
119-
this.handleCreateHTMLChild("Paragraph");
118+
this.handleCreateHTMLChild('Paragraph');
120119
}}
121120
>
122121
<ParagraphIcon />

src/components/__tests__/App.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
// import '../../setupTests';
33
import { shallow } from 'enzyme';
4-
import App from '../App.jsx';
4+
import App from '../App.tsx';
55
import AppContainer from '../../containers/AppContainer.jsx';
66

77
it('contains a AppContainer', () => {

src/components/theme.js renamed to src/components/theme.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,16 @@ import { createMuiTheme } from '@material-ui/core/styles';
22
// import teal from '@material-ui/core/colors/teal';
33
import indigo from '@material-ui/core/colors/indigo';
44

5-
const theme = createMuiTheme({
5+
interface palette {
6+
primary: object;
7+
secondary: any;
8+
}
9+
10+
interface theme {
11+
palette: palette;
12+
}
13+
14+
const theme: theme = createMuiTheme({
615
palette: {
716
primary: {
817
light: '#00e676',

src/containers/AppContainer.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import LeftContainer from './LeftContainer.jsx';
77
import MainContainer from './MainContainer.jsx';
88
import RightContainer from './RightContainer.jsx';
99
import convertIdsToObjs from '../utils/convertIdsToObjs.util';
10-
import theme from '../components/theme';
10+
import theme from '../components/theme.ts';
1111
import { loadInitData } from '../actions/components';
1212

1313
const mapStateToProps = store => ({

src/containers/MainContainer.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import List from '@material-ui/core/List';
66
import ListItem from '@material-ui/core/ListItem';
77
import ListItemText from '@material-ui/core/ListItemText';
88
import BottomPanel from '../components/BottomPanel.jsx';
9-
import theme from '../components/theme';
9+
import theme from '../components/theme.ts';
1010
import {
1111
openExpansionPanel,
1212
handleTransform,

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import 'babel-polyfill';
22
import React from 'react';
33
import ReactDOM from 'react-dom';
44
import { Provider } from 'react-redux';
5-
import App from './components/App.jsx';
5+
import App from './components/App.tsx';
66
import store from './store';
77

88
ReactDOM.render(

src/utils/componentRender.util.js

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
const componentRender = (component) => {
1+
const componentRender = (component, data) => {
22
const {
3-
stateful,
4-
children,
5-
title,
6-
props,
3+
stateful, children, title, props,
74
} = component;
85

96
if (stateful) {
@@ -21,14 +18,22 @@ const componentRender = (component) => {
2118
const { ${props.map(p => `${p.key}`).join(', ')} } = this.props;
2219
return (
2320
<div>
24-
${children.map(child => `<${child.title} ${child.props.map(prop => `${prop.key}={${prop.value}}`).join(' ')}/>`).join('\n')}
21+
${children
22+
.map(
23+
child => `<${child.title} ${child.props
24+
.map(prop => `${prop.key}={${prop.value}}`)
25+
.join(' ')}/>`,
26+
)
27+
.join('\n')}
2528
</div>
2629
)
2730
}
2831
}
2932
3033
${title}.propTypes = {
31-
${props.map(p => `${p.key}: PropTypes.${p.type}${p.required ? '.isRequired' : ''},`).join('\n')}
34+
${props
35+
.map(p => `${p.key}: PropTypes.${p.type}${p.required ? '.isRequired' : ''},`)
36+
.join('\n')}
3237
}
3338
3439
export default ${title};
@@ -42,12 +47,20 @@ const componentRender = (component) => {
4247
4348
const ${title} = props => (
4449
<div>
45-
${children.map(child => `<${child.title} ${child.props.map(prop => `${prop.key}={${prop.value}}`).join(' ')}/>`).join('\n')}
50+
${children
51+
.map(
52+
child => `<${child.title} ${child.props
53+
.map(prop => `${prop.key}={${prop.value}}`)
54+
.join(' ')}/>`,
55+
)
56+
.join('\n')}
4657
</div>
4758
);
4859
4960
${title}.propTypes = {
50-
${props.map(p => `${p.key}: PropTypes.${p.type}${p.required ? '.isRequired' : ''},`).join('\n')}
61+
${props
62+
.map(p => `${p.key}: PropTypes.${p.type}${p.required ? '.isRequired' : ''},`)
63+
.join('\n')}
5164
}
5265
5366
export default ${title};

src/utils/createFiles.util.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ const createFiles = (data, path) => {
1616
const promises = [];
1717
data.forEach((component) => {
1818
const newPromise = new Promise((resolve, reject) => {
19-
fs.writeFile(`${dir}/${component.title}.tsx`,
19+
fs.writeFile(
20+
`${dir}/${component.title}.tsx`,
2021
format(componentRender(component, data), {
2122
singleQuote: true,
2223
trailingComma: 'es5',
@@ -27,7 +28,8 @@ const createFiles = (data, path) => {
2728
(err) => {
2829
if (err) return reject(err.message);
2930
return resolve(path);
30-
});
31+
},
32+
);
3133
});
3234

3335
promises.push(newPromise);

0 commit comments

Comments
 (0)