11// @flow
22
3- import React , { useState , memo } from "react"
3+ import React , { useState , memo , useCallback } from "react"
44import Paper from "@material-ui/core/Paper"
55import { makeStyles } from "@material-ui/core/styles"
66import ExpandIcon from "@material-ui/icons/ExpandMore"
@@ -11,34 +11,47 @@ import classnames from "classnames"
1111import useEventCallback from "use-event-callback"
1212import Typography from "@material-ui/core/Typography"
1313import { useIconDictionary } from "../icon-dictionary.js"
14+ import ResizePanel from "react-resize-panel"
1415
1516const 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+
6088export 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
0 commit comments