@@ -10,7 +10,7 @@ import AppsMenu from 'components/Sidebar/AppsMenu.react';
10
10
import AppName from 'components/Sidebar/AppName.react' ;
11
11
import isInsidePopover from 'lib/isInsidePopover' ;
12
12
import Pin from 'components/Sidebar/Pin.react' ;
13
- import React , { useEffect , useState , useContext } from 'react' ;
13
+ import React , { useEffect , useState , useContext , useRef } from 'react' ;
14
14
import SidebarHeader from 'components/Sidebar/SidebarHeader.react' ;
15
15
import SidebarSection from 'components/Sidebar/SidebarSection.react' ;
16
16
import SidebarSubItem from 'components/Sidebar/SidebarSubItem.react' ;
@@ -36,6 +36,9 @@ const Sidebar = ({
36
36
const [ appsMenuOpen , setAppsMenuOpen ] = useState ( false ) ;
37
37
const [ collapsed , setCollapsed ] = useState ( false ) ;
38
38
const [ fixed , setFixed ] = useState ( true ) ;
39
+ const initialWidth = parseInt ( localStorage . getItem ( 'sidebarWidth' ) || '300' , 10 ) ;
40
+ const [ width , setWidth ] = useState ( initialWidth ) ;
41
+ const widthRef = useRef ( initialWidth ) ;
39
42
const [ dashboardUser , setDashboardUser ] = useState ( '' ) ;
40
43
fetch ( mountPath ) . then ( response => {
41
44
setDashboardUser ( response . headers . get ( 'username' ) ) ;
@@ -66,6 +69,11 @@ const Sidebar = ({
66
69
} ;
67
70
} ) ;
68
71
72
+ useEffect ( ( ) => {
73
+ document . documentElement . style . setProperty ( '--sidebar-width' , `${ width } px` ) ;
74
+ widthRef . current = width ;
75
+ } , [ width ] ) ;
76
+
69
77
const sidebarClasses = [ styles . sidebar ] ;
70
78
if ( fixed ) {
71
79
document . body . className = document . body . className . replace ( ' expanded' , '' ) ;
@@ -112,6 +120,24 @@ const Sidebar = ({
112
120
}
113
121
} ;
114
122
123
+ const startResize = e => {
124
+ e . preventDefault ( ) ;
125
+ const startX = e . clientX ;
126
+ const startWidth = widthRef . current ;
127
+ const doDrag = ev => {
128
+ const newWidth = Math . max ( 200 , startWidth + ev . clientX - startX ) ;
129
+ widthRef . current = newWidth ;
130
+ setWidth ( newWidth ) ;
131
+ } ;
132
+ const stopDrag = ( ) => {
133
+ document . removeEventListener ( 'mousemove' , doDrag ) ;
134
+ document . removeEventListener ( 'mouseup' , stopDrag ) ;
135
+ localStorage . setItem ( 'sidebarWidth' , widthRef . current . toString ( ) ) ;
136
+ } ;
137
+ document . addEventListener ( 'mousemove' , doDrag ) ;
138
+ document . addEventListener ( 'mouseup' , stopDrag ) ;
139
+ } ;
140
+
115
141
let sidebarContent ;
116
142
if ( appsMenuOpen ) {
117
143
const apps = [ ]
@@ -192,6 +218,7 @@ const Sidebar = ({
192
218
</ a >
193
219
</ div >
194
220
) }
221
+ < div className = { styles . resizeHandle } onMouseDown = { startResize } />
195
222
</ div >
196
223
) ;
197
224
} ;
0 commit comments