Skip to content

Commit f308b91

Browse files
authored
Merge pull request #13 from oslabs-beta/jon
Revise clicking & dragging functionality of bottom panel
2 parents eb63a85 + c48a0f5 commit f308b91

File tree

4 files changed

+33
-26
lines changed

4 files changed

+33
-26
lines changed

app/src/components/bottom/BottomPanel.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useRef } from 'react';
1+
import React, { useEffect, useRef, useState } from 'react';
22
import BottomTabs from './BottomTabs';
33
import { ExpandLess, ExpandMore } from '@mui/icons-material';
44

@@ -7,6 +7,8 @@ const BottomPanel = (props): JSX.Element => {
77
let h: number = 0;
88
const node = useRef() as React.MutableRefObject<HTMLDivElement>;
99

10+
const [isDragging, setIsDragging] = useState(false);
11+
1012
const mouseDownHandler = (e): void => {
1113
y = e.clientY;
1214

@@ -28,6 +30,7 @@ const BottomPanel = (props): JSX.Element => {
2830
};
2931

3032
const mouseMoveHandler = function (e: MouseEvent): void {
33+
if (!props.bottomShow) return; // prevent drag calculation to occur when bottom menu is not showing
3134

3235
const dy = y - e.clientY;
3336

@@ -38,6 +41,8 @@ const BottomPanel = (props): JSX.Element => {
3841
};
3942

4043
const mouseUpHandler = function () {
44+
// puts false in callback queue after OnDragStart sets to true (b/c react 17 doesn't have onDragEnd)
45+
setTimeout(() => setIsDragging(false), 0);
4146
document.removeEventListener('mousemove', mouseMoveHandler);
4247
document.removeEventListener('mouseup', mouseUpHandler);
4348
window.removeEventListener('message', handleIframeMessage);
@@ -54,7 +59,9 @@ const BottomPanel = (props): JSX.Element => {
5459
<div
5560
id="resize-drag"
5661
onMouseDown={mouseDownHandler}
57-
onClick={() => props.setBottomShow(true)}
62+
draggable
63+
onDragStart={() => setIsDragging(true)}
64+
onClick={() => !isDragging && props.setBottomShow(!props.bottomShow)}
5865
tabIndex={0}
5966
>
6067
{props.bottomShow ? <ExpandMore /> : <ExpandLess />}

app/src/components/bottom/BottomTabs.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ const BottomTabs = (props): JSX.Element => {
4141

4242
arrow.renderArrow(state.canvasFocus?.childId);
4343

44+
const showBottomPanel = () => {
45+
props.setBottomShow(true);
46+
};
47+
4448
return (
4549
<div
4650
className={`${classes.root} ${classes.rootLight}`}
@@ -49,9 +53,6 @@ const BottomTabs = (props): JSX.Element => {
4953
zIndex: 1,
5054
borderTop: '2px solid grey'
5155
}}
52-
onClick={() => {
53-
props.setBottomShow(true);
54-
}}
5556
>
5657
<Box
5758
display="flex"
@@ -71,31 +72,37 @@ const BottomTabs = (props): JSX.Element => {
7172
disableRipple
7273
classes={{ root: classes.tabRoot, selected: classes.tabSelected }}
7374
label="Creation Panel"
75+
onClick={showBottomPanel}
7476
/>
7577
<Tab
7678
disableRipple
7779
classes={{ root: classes.tabRoot, selected: classes.tabSelected }}
7880
label="Customization"
81+
onClick={showBottomPanel}
7982
/>
8083
<Tab
8184
disableRipple
8285
classes={{ root: classes.tabRoot, selected: classes.tabSelected }}
8386
label="CSS Editor"
87+
onClick={showBottomPanel}
8488
/>
8589
<Tab
8690
disableRipple
8791
classes={{ root: classes.tabRoot, selected: classes.tabSelected }}
8892
label="Component Tree"
93+
onClick={showBottomPanel}
8994
/>
9095
<Tab
9196
disableRipple
9297
classes={{ root: classes.tabRoot, selected: classes.tabSelected }}
9398
label="Context Manager"
99+
onClick={showBottomPanel}
94100
/>
95101
<Tab
96102
disableRipple
97103
classes={{ root: classes.tabRoot, selected: classes.tabSelected }}
98104
label="State Manager"
105+
onClick={showBottomPanel}
99106
/>
100107
<Tab
101108
disableRipple

app/src/containers/MainContainer.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,27 @@ const MainContainer = (props): JSX.Element => {
109109
setBottomShow(false);
110110
};
111111

112-
let showPanel = bottomShow ? 'bottom-show' : 'bottom-hide';
112+
const hideBottomPanelStyles = {
113+
maxHeight: '64px',
114+
boxSizing: 'border-box',
115+
transition: 'all 0.5s ease-in-out'
116+
};
117+
118+
const showBottomPanelStyles = {
119+
maxHeight: '100%',
120+
transition: 'all 0.5s ease-in-out'
121+
};
113122

114123
return (
115124
<div className="main-container" style={style} ref={containerRef}>
116125
<div className="main">
117126
<CanvasContainer isThemeLight={props.isThemeLight} />
118127
<DemoRender />
119128
</div>
120-
<div className={showPanel} ref={ref}>
129+
<div
130+
ref={ref}
131+
style={bottomShow ? showBottomPanelStyles : hideBottomPanelStyles}
132+
>
121133
<BottomPanel
122134
bottomShow={bottomShow}
123135
setBottomShow={setBottomShow}

app/src/public/styles/style.css

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -502,25 +502,6 @@ BOTTOM PANEL
502502
/////////////////////////////////////////////////////
503503
*/
504504

505-
.bottom-hide {
506-
max-height: 64px;
507-
box-sizing: border-box;
508-
transition: all 0.5s ease-in-out;
509-
}
510-
511-
.bottom-show {
512-
max-height: 100%;
513-
transition: all 0.5s ease-in-out;
514-
}
515-
516-
.bottom-hide:focus-within {
517-
max-height: 100%;
518-
}
519-
/*
520-
.bottom-hide:hover {
521-
max-height: 100%;
522-
} */
523-
524505
.tab-content {
525506
height: calc(100% - 76px);
526507
width: 100%;

0 commit comments

Comments
 (0)