Skip to content

Commit ca5c35c

Browse files
authored
fix: Merge pull request #14 from UniversalDataTool/overhaul-1
Shrink UI Elements
2 parents 581f742 + 218f262 commit ca5c35c

File tree

8 files changed

+125
-31
lines changed

8 files changed

+125
-31
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"@material-ui/icons": "^4.9.1",
1111
"classnames": "^2.2.6",
1212
"react": "^16.13.1",
13+
"react-resize-panel": "^0.3.5",
1314
"react-use-dimensions": "^1.2.1",
1415
"use-event-callback": "^0.1.0"
1516
},

src/HeaderButton/index.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Button from "@material-ui/core/Button"
55
import { styled } from "@material-ui/core/styles"
66
import { useIconDictionary } from "../icon-dictionary.js"
77
import { iconMapping } from "../icon-mapping.js"
8+
import { colors } from "@material-ui/core"
89

910
const defaultNameIconMapping = iconMapping
1011

@@ -18,19 +19,28 @@ const getIcon = (name, customIconMapping) => {
1819

1920
const StyledButton = styled(Button)({
2021
textTransform: "none",
21-
width: 80,
22-
marginLeft: 4,
23-
marginRight: 4,
22+
width: 60,
23+
paddingTop: 8,
24+
paddingBottom: 4,
25+
marginLeft: 1,
26+
marginRight: 1,
2427
})
2528
const ButtonInnerContent = styled("div")({
2629
display: "flex",
2730
flexDirection: "column",
2831
})
29-
const IconContainer = styled("div")({})
32+
const IconContainer = styled("div")({
33+
color: colors.grey[700],
34+
height: 20,
35+
"& .MuiSvgIcon-root": {
36+
width: 18,
37+
height: 18,
38+
},
39+
})
3040
const Text = styled("div")({
3141
fontWeight: "bold",
32-
lineHeight: 1,
33-
height: 28,
42+
fontSize: 11,
43+
color: colors.grey[800],
3444
display: "flex",
3545
alignItems: "center",
3646
justifyContent: "center",

src/IconSidebar/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ type Props = {
2323
|}>,
2424
}
2525

26+
const emptyAr = []
27+
2628
export const IconSidebar = ({
27-
items = [],
29+
items = emptyAr,
2830
onClickItem,
29-
selectedTools,
31+
selectedTools = emptyAr,
3032
}: Props) => {
3133
const customIconMapping = useIconDictionary()
3234
return (

src/RightSidebar/index.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,22 +73,28 @@ const InnerSliderContent = styled("div")({
7373
})
7474

7575
const getInitialExpandedState = () => {
76-
return Boolean(window.__REACT_WORKSPACE_LAYOUT_EXPANDED_STATE)
76+
try {
77+
return JSON.parse(window.localStorage.__REACT_WORKSPACE_LAYOUT_EXPANDED)
78+
} catch (e) {
79+
return window.innerWidth > 1000 ? true : false
80+
}
7781
}
7882

79-
export const RightSidebar = ({ children, initialExpandedState, height }) => {
83+
export const RightSidebar = ({ children, initiallyExpanded, height }) => {
8084
const [expanded, toggleExpanded] = useReducer(
8185
(state) => !state,
82-
initialExpandedState === undefined
86+
initiallyExpanded === undefined
8387
? getInitialExpandedState()
84-
: initialExpandedState
88+
: initiallyExpanded
8589
)
8690

8791
useEffect(() => {
88-
if (initialExpandedState !== undefined) {
89-
window.__REACT_WORKSPACE_LAYOUT_EXPANDED_STATE = expanded
92+
if (initiallyExpanded === undefined) {
93+
window.localStorage.__REACT_WORKSPACE_LAYOUT_EXPANDED = JSON.stringify(
94+
expanded
95+
)
9096
}
91-
}, [initialExpandedState, expanded])
97+
}, [initiallyExpanded, expanded])
9298

9399
const containerStyle = useMemo(() => ({ height: height || "100%" }), [height])
94100

src/SidebarBox/index.js

Lines changed: 65 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @flow
22

3-
import React, { useState, memo } from "react"
3+
import React, { useState, memo, useCallback } from "react"
44
import Paper from "@material-ui/core/Paper"
55
import { makeStyles } from "@material-ui/core/styles"
66
import ExpandIcon from "@material-ui/icons/ExpandMore"
@@ -11,34 +11,47 @@ import classnames from "classnames"
1111
import useEventCallback from "use-event-callback"
1212
import Typography from "@material-ui/core/Typography"
1313
import { useIconDictionary } from "../icon-dictionary.js"
14+
import ResizePanel from "react-resize-panel"
1415

1516
const useStyles = makeStyles({
16-
container: { margin: 8, border: "1px solid #ccc" },
17+
container: {
18+
borderBottom: `2px solid ${grey[400]}`,
19+
"&:first-child": { borderTop: `1px solid ${grey[400]}` },
20+
},
1721
header: {
1822
display: "flex",
1923
flexDirection: "row",
2024
alignItems: "center",
21-
padding: 8,
25+
padding: 4,
2226
paddingLeft: 16,
23-
paddingRight: 16,
27+
paddingRight: 12,
28+
"& .iconContainer": {
29+
color: grey[600],
30+
display: "flex",
31+
alignItems: "center",
32+
justifyContent: "center",
33+
"& .MuiSvgIcon-root": {
34+
width: 16,
35+
height: 16,
36+
},
37+
},
2438
},
2539
title: {
26-
fontSize: 14,
27-
fontWeight: "bold",
40+
fontSize: 11,
2841
flexGrow: 1,
42+
fontWeight: 800,
2943
paddingLeft: 8,
3044
color: grey[800],
3145
"& span": {
3246
color: grey[600],
33-
fontSize: 12,
47+
fontSize: 11,
3448
},
3549
},
3650
expandButton: {
3751
padding: 0,
3852
width: 30,
3953
height: 30,
4054
"& .icon": {
41-
marginTop: -6,
4255
width: 20,
4356
height: 20,
4457
transition: "500ms transform",
@@ -57,13 +70,28 @@ const useStyles = makeStyles({
5770
},
5871
})
5972

73+
const getExpandedFromLocalStorage = (title) => {
74+
try {
75+
return JSON.parse(
76+
window.localStorage[`__REACT_WORKSPACE_SIDEBAR_EXPANDED_${title}`]
77+
)
78+
} catch (e) {
79+
return false
80+
}
81+
}
82+
const setExpandedInLocalStorage = (title, expanded) => {
83+
window.localStorage[
84+
`__REACT_WORKSPACE_SIDEBAR_EXPANDED_${title}`
85+
] = JSON.stringify(expanded)
86+
}
87+
6088
export const SidebarBox = ({
6189
icon,
6290
title,
6391
subTitle,
6492
children,
6593
noScroll = false,
66-
expandedByDefault = false,
94+
expandedByDefault,
6795
}) => {
6896
const classes = useStyles()
6997
const content = (
@@ -74,14 +102,28 @@ export const SidebarBox = ({
74102
</div>
75103
)
76104

77-
const [expanded, changeExpanded] = useState(expandedByDefault)
105+
const [expanded, changeExpandedState] = useState(
106+
expandedByDefault === undefined
107+
? getExpandedFromLocalStorage(title)
108+
: expandedByDefault
109+
)
110+
const changeExpanded = useCallback(
111+
(expanded) => {
112+
changeExpandedState(expanded)
113+
setExpandedInLocalStorage(title, expanded)
114+
},
115+
[changeExpandedState, title]
116+
)
117+
78118
const toggleExpanded = useEventCallback(() => changeExpanded(!expanded))
79119
const customIconMapping = useIconDictionary()
80120
const TitleIcon = customIconMapping[title.toLowerCase()]
81121
return (
82-
<Paper className={classes.container}>
122+
<div className={classes.container}>
83123
<div className={classes.header}>
84-
{icon || <TitleIcon />}
124+
<div className="iconContainer">
125+
{icon || <TitleIcon className={classes.titleIcon} />}
126+
</div>
85127
<Typography className={classes.title}>
86128
{title} <span>{subTitle}</span>
87129
</Typography>
@@ -94,9 +136,18 @@ export const SidebarBox = ({
94136
content
95137
) : null
96138
) : (
97-
<Collapse in={expanded}>{content}</Collapse>
139+
<Collapse in={expanded}>
140+
<ResizePanel direction="s" style={{ height: 200 }}>
141+
<div
142+
className="panel"
143+
style={{ display: "flex", overflow: "hidden", height: 500 }}
144+
>
145+
{content}
146+
</div>
147+
</ResizePanel>
148+
</Collapse>
98149
)}
99-
</Paper>
150+
</div>
100151
)
101152
}
102153

src/Workspace/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export default ({
3737
onClickIconSidebarItem,
3838
headerLeftSide = null,
3939
iconDictionary = emptyObj,
40+
rightSidebarExpanded,
4041
children,
4142
}) => {
4243
const [workContainerRef, workContainerSize] = useDimensions()
@@ -58,7 +59,10 @@ export default ({
5859
)}
5960
<WorkContainer ref={workContainerRef}>{children}</WorkContainer>
6061
{rightSidebarItems.length === 0 ? null : (
61-
<RightSidebar height={workContainerSize.height || 0}>
62+
<RightSidebar
63+
initiallyExpanded={rightSidebarExpanded}
64+
height={workContainerSize.height || 0}
65+
>
6266
{rightSidebarItems}
6367
</RightSidebar>
6468
)}

src/Workspace/index.stories.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { action } from "@storybook/addon-actions"
33
import Workspace from "./"
44
import SidebarBox from "../SidebarBox"
55
import FeaturedVideoIcon from "@material-ui/icons/FeaturedVideo"
6+
import PlayIcon from "@material-ui/icons/PlayArrow"
67

78
export default {
89
title: "Workspace",
@@ -15,6 +16,7 @@ export const Basic = () => (
1516
headerItems={[{ name: "Prev" }, { name: "Next" }, { name: "Save" }]}
1617
onClickHeaderItem={action("onClickHeaderItem")}
1718
onClickIconSidebarItem={action("onClickIconSidebarItem")}
19+
rightSidebarExpanded
1820
iconSidebarItems={[
1921
{
2022
name: "Play",
@@ -23,12 +25,15 @@ export const Basic = () => (
2325
{
2426
name: "Pause",
2527
helperText: "Pause Tooltip",
26-
}
28+
},
2729
]}
2830
rightSidebarItems={[
2931
<SidebarBox icon={<FeaturedVideoIcon />} title="Region Selector">
3032
Hello world!
3133
</SidebarBox>,
34+
<SidebarBox icon={<PlayIcon />} title="Playable GIFs">
35+
Hello world!
36+
</SidebarBox>,
3237
]}
3338
>
3439
<div

yarn.lock

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4160,6 +4160,11 @@ caseless@~0.12.0:
41604160
resolved "https://registry.yarnpkg.com/caseless/-/caseless-0.12.0.tgz#1b681c21ff84033c826543090689420d187151dc"
41614161
integrity sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=
41624162

4163+
cash-dom@^4.1.5:
4164+
version "4.1.5"
4165+
resolved "https://registry.yarnpkg.com/cash-dom/-/cash-dom-4.1.5.tgz#0ef0cf205bc7603aa4e2dfada5808442a7a0e6ca"
4166+
integrity sha512-E6MO0A6ms5iZPtexznQXWRkFEvqdPqCmdx/SiJr2PnhOQNhZNfALkLG5t83Hk3J5JELzED7PJuzhMoS2tT64XA==
4167+
41634168
chalk@2.4.2, chalk@^2.0.0, chalk@^2.0.1, chalk@^2.1.0, chalk@^2.3.2, chalk@^2.4.1, chalk@^2.4.2:
41644169
version "2.4.2"
41654170
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424"
@@ -11212,6 +11217,16 @@ react-popper@^1.3.7:
1121211217
typed-styles "^0.0.7"
1121311218
warning "^4.0.2"
1121411219

11220+
react-resize-panel@^0.3.5:
11221+
version "0.3.5"
11222+
resolved "https://registry.yarnpkg.com/react-resize-panel/-/react-resize-panel-0.3.5.tgz#43aa3450bf5b5a2566b40c4201445ced96c2a905"
11223+
integrity sha512-iyHOFTrSt+WV4Ilzi81x6KH3FU7VsGP736rmxepwGrgAEATmCvXzZdluTm3NpsptP7aC3hLODmXwnxusyA393A==
11224+
dependencies:
11225+
cash-dom "^4.1.5"
11226+
classnames "^2.2.6"
11227+
lodash.debounce "^4.0.8"
11228+
react-draggable "^4.0.3"
11229+
1121511230
react-scripts@3.4.1:
1121611231
version "3.4.1"
1121711232
resolved "https://registry.yarnpkg.com/react-scripts/-/react-scripts-3.4.1.tgz#f551298b5c71985cc491b9acf3c8e8c0ae3ada0a"

0 commit comments

Comments
 (0)