Skip to content

Commit 749816c

Browse files
Merge pull request #55 from spincycle01/master
exporting working with multiple props in one component
2 parents 8b4f168 + ddaa117 commit 749816c

File tree

3 files changed

+95
-97
lines changed

3 files changed

+95
-97
lines changed

src/components/Props.jsx

Lines changed: 91 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,130 +1,133 @@
1-
import React, { Component, Fragment } from "react";
2-
import { connect } from "react-redux";
1+
import React, { Component, Fragment } from 'react';
2+
import { connect } from 'react-redux';
33

44
// import PropTypes from 'prop-types';
5-
import { withStyles } from "@material-ui/core/styles";
6-
import Chip from "@material-ui/core/Chip";
7-
import Avatar from "@material-ui/core/Avatar";
8-
import FormControl from "@material-ui/core/FormControl";
9-
import Grid from "@material-ui/core/Grid";
10-
import TextField from "@material-ui/core/TextField";
11-
import Button from "@material-ui/core/Button";
12-
import Select from "@material-ui/core/Select";
13-
import Switch from "@material-ui/core/Switch";
14-
import InputLabel from "@material-ui/core/InputLabel";
15-
import RemoveCircleOutlineIcon from "@material-ui/icons/RemoveCircleOutline";
16-
import { addProp, deleteProp } from "../actions/components";
17-
import DataTable from "./DataTable.jsx";
5+
import { withStyles } from '@material-ui/core/styles';
6+
import Chip from '@material-ui/core/Chip';
7+
import Avatar from '@material-ui/core/Avatar';
8+
import FormControl from '@material-ui/core/FormControl';
9+
import Grid from '@material-ui/core/Grid';
10+
import TextField from '@material-ui/core/TextField';
11+
import Button from '@material-ui/core/Button';
12+
import Select from '@material-ui/core/Select';
13+
import Switch from '@material-ui/core/Switch';
14+
import InputLabel from '@material-ui/core/InputLabel';
15+
import RemoveCircleOutlineIcon from '@material-ui/icons/RemoveCircleOutline';
16+
import { addProp, deleteProp } from '../actions/components';
17+
import DataTable from './DataTable.jsx';
1818

1919
const styles = theme => ({
2020
root: {
21-
display: "flex",
22-
justifyContent: "center",
23-
flexWrap: "wrap"
21+
display: 'flex',
22+
justifyContent: 'center',
23+
flexWrap: 'wrap',
2424
},
2525
chip: {
2626
margin: theme.spacing.unit,
27-
color: "#eee",
28-
backgroundColor: "#333333"
27+
color: '#eee',
28+
backgroundColor: '#333333',
2929
},
3030
column: {
31-
display: "inline-flex",
32-
alignItems: "baseline"
31+
display: 'inline-flex',
32+
alignItems: 'baseline',
3333
},
3434
icon: {
35-
fontSize: "20px",
36-
color: "#eee",
37-
opacity: "0.7",
38-
transition: "all .2s ease",
35+
fontSize: '20px',
36+
color: '#eee',
37+
opacity: '0.7',
38+
transition: 'all .2s ease',
3939

40-
"&:hover": {
41-
color: "red"
42-
}
40+
'&:hover': {
41+
color: 'red',
42+
},
4343
},
4444
cssLabel: {
45-
color: "white",
45+
color: 'white',
4646

47-
"&$cssFocused": {
48-
color: "green"
49-
}
47+
'&$cssFocused': {
48+
color: 'green',
49+
},
5050
},
5151
cssFocused: {},
5252
input: {
53-
color: "#eee",
54-
marginBottom: "10px",
55-
width: "60%"
53+
color: '#eee',
54+
marginBottom: '10px',
55+
width: '60%',
5656
},
5757
light: {
58-
color: "#eee"
58+
color: '#eee',
5959
},
6060
avatar: {
61-
color: "#eee",
62-
fontSize: "10px"
63-
}
61+
color: '#eee',
62+
fontSize: '10px',
63+
},
6464
});
6565

6666
const mapDispatchToProps = dispatch => ({
67-
addProp: ({ key, value, required, type }) =>
68-
dispatch(
69-
addProp({
70-
key,
71-
value,
72-
required,
73-
type
74-
})
75-
),
76-
deleteProp: propId => dispatch(deleteProp(propId))
67+
addProp: ({
68+
key, value, required, type,
69+
}) => dispatch(
70+
addProp({
71+
key,
72+
value,
73+
required,
74+
type,
75+
}),
76+
),
77+
deleteProp: propId => dispatch(deleteProp(propId)),
7778
});
7879

7980
const mapStateToProps = store => ({
80-
focusComponent: store.workspace.focusComponent
81+
focusComponent: store.workspace.focusComponent,
8182
});
8283

8384
const availablePropTypes = {
84-
string: "STR",
85-
object: "OBJ",
86-
array: "ARR",
87-
number: "NUM",
88-
bool: "BOOL",
89-
func: "FUNC",
90-
symbol: "SYM",
91-
node: "NODE",
92-
element: "ELEM"
85+
string: 'STR',
86+
object: 'OBJ',
87+
array: 'ARR',
88+
number: 'NUM',
89+
boolean: 'BOOL',
90+
function: 'FUNC',
91+
symbol: 'SYM',
92+
node: 'NODE',
93+
element: 'ELEM',
9394
};
9495

9596
const typeOptions = [
9697
<option value="" key="" />,
9798
...Object.keys(availablePropTypes).map(type => (
98-
<option value={type} key={type} style={{ color: "#000" }}>
99+
<option value={type} key={type} style={{ color: '#000' }}>
99100
{type}
100101
</option>
101-
))
102+
)),
102103
];
103104

104105
class Props extends Component {
105106
state = {
106-
propKey: "",
107-
propValue: "",
107+
propKey: '',
108+
propValue: '',
108109
propRequired: false,
109-
propType: ""
110+
propType: '',
110111
};
111112

112-
handleChange = event => {
113+
handleChange = (event) => {
113114
this.setState({
114-
[event.target.id]: event.target.value.trim()
115+
[event.target.id]: event.target.value.trim(),
115116
});
116117
};
117118

118119
togglePropRequired = () => {
119120
this.setState({
120-
propRequired: !this.state.propRequired
121+
propRequired: !this.state.propRequired,
121122
});
122123
};
123124

124-
handleAddProp = event => {
125+
handleAddProp = (event) => {
125126
event.preventDefault();
126127

127-
const { propKey, propValue, propRequired, propType } = this.state;
128+
const {
129+
propKey, propValue, propRequired, propType,
130+
} = this.state;
128131

129132
// check if prop exists with same key. CANNOT have doubles
130133
const savedPropKeys = this.props.focusComponent.props.map(p => p.key);
@@ -137,36 +140,38 @@ class Props extends Component {
137140
key: propKey,
138141
value: propValue,
139142
required: propRequired,
140-
type: propType
143+
type: propType,
141144
});
142145

143146
this.setState({
144-
propKey: "",
145-
propValue: "",
147+
propKey: '',
148+
propValue: '',
146149
propRequired: false,
147-
propType: ""
150+
propType: '',
148151
});
149152
};
150153

151154
render() {
152-
const { focusComponent, classes, deleteProp, addProp } = this.props;
155+
const {
156+
focusComponent, classes, deleteProp, addProp,
157+
} = this.props;
153158

154-
const rowHeader = ["_Key", "Value", "Type", "Required"];
159+
const rowHeader = ['_Key', 'Value', 'Type', 'Required'];
155160
// prepare the saved Props in a nice way, so you can sent them to TableData
156161
const propsRows = focusComponent.props.map(prop => ({
157162
_Key: prop.key,
158163
Value: prop.value,
159164
Type: prop.type,
160165
Required: prop.required,
161-
id: prop.id
166+
id: prop.id,
162167
}));
163168

164169
return (
165170
// <div style={{ display: rightColumnOpen ? "inline" : "none" }}>
166171
<div>
167-
{" "}
172+
{' '}
168173
{Object.keys(focusComponent).length < 1 ? (
169-
<div style={{ marginTop: "20px", marginLeft: "20px" }}>
174+
<div style={{ marginTop: '20px', marginLeft: '20px' }}>
170175
Click a component to view its props.
171176
</div>
172177
) : (
@@ -186,10 +191,10 @@ class Props extends Component {
186191
value={this.state.propKey}
187192
required
188193
InputProps={{
189-
className: classes.input
194+
className: classes.input,
190195
}}
191196
InputLabelProps={{
192-
className: classes.input
197+
className: classes.input,
193198
}}
194199
/>
195200
</Grid>
@@ -200,20 +205,17 @@ class Props extends Component {
200205
margin="normal"
201206
onChange={this.handleChange}
202207
InputProps={{
203-
className: classes.input
208+
className: classes.input,
204209
}}
205210
InputLabelProps={{
206-
className: classes.input
211+
className: classes.input,
207212
}}
208213
value={this.state.propValue}
209214
/>
210215
</Grid>
211216
<Grid item xs={6}>
212217
<FormControl required>
213-
<InputLabel
214-
className={classes.light}
215-
htmlFor="propType"
216-
>
218+
<InputLabel className={classes.light} htmlFor="propType">
217219
Type
218220
</InputLabel>
219221
<Select
@@ -231,10 +233,7 @@ class Props extends Component {
231233
</Grid>
232234
<Grid item xs={6}>
233235
<div className={classes.column}>
234-
<InputLabel
235-
className={classes.light}
236-
htmlFor="propRequired"
237-
>
236+
<InputLabel className={classes.light} htmlFor="propRequired">
238237
Required?
239238
</InputLabel>
240239
<Switch
@@ -305,5 +304,5 @@ class Props extends Component {
305304

306305
export default connect(
307306
mapStateToProps,
308-
mapDispatchToProps
307+
mapDispatchToProps,
309308
)(withStyles(styles)(Props));

src/utils/componentRender.util.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ const componentRender = (component, data) => {
33
stateful, id, position, childrenArray, title, props,
44
} = component;
55

6-
// need to filter with reduce the import, copy from below
76
if (stateful) {
87
return `
98
import React, { Component } from 'react';
109
${childrenArray
10+
.filter(child => child.childType !== 'HTML')
1111
.map(child => `import ${child.componentName} from './${child.componentName}.tsx'`)
1212
.reduce((acc, child) => {
1313
if (!acc.includes(child)) {
@@ -36,10 +36,10 @@ const componentRender = (component, data) => {
3636
export default ${title};
3737
`;
3838
}
39-
4039
return `
4140
import React from 'react';
4241
${childrenArray
42+
.filter(child => child.childType !== 'HTML')
4343
.map(child => `import ${child.componentName} from './${child.componentName}.tsx'`)
4444
.reduce((acc, child) => {
4545
if (!acc.includes(child)) {
@@ -50,9 +50,8 @@ const componentRender = (component, data) => {
5050
}, [])
5151
.join('\n')}
5252
53-
5453
type Props = {
55-
${component.props.map(prop => `${prop.key}: ${prop.type}`).join('\n')}
54+
${props.map(prop => `${prop.key}: ${prop.type}`).join('\n')}
5655
}
5756
5857
const ${title} = (props: Props) => (

src/utils/createFiles.util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const createFiles = (data, path) => {
2323
trailingComma: 'es5',
2424
bracketSpacing: true,
2525
jsxBracketSameLine: true,
26-
parser: 'babylon',
26+
parser: 'typescript',
2727
}),
2828
(err) => {
2929
if (err) return reject(err.message);

0 commit comments

Comments
 (0)