Skip to content

Commit c16f6a4

Browse files
committed
Resizable bottom container
1 parent 201fa45 commit c16f6a4

File tree

14 files changed

+184
-93
lines changed

14 files changed

+184
-93
lines changed
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
import React, { useContext } from 'react';
22
import { stateContext } from '../../context/context';
33
import BottomTabs from './BottomTabs';
4-
// import BottomTabs from './BottomTabs';
54

65
// const IPC = require('electron').ipcRenderer;
76

87
const BottomPanel = () => {
98
return (
10-
<div className="bottom-panel" style={{ width: '100%' }}>
9+
<div className="bottom-panel" style={{ width: '100%', height: '100%' }}>
1110
<BottomTabs />
1211
</div>
1312
);
1413
};
1514

16-
export default BottomPanel;
15+
export default BottomPanel;

app/src/components/bottom/CodePreview.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const CodePreview = () => {
2626
justifyContent: 'center'
2727
}}
2828
>
29+
2930
<AceEditor
3031
mode="javascript"
3132
theme="monokai"

app/src/components/left/ComponentPanel.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const ComponentPanel = (): JSX.Element => {
6666

6767
// Add a new component
6868
const createOption = (inputName: String) => {
69-
// format name so first letter is capitalized and there are no whitespaces
69+
// format name so first letter is capitalized and there are no white spaces
7070
let inputNameClean = inputName.replace(/\s+/g, '');
7171
const formattedName =
7272
inputNameClean.charAt(0).toUpperCase() + inputNameClean.slice(1);
@@ -86,11 +86,6 @@ const ComponentPanel = (): JSX.Element => {
8686
if (!compName.charAt(0).match(letters)) {
8787
triggerError('letters');
8888
return;
89-
// }
90-
// let firstChar = compName.charAt(0);
91-
// if (firstChar <= '9' && firstChar >= '0') {
92-
// triggerError('number');
93-
// return;
9489
} else if (compName.trim() === '') {
9590
triggerError('empty');
9691
return;

app/src/components/left/HTMLItem.tsx

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import React from 'react';
2+
import { useDrag } from 'react-dnd';
3+
import { ItemTypes } from '../../constants/ItemTypes';
4+
import Grid from '@material-ui/core/Grid';
5+
import { makeStyles } from '@material-ui/core/styles';
6+
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+
});
27+
28+
const HTMLItem: React.FC<{
29+
name: string;
30+
id: number;
31+
Icon: any;
32+
}> = ({ name, id, Icon }) => {
33+
const classes = useStyles();
34+
35+
const [{ isDragging }, drag] = useDrag({
36+
item: {
37+
type: ItemTypes.INSTANCE,
38+
newInstance: true,
39+
instanceType: 'HTML Element',
40+
name,
41+
instanceTypeId: id
42+
},
43+
collect: (monitor: any) => ({
44+
isDragging: !!monitor.isDragging()
45+
})
46+
});
47+
48+
return (
49+
<Grid item xs={5} key={`html-${name}`}>
50+
<div ref={drag} className={classes.HTMLPanelItem}>
51+
<h3>{name}</h3>
52+
<span
53+
style={{
54+
verticalAlign: 'middle',
55+
display: 'inline-block',
56+
marginLeft: '5px'
57+
}}
58+
>
59+
{Icon && <Icon />}
60+
</span>
61+
</div>
62+
</Grid>
63+
);
64+
}
65+
66+
export default HTMLItem;

app/src/components/left/HTMLPanel.tsx

Lines changed: 56 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,75 @@
1-
import React from 'react';
1+
import React, { useState, useContext } from 'react';
22
import Grid from '@material-ui/core/Grid';
3-
import { useDrag } from 'react-dnd';
4-
import { ItemTypes } from '../../constants/ItemTypes';
5-
import HTMLTypes from '../../context/HTMLTypes';
6-
import { makeStyles } from '@material-ui/core/styles';
3+
import { stateContext } from '../../context/context';
4+
import HTMLItem from './HTMLItem';
75

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-
}
6+
const HTMLPanel = (): JSX.Element => {
7+
const [tag, setTag] = useState('');
8+
const [name, setName] = useState('');
9+
const [currentID, setCurrentID] = useState(12);
10+
const [state, dispatch] = useContext(stateContext);
11+
12+
const handleTagChange = (e: React.ChangeEvent<HTMLInputElement>) => {
13+
setTag(e.target.value);
2514
}
26-
});
2715

28-
const HTMLPanel = (): JSX.Element => {
29-
const classes = useStyles();
30-
const options = HTMLTypes.map(option => {
31-
const [{ isDragging }, drag] = useDrag({
32-
item: {
33-
type: ItemTypes.INSTANCE,
34-
newInstance: true,
35-
instanceType: 'HTML Element',
36-
name: option.name,
37-
instanceTypeId: option.id
38-
},
39-
collect: (monitor: any) => ({
40-
isDragging: !!monitor.isDragging()
41-
})
16+
const handleNameChange = (e: React.ChangeEvent<HTMLInputElement>) => {
17+
setName(e.target.value);
18+
}
19+
20+
const handleSubmit = (e) => {
21+
e.preventDefault();
22+
const newElement = {
23+
id: currentID,
24+
tag,
25+
name,
26+
style: {},
27+
placeHolderShort: name,
28+
placeHolderLong: '',
29+
icon: null
30+
};
31+
dispatch({
32+
type: 'ADD ELEMENT',
33+
payload: newElement
4234
});
43-
return (
44-
<Grid item xs={5} key={`html-${option.name}`}>
45-
<div ref={drag} className={classes.HTMLPanelItem}>
46-
<h3>{option.name}</h3>
47-
<span
48-
style={{
49-
verticalAlign: 'middle',
50-
display: 'inline-block',
51-
marginLeft: '5px'
52-
}}
53-
>
54-
{<option.icon />}
55-
</span>
56-
</div>
57-
</Grid>
58-
);
59-
});
35+
setCurrentID(currentID + 1);
36+
setTag('');
37+
setName('');
38+
console.log("SUBMIT BUTTON CLICKED: ", newElement);
39+
}
6040

6141
return (
6242
<div>
6343
<h4> HTML Elements</h4>
44+
<div>
45+
<form onSubmit={handleSubmit}>
46+
<h4>Create New Element: </h4>
47+
<label>
48+
Tag:
49+
<input type="text" name="Tag" value={tag} onChange={handleTagChange} />
50+
</label>
51+
<label>
52+
Tag Name:
53+
<input type="text" name="Tag Name" value={name} onChange={handleNameChange} />
54+
</label>
55+
<input type="submit" value="Add Element" />
56+
</form>
57+
</div>
6458
<Grid
6559
container
6660
spacing={1}
6761
direction="row"
6862
justify="center"
6963
alignItems="center"
7064
>
71-
{options}
65+
{state.HTMLTypes.map(option => (
66+
<HTMLItem
67+
name={option.name}
68+
key={`html-${option.name}`}
69+
id={option.id}
70+
Icon={option.icon}
71+
/>
72+
))}
7273
</Grid>
7374
</div>
7475
);

app/src/components/main/DirectChildHTML.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { ItemTypes } from '../../constants/ItemTypes';
1010
import { stateContext } from '../../context/context';
1111
import { combineStyles } from '../../helperFunctions/combineStyles';
1212
import IndirectChild from './IndirectChild';
13-
import HTMLTypes from '../../context/HTMLTypes';
1413
import globalDefaultStyle from '../../public/styles/globalDefaultStyles';
1514

1615
function DirectChildHTML({
@@ -24,7 +23,7 @@ function DirectChildHTML({
2423

2524
// find the HTML element corresponding with this instance of an HTML element
2625
// find the current component to render on the canvas
27-
const HTMLType: HTMLType = HTMLTypes.find(
26+
const HTMLType: HTMLType = state.HTMLTypes.find(
2827
(type: HTMLType) => type.id === typeId
2928
);
3029

app/src/components/right/ProjectManager.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ const ProjectManager = () => {
7171
<ListItemText
7272
primary={'Yes, delete all project data'}
7373
style={{ textAlign: 'center' }}
74+
onClick={closeModal}
7475
/>
7576
</ListItem>
7677
</List>

app/src/containers/MainContainer.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import React, { Component } from 'react';
22
import BottomPanel from '../components/bottom/BottomPanel';
33
import CanvasContainer from '../components/main/CanvasContainer';
44

5+
//test for resizable component
6+
import { Resizable } from "re-resizable";
7+
58
// Main container contains the canvas which renders the components/elements on screen
69
// and the bottom panel which displays the code for the component
710
class MainContainer extends Component {
@@ -13,9 +16,10 @@ class MainContainer extends Component {
1316
>
1417
<CanvasContainer />
1518
</div>
16-
17-
<BottomPanel />
18-
</div>
19+
<Resizable minHeight={'25%'} enable={{ top: true }}>
20+
<BottomPanel />
21+
</Resizable>
22+
</div>
1923
);
2024
}
2125
}

app/src/containers/RightContainer.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import TextField from '@material-ui/core/TextField';
88
import Button from '@material-ui/core/Button';
99

1010
import { stateContext } from '../context/context';
11-
import HTMLTypes from '../context/HTMLTypes';
1211

1312
import ProjectManager from '../components/right/ProjectManager';
1413

@@ -116,7 +115,7 @@ const RightContainer = (props): JSX.Element => {
116115
// if type is HTML Element, search through HTML types to find matching element's name
117116
} else if (focusChild.type === 'HTML Element') {
118117
focusTarget.child.type = 'HTML element';
119-
focusTarget.child.name = HTMLTypes.find(
118+
focusTarget.child.name = state.HTMLTypes.find(
120119
elem => elem.id === focusChild.typeId
121120
).name;
122121
}
@@ -166,7 +165,7 @@ const RightContainer = (props): JSX.Element => {
166165
const handlePageDelete = (id) => () => {
167166
dispatch({ type: 'DELETE PAGE', payload: { id }});
168167
}
169-
168+
170169
const handleDeleteReusableComponent = () => {
171170
dispatch({ type: 'DELETE REUSABLE COMPONENT', payload: {} });
172171
}
@@ -398,7 +397,7 @@ const RightContainer = (props): JSX.Element => {
398397
DELETE PAGE
399398
</Button>
400399
</div>
401-
) :
400+
) :
402401
''
403402
)}
404403
</div>

app/src/context/initialState.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { State } from '../interfaces/Interfaces';
2+
import HTMLTypes from './HTMLTypes';
23

34
// This is the state that will be set for a new project or when the user resets the state of their project
45
export const initialState: State = {
@@ -17,7 +18,8 @@ export const initialState: State = {
1718
rootComponents: [1],
1819
canvasFocus: { componentId: 1, childId: null },
1920
nextComponentId: 2,
20-
nextChildId: 1
21+
nextChildId: 1,
22+
HTMLTypes
2123
};
2224

2325
export default initialState;

0 commit comments

Comments
 (0)