Skip to content

Commit 5fc4eac

Browse files
authored
Merge pull request #37 from adriansun1/master
paper outlines for state and props, non stateful components are no longer able to add state
2 parents 0934512 + 6c83d87 commit 5fc4eac

File tree

2 files changed

+152
-125
lines changed

2 files changed

+152
-125
lines changed

src/components/Props.jsx

Lines changed: 150 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,16 @@ import {
1212
Switch,
1313
InputLabel,
1414
Typography,
15+
Paper,
1516
} from '@material-ui/core';
1617
import RemoveCircleOutlineIcon from '@material-ui/icons/RemoveCircleOutline';
1718
import { connect } from 'react-redux';
1819
import { compose } from 'redux';
1920
import {
20-
deleteProp, addProp, addPropToDisplayed, removePropFromDisplayed,
21+
deleteProp,
22+
addProp,
23+
addPropToDisplayed,
24+
removePropFromDisplayed,
2125
} from '../actions/components';
2226

2327
const mapDispatchToProps = dispatch => ({
@@ -45,7 +49,7 @@ const styles = theme => ({
4549
chip: {
4650
margin: theme.spacing.unit,
4751
color: '#eee',
48-
backgroundColor: '#333333',
52+
backgroundColor: '#262627',
4953
},
5054
column: {
5155
display: 'inline-flex',
@@ -81,6 +85,16 @@ const styles = theme => ({
8185
color: '#eee',
8286
fontSize: '10px',
8387
},
88+
panel: {
89+
backgroundColor: '#333333',
90+
minHeight: '100px',
91+
marginTop: '20px',
92+
},
93+
panelTitle: {
94+
margin: '10px',
95+
padding: '5px',
96+
color: '#eee',
97+
},
8498
});
8599

86100
const availablePropTypes = {
@@ -184,10 +198,7 @@ class Props extends Component {
184198

185199
render() {
186200
const {
187-
focusComponent,
188-
classes,
189-
rightColumnOpen,
190-
compProps,
201+
focusComponent, classes, rightColumnOpen, compProps,
191202
} = this.props;
192203

193204
return (
@@ -199,89 +210,99 @@ class Props extends Component {
199210
</div>
200211
) : (
201212
<div className="props-container">
202-
<form className="props-input" onSubmit={this.handleAddProp}>
203-
<Grid container spacing={24}>
204-
<Grid item xs={6}>
205-
<TextField
206-
id="propKey"
207-
label="Key"
208-
margin="normal"
209-
autoFocus
210-
onChange={this.handleChange}
211-
value={this.state.propKey}
212-
required
213-
InputProps={{
214-
className: classes.input,
215-
}}
216-
InputLabelProps={{
217-
className: classes.input,
218-
}}
219-
/>
220-
</Grid>
221-
<Grid item xs={6}>
222-
<TextField
223-
id="propValue"
224-
label="Value"
225-
margin="normal"
226-
onChange={this.handleChange}
227-
InputProps={{
228-
className: classes.input,
229-
}}
230-
InputLabelProps={{
231-
className: classes.input,
232-
}}
233-
value={this.state.propValue}
234-
/>
235-
</Grid>
236-
<Grid item xs={6}>
237-
<FormControl required>
238-
<InputLabel className={classes.light} htmlFor="propType">
239-
Type
240-
</InputLabel>
241-
<Select
242-
native
243-
className={classes.light}
244-
id="propType"
245-
placeholder="title"
246-
onChange={this.handleChange}
247-
value={this.state.propType}
248-
required
249-
>
250-
{typeOptions}
251-
</Select>
252-
</FormControl>
253-
</Grid>
254-
<Grid item xs={6}>
255-
<div className={classes.column}>
256-
<InputLabel
257-
className={classes.light}
258-
htmlFor="propRequired"
259-
>
260-
Required?
261-
</InputLabel>
262-
<Switch
263-
checked={this.state.propRequired}
264-
onChange={this.togglePropRequired}
265-
value="propRequired"
266-
color="secondary"
267-
id="propRequired"
268-
/>
269-
</div>
270-
</Grid>
271-
<Grid item>
272-
<Button
273-
color="primary"
274-
aria-label="Add"
275-
type="submit"
276-
disabled={!this.state.propKey || !this.state.propType}
277-
variant="contained"
278-
size="large"
279-
>
280-
ADD PROP
281-
</Button>
282-
</Grid>
283-
</Grid>
284-
</form>
213+
{focusComponent.stateful
214+
? <form className="props-input" onSubmit={this.handleAddProp}>
215+
<Grid
216+
container
217+
spacing={24}
218+
justify="space-evenly"
219+
alignItems="baseline"
220+
>
221+
<Grid item xs={6}>
222+
<TextField
223+
id="propKey"
224+
label="Key"
225+
margin="normal"
226+
autoFocus
227+
onChange={this.handleChange}
228+
value={this.state.propKey}
229+
required
230+
InputProps={{
231+
className: classes.input,
232+
}}
233+
InputLabelProps={{
234+
className: classes.input,
235+
}}
236+
/>
237+
</Grid>
238+
{/* <Grid item xs={6}>
239+
<TextField
240+
id="propValue"
241+
label="Value"
242+
margin="normal"
243+
onChange={this.handleChange}
244+
InputProps={{
245+
className: classes.input,
246+
}}
247+
InputLabelProps={{
248+
className: classes.input,
249+
}}
250+
value={this.state.propValue}
251+
/>
252+
</Grid> */}
253+
<Grid item xs={6}>
254+
<FormControl required>
255+
<InputLabel className={classes.light} htmlFor="propType">
256+
Type
257+
</InputLabel>
258+
<Select
259+
native
260+
className={classes.light}
261+
id="propType"
262+
placeholder="title"
263+
onChange={this.handleChange}
264+
value={this.state.propType}
265+
required
266+
>
267+
{typeOptions}
268+
</Select>
269+
</FormControl>
270+
</Grid>
271+
<Grid item xs={6}>
272+
<div className={classes.column}>
273+
<InputLabel
274+
className={classes.light}
275+
htmlFor="propRequired"
276+
>
277+
Required?
278+
</InputLabel>
279+
<Switch
280+
checked={this.state.propRequired}
281+
onChange={this.togglePropRequired}
282+
value="propRequired"
283+
color="secondary"
284+
id="propRequired"
285+
/>
286+
</div>
287+
</Grid>
288+
<Grid item xs={6}>
289+
<Button
290+
color="primary"
291+
aria-label="Add"
292+
type="submit"
293+
disabled={!this.state.propKey || !this.state.propType}
294+
variant="contained"
295+
size="large"
296+
>
297+
ADD PROP
298+
</Button>
299+
</Grid>
300+
</Grid>
301+
</form>
302+
: ''
303+
}
304+
<Paper className={classes.panel}>
305+
<Typography className={classes.panelTitle}>State and Props</Typography>
285306
<div className="chips">
286307
{compProps
287308
.filter(
@@ -318,41 +339,46 @@ class Props extends Component {
318339
);
319340
})}
320341
</div>
321-
<Typography className={classes.label}>Parent Props</Typography>
322-
{compProps
323-
// display if the parents contain it and the prop doesnt contain the current id
324-
.filter(el => (focusComponent.parentId === el.origin
325-
|| el.displayedAt.indexOf(focusComponent.parentId) >= 0)
326-
&& el.displayedAt.indexOf(focusComponent.id) < 0)
327-
.map((el) => {
328-
const {
329-
id, key, value, required, type,
330-
} = el;
331-
return (
332-
<Chip
333-
key={id}
334-
avatar={
335-
<Avatar className={classes.avatar}>
336-
{availablePropTypes[type]}
337-
</Avatar>
338-
}
339-
label={`${key}: ${value}`}
340-
onClick={() => {
341-
this.parentPropHandler({ id }, focusComponent.id);
342-
}}
343-
className={classes.chip}
344-
elevation={6}
345-
disabled={
346-
el.origin !== focusComponent.id
347-
|| el.availableAt.indexOf(focusComponent.id) < 0
348-
}
349-
color={required ? 'secondary' : 'primary'}
350-
deleteIcon={
351-
<RemoveCircleOutlineIcon className={classes.icon} />
352-
}
353-
/>
354-
);
355-
})}
342+
</Paper>
343+
<Paper className={classes.panel}>
344+
<Typography className={classes.panelTitle}>Parent</Typography>
345+
{compProps
346+
// display if the parents contain it and the prop doesnt contain the current id
347+
.filter(
348+
el => (focusComponent.parentId === el.origin
349+
|| el.displayedAt.indexOf(focusComponent.parentId) >= 0)
350+
&& el.displayedAt.indexOf(focusComponent.id) < 0,
351+
)
352+
.map((el) => {
353+
const {
354+
id, key, value, required, type,
355+
} = el;
356+
return (
357+
<Chip
358+
key={id}
359+
avatar={
360+
<Avatar className={classes.avatar}>
361+
{availablePropTypes[type]}
362+
</Avatar>
363+
}
364+
label={`${key}: ${value}`}
365+
onClick={() => {
366+
this.parentPropHandler({ id }, focusComponent.id);
367+
}}
368+
className={classes.chip}
369+
elevation={6}
370+
disabled={
371+
el.origin !== focusComponent.id
372+
|| el.availableAt.indexOf(focusComponent.id) < 0
373+
}
374+
color={required ? 'secondary' : 'primary'}
375+
deleteIcon={
376+
<RemoveCircleOutlineIcon className={classes.icon} />
377+
}
378+
/>
379+
);
380+
})}
381+
</Paper>
356382
</div>
357383
)}
358384
</div>

src/containers/LeftComponentContainer.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ const LeftComponentContainer = (props) => {
130130
/>) : null;
131131

132132
return (
133-
<div className={classes.root}>
133+
// <div className={classes.root}>
134+
<div>
134135
<ExpansionPanel
135136
className={classes.panel}
136137
expanded={focusComponent.id === id}

0 commit comments

Comments
 (0)