1
1
// @flow
2
2
3
- import React , { useState , memo } from "react"
3
+ import React , { useState , memo , useCallback } from "react"
4
4
import Paper from "@material-ui/core/Paper"
5
5
import { makeStyles } from "@material-ui/core/styles"
6
6
import ExpandIcon from "@material-ui/icons/ExpandMore"
@@ -11,34 +11,47 @@ import classnames from "classnames"
11
11
import useEventCallback from "use-event-callback"
12
12
import Typography from "@material-ui/core/Typography"
13
13
import { useIconDictionary } from "../icon-dictionary.js"
14
+ import ResizePanel from "react-resize-panel"
14
15
15
16
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
+ } ,
17
21
header : {
18
22
display : "flex" ,
19
23
flexDirection : "row" ,
20
24
alignItems : "center" ,
21
- padding : 8 ,
25
+ padding : 4 ,
22
26
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
+ } ,
24
38
} ,
25
39
title : {
26
- fontSize : 14 ,
27
- fontWeight : "bold" ,
40
+ fontSize : 11 ,
28
41
flexGrow : 1 ,
42
+ fontWeight : 800 ,
29
43
paddingLeft : 8 ,
30
44
color : grey [ 800 ] ,
31
45
"& span" : {
32
46
color : grey [ 600 ] ,
33
- fontSize : 12 ,
47
+ fontSize : 11 ,
34
48
} ,
35
49
} ,
36
50
expandButton : {
37
51
padding : 0 ,
38
52
width : 30 ,
39
53
height : 30 ,
40
54
"& .icon" : {
41
- marginTop : - 6 ,
42
55
width : 20 ,
43
56
height : 20 ,
44
57
transition : "500ms transform" ,
@@ -57,13 +70,28 @@ const useStyles = makeStyles({
57
70
} ,
58
71
} )
59
72
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
+
60
88
export const SidebarBox = ( {
61
89
icon,
62
90
title,
63
91
subTitle,
64
92
children,
65
93
noScroll = false ,
66
- expandedByDefault = false ,
94
+ expandedByDefault,
67
95
} ) => {
68
96
const classes = useStyles ( )
69
97
const content = (
@@ -74,14 +102,28 @@ export const SidebarBox = ({
74
102
</ div >
75
103
)
76
104
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
+
78
118
const toggleExpanded = useEventCallback ( ( ) => changeExpanded ( ! expanded ) )
79
119
const customIconMapping = useIconDictionary ( )
80
120
const TitleIcon = customIconMapping [ title . toLowerCase ( ) ]
81
121
return (
82
- < Paper className = { classes . container } >
122
+ < div className = { classes . container } >
83
123
< div className = { classes . header } >
84
- { icon || < TitleIcon /> }
124
+ < div className = "iconContainer" >
125
+ { icon || < TitleIcon className = { classes . titleIcon } /> }
126
+ </ div >
85
127
< Typography className = { classes . title } >
86
128
{ title } < span > { subTitle } </ span >
87
129
</ Typography >
@@ -94,9 +136,18 @@ export const SidebarBox = ({
94
136
content
95
137
) : null
96
138
) : (
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 >
98
149
) }
99
- </ Paper >
150
+ </ div >
100
151
)
101
152
}
102
153
0 commit comments