Skip to content

Commit 62640bc

Browse files
committed
refinements on left panel, added right panel config options
1 parent 91a2d4f commit 62640bc

File tree

8 files changed

+151
-60
lines changed

8 files changed

+151
-60
lines changed

src/components/left/ComponentPanelItemNew.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ const ComponentPanelItem: React.FC<{
2424
name: string;
2525
id: number;
2626
root: boolean;
27-
focusClick: any;
2827
isFocus: boolean
29-
}> = ({ name, id, root, focusClick, isFocus }) => {
28+
}> = ({ name, id, root, isFocus }) => {
3029
const classes = useStyles();
3130
const [state, dispatch] = useContext(stateContext);
3231
// useDrag hook allows components in left panel to be drag source

src/components/left/ComponentPanelNew.tsx

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ import { makeStyles } from '@material-ui/core/styles';
1414

1515
const useStyles = makeStyles({
1616
inputField: {
17-
marginRight: '15px',
18-
// width: '245px'
17+
1918
},
2019
inputWrapper: {
2120
height: '110px',
@@ -28,7 +27,8 @@ const useStyles = makeStyles({
2827
width: '100%'
2928
},
3029
panelWrapperList: {
31-
height: '675px',
30+
maxHeight: '675px',
31+
minHeight: '120px',
3232
overflowY: 'auto',
3333
marginLeft: '-15px'
3434
},
@@ -53,7 +53,7 @@ const useStyles = makeStyles({
5353
display: 'flex',
5454
flexDirection: 'column',
5555
paddingTop: '10px',
56-
marginRight: '10px'
56+
marginLeft: '10px'
5757
},
5858
button: {
5959
fontSize: '1rem'
@@ -62,14 +62,7 @@ const useStyles = makeStyles({
6262
color: '#01d46d',
6363
fontSize: '0.85rem'
6464
},
65-
compPanelItem: {
66-
color: 'red',
67-
'&:hover': {
68-
cursor: 'pointer',
69-
backgroundColor: 'red'
70-
}
71-
},
72-
65+
7366
});
7467

7568

src/components/left/HTMLPanelNew.tsx

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,32 @@
11
import React from 'react';
2-
import { withStyles, Theme } from '@material-ui/core/styles';
3-
import ImageIcon from '@material-ui/icons/Image';
4-
import ParagraphIcon from '@material-ui/icons/LocalParking';
5-
import FormIcon from '@material-ui/icons/Description';
6-
import HeaderIcon from '@material-ui/icons/TextFormat';
7-
import ButtonIcon from '@material-ui/icons/EditAttributes';
8-
import LinkIcon from '@material-ui/icons/Link';
9-
import ListIcon from '@material-ui/icons/List';
102
import Grid from '@material-ui/core/Grid';
11-
import Typography from '@material-ui/core/Typography';
123
import { useDrag } from 'react-dnd';
134
import { ItemTypes } from '../../constants/ItemTypes';
145
import HTMLTypes from '../../context/HTMLTypes';
6+
import { makeStyles } from '@material-ui/core/styles';
7+
8+
const useStyles = makeStyles({
9+
HTMLPanelItem: {
10+
color: 'white',
11+
// this is experimental for version: BLADERUNNER THEME
12+
backgroundColor: 'transparent',
13+
// minWidth: '340px',
14+
minHeight: '60px',
15+
marginBottom: '10px',
16+
marginRight: '5px',
17+
marginLeft: '5px',
18+
border: '2px dotted rgba(255,255,255, 0.45)',
19+
borderRadius: '8px',
20+
cursor: 'grab',
21+
'& > h3': {
22+
display: 'inline-block',
23+
paddingTop: '18px'
24+
}
25+
}
26+
})
1527

1628
const HTMLPanel = (): JSX.Element => {
29+
const classes = useStyles();
1730
const options = HTMLTypes.map(option => {
1831
const [{ isDragging }, drag] = useDrag({
1932
item: {
@@ -30,39 +43,32 @@ const HTMLPanel = (): JSX.Element => {
3043
return (
3144
<Grid
3245
item
33-
ref={drag}
3446
xs={5}
3547
key={`html-${option.name}`}
36-
style={{
37-
color: 'white',
38-
// this is experimental for version: BLADERUNNER THEME
39-
backgroundColor: 'transparent',
40-
// minWidth: '340px',
41-
minHeight: '60px',
42-
marginBottom: '15px',
43-
border: '2px dotted rgba(255,255,255, 0.45)',
44-
borderRadius: '8px'
45-
}}
4648
>
47-
<h3>
48-
{option.name}
49+
<div ref={drag} className={classes.HTMLPanelItem}>
50+
<h3>
51+
{option.name}
52+
53+
</h3>
4954
<span
50-
style={{
51-
verticalAlign: '-webkit-baseline-middle',
52-
marginLeft: '5px'
53-
}}
54-
>
55-
{<option.icon />}
56-
</span>
57-
</h3>
55+
style={{
56+
verticalAlign: 'middle',
57+
display: 'inline-block',
58+
marginLeft: '5px'
59+
}}
60+
>
61+
{<option.icon />}
62+
</span>
63+
</div>
5864
</Grid>
5965
);
6066
});
6167

6268
return (
6369
<div>
6470
<h4> HTML Elements</h4>
65-
<Grid container direction="row" justify="center" alignItems="center">
71+
<Grid container spacing={1} direction="row" justify="center" alignItems="center">
6672
{options}
6773
</Grid>
6874
</div>

src/components/main/CanvasContainerNew.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import Canvas from './CanvasNew';
44
// The CanvasContainer sets the boundaries on the width/height of the canvas
55
function CanvasContainer() {
66
const canvasContainerStyle = {
7-
width: '1000px',
87
height: '100%',
8+
width: '100%',
99
backgroundColor: 'lightgrey',
1010
border: '2px Solid grey',
1111
overflowY: 'auto'

src/components/main/CanvasNew.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ function Canvas() {
9494

9595
const defaultCanvasStyle = {
9696
width: '100%',
97-
height: '100%',
97+
minHeight: '100%',
9898
backgroundColor: isOver ? 'lightyellow' : 'white',
99-
border: '2px Solid black',
99+
border: '3px solid #01d46d',
100100
borderStyle: isOver ? 'dotted' : 'solid'
101101
};
102102

src/containers/LeftContainerNew.tsx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,40 @@ import Button from '@material-ui/core/Button';
66
import AddIcon from '@material-ui/icons/Add';
77
import Fab from '@material-ui/core/Fab';
88
import FormControlLabel from '@material-ui/core/FormControlLabel';
9-
9+
import { makeStyles } from '@material-ui/core/styles';
1010
import ComponentPanel from '../components/left/ComponentPanelNew';
1111
import HTMLPanel from '../components/left/HTMLPanelNew';
12+
import GetAppIcon from '@material-ui/icons/GetApp';
13+
14+
const useStyles = makeStyles({
15+
btnGroup: {
16+
display: 'flex',
17+
justifyContent: 'center',
18+
width: '100%',
19+
position: 'absolute',
20+
bottom: '65px',
21+
left: '0px'
22+
},
23+
exportBtn: {
24+
width: '55%',
25+
backgroundColor: 'rgba(1,212,109,0.1)',
26+
fontSize: '1em'
27+
}
28+
})
1229

1330
// Left-hand portion of the app, where component options are displayed
1431
const LeftContainer = (): JSX.Element => {
32+
const classes = useStyles();
1533
return (
1634
<div className="column left" style={{ minWidth: '375px' }}>
1735
<Grid container direction="row" alignItems="center">
1836
<ComponentPanel />
1937
<HTMLPanel />
38+
<div className={classes.btnGroup}>
39+
<Button className={classes.exportBtn} variant="outlined" color="primary" endIcon={<GetAppIcon />}>
40+
EXPORT PROJECT
41+
</Button>
42+
</div>
2043
</Grid>
2144
</div>
2245
);

src/containers/RightContainerNew.tsx

Lines changed: 80 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import React, { useState, useContext } from 'react';
1+
import React, { useState, useContext, useEffect } from 'react';
22
import FormControl from '@material-ui/core/FormControl';
33
import Select from '@material-ui/core/Select';
44
import MenuItem from '@material-ui/core/MenuItem';
55
import TextField from '@material-ui/core/TextField';
66
import { makeStyles } from '@material-ui/core/styles';
77
import { stateContext } from '../context/context';
8+
import HTMLTypes from '../context/HTMLTypes';
89
import Button from '@material-ui/core/Button';
910

1011
const useStyles = makeStyles({
@@ -52,9 +53,19 @@ const useStyles = makeStyles({
5253
compName: {
5354
color: '#01d46d',
5455
fontSize: '1.25rem'
56+
},
57+
configHeader: {
58+
height: '70px',
59+
'& > h4': {
60+
fontSize: '1.15rem',
61+
letterSpacing: '0.5px',
62+
marginBottom: '0',
63+
marginTop: '10px'
64+
}
5565
}
5666
});
5767

68+
5869
const RightContainer = ():JSX.Element => {
5970
const classes = useStyles();
6071
const [state, dispatch] = useContext(stateContext);
@@ -68,7 +79,25 @@ const RightContainer = ():JSX.Element => {
6879
const [compWidth, setCompWidth] = useState('');
6980
const [compHeight, setCompHeight] = useState('');
7081

82+
const resetFields = () => {
83+
setDisplayMode('');
84+
setFlexDir('');
85+
setFlexJustify('');
86+
setFlexAlign('');
87+
setCompWidth('');
88+
setCompHeight('');
89+
setBGColor('');
90+
}
91+
92+
//reset input fields if focus changes
93+
useEffect(()=> {
94+
// reset
95+
console.log('canvas focus changed');
96+
resetFields();
97+
}, [state.canvasFocus.componentId, state.canvasFocus.childId]);
7198

99+
100+
// handles all input field changes, with specific updates called based on input's name
72101
const handleChange = (e: React.ChangeEvent<{value: any}>) => {
73102
let inputVal = e.target.value;
74103
switch(e.target.name) {
@@ -96,13 +125,46 @@ const RightContainer = ():JSX.Element => {
96125
}
97126
}
98127

128+
// returns the current component referenced in canvasFocus
129+
// along with its child instance, if it exists
99130
const getFocus = () => {
100-
const focusTarget = state.components.find(comp => {
101-
return comp.id === state.canvasFocus.componentId;
102-
})
131+
// find and store component's name based on canvasFocus.componentId
132+
// note: deep clone here to make sure we don't end up altering state
133+
let focusTarget = JSON.parse(JSON.stringify(state.components.find(comp => comp.id === state.canvasFocus.componentId )));
134+
delete focusTarget.child;
135+
136+
// checks if canvasFocus references a childId
137+
const childInstanceId = state.canvasFocus.childId ? state.canvasFocus.childId : null;
138+
139+
// if so, breadth-first search through focusTarget's descendants to find matching child
140+
if (childInstanceId) {
141+
focusTarget.child = {};
142+
focusTarget.child.id = childInstanceId;
143+
let focusChild = {}; //child instance being referenced in canvasFocus
144+
const searchArray = [...focusTarget.children];
145+
while (searchArray.length > 0) {
146+
const currentChild = searchArray.shift();
147+
if (currentChild.childId === childInstanceId) focusChild = currentChild;
148+
currentChild.children.forEach(child => searchArray.push(child));
149+
}
150+
// if type is Component, use child's typeId to search through state components and find matching component's name
151+
if (focusChild.type === 'Component') {
152+
focusTarget.child.type = 'component';
153+
focusTarget.child.name = state.components.find(comp => comp.id === focusChild.typeId).name;
154+
// if type is HTML Element, search through HTML types to find matching element's name
155+
} else if (focusChild.type === 'HTML Element') {
156+
focusTarget.child.type = 'HTML element';
157+
focusTarget.child.name = HTMLTypes.find(elem => elem.id === focusChild.typeId).name;
158+
}
159+
}
160+
console.log('right panel focus: ');
161+
console.log(focusTarget);
162+
103163
return focusTarget;
104164
}
105165

166+
// dispatch to 'UPDATE CSS' called when save button is clicked,
167+
// passing in style object constructed from all changed input values
106168
const handleSave = ():Object => {
107169
const styleObj = {};
108170
if (displayMode !== '') styleObj.display = displayMode;
@@ -113,16 +175,29 @@ const RightContainer = ():JSX.Element => {
113175
if (compHeight !== '') styleObj.height = compHeight;
114176
if (BGColor !== '') styleObj.backgroundColor = BGColor;
115177
console.log(styleObj);
178+
dispatch({
179+
type: 'UPDATE CSS',
180+
payload: { style: styleObj }
181+
});
182+
resetFields();
116183
return styleObj;
117184
}
118185

186+
// placeholder for handling deleting instance
119187
const handleDelete = () => {
120188
console.log('DELETING ...');
121189
}
122190

191+
const configTarget = getFocus();
192+
123193
return (
124194
<div className="column right">
125-
<h4>Configuration options for <span className={classes.compName}>{getFocus().name}</span></h4>
195+
<div className={classes.configHeader}>
196+
<h4>Configuration options in <span className={classes.compName}>{configTarget.name}</span></h4>
197+
{ configTarget.child &&
198+
<h4>for instance <span className={classes.compName}>{configTarget.child.id}</span> of {configTarget.child.type} <span className={classes.compName}>{configTarget.child.name}</span ></h4>
199+
}
200+
</div>
126201
<div className={classes.configRow}>
127202
<div className={classes.configType}>
128203
<h3>Display:</h3>

src/public/styles/styleNew.css

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@ h3 {
5050
}
5151

5252
.right {
53-
padding-top: 25px;
53+
padding-top: 35px;
5454
}
5555

56-
.right h4 {
57-
font-size: 1.15rem;
58-
margin-bottom: 30px;
59-
letter-spacing: 0.5px;
60-
}

0 commit comments

Comments
 (0)