Skip to content

Commit fd7229d

Browse files
committed
feat(ui): make sidebar resizable
1 parent cfd0bce commit fd7229d

File tree

10 files changed

+53
-12
lines changed

10 files changed

+53
-12
lines changed

src/components/FlowFooter/FlowFooter.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
.footer {
1111
@include animation('footer-enter 0.5s cubic-bezier(0.165, 0.84, 0.44, 1)');
1212
position: fixed;
13-
left: 300px;
13+
left: var(--sidebar-width, 300px);
1414
right: 0;
1515
bottom: 0;
1616
background: #fbfbfc;

src/components/Sidebar/Sidebar.react.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import AppsMenu from 'components/Sidebar/AppsMenu.react';
1010
import AppName from 'components/Sidebar/AppName.react';
1111
import isInsidePopover from 'lib/isInsidePopover';
1212
import Pin from 'components/Sidebar/Pin.react';
13-
import React, { useEffect, useState, useContext } from 'react';
13+
import React, { useEffect, useState, useContext, useRef } from 'react';
1414
import SidebarHeader from 'components/Sidebar/SidebarHeader.react';
1515
import SidebarSection from 'components/Sidebar/SidebarSection.react';
1616
import SidebarSubItem from 'components/Sidebar/SidebarSubItem.react';
@@ -36,6 +36,9 @@ const Sidebar = ({
3636
const [appsMenuOpen, setAppsMenuOpen] = useState(false);
3737
const [collapsed, setCollapsed] = useState(false);
3838
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);
3942
const [dashboardUser, setDashboardUser] = useState('');
4043
fetch(mountPath).then(response => {
4144
setDashboardUser(response.headers.get('username'));
@@ -66,6 +69,11 @@ const Sidebar = ({
6669
};
6770
});
6871

72+
useEffect(() => {
73+
document.documentElement.style.setProperty('--sidebar-width', `${width}px`);
74+
widthRef.current = width;
75+
}, [width]);
76+
6977
const sidebarClasses = [styles.sidebar];
7078
if (fixed) {
7179
document.body.className = document.body.className.replace(' expanded', '');
@@ -112,6 +120,24 @@ const Sidebar = ({
112120
}
113121
};
114122

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+
115141
let sidebarContent;
116142
if (appsMenuOpen) {
117143
const apps = []
@@ -192,6 +218,7 @@ const Sidebar = ({
192218
</a>
193219
</div>
194220
)}
221+
<div className={styles.resizeHandle} onMouseDown={startResize} />
195222
</div>
196223
);
197224
};

src/components/Sidebar/Sidebar.scss

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,24 @@ $footerHeight: 36px;
1414

1515
.sidebar {
1616
position: fixed;
17-
width: 300px;
17+
width: var(--sidebar-width, 300px);
1818
top: 0;
1919
left: 0;
2020
bottom: 0;
2121
background: #0c5582;
2222
color: #fff;
2323
z-index: 100;
2424

25+
.resizeHandle {
26+
position: absolute;
27+
top: 0;
28+
right: 0;
29+
bottom: 0;
30+
width: 5px;
31+
cursor: col-resize;
32+
user-select: none;
33+
}
34+
2535
&.collapsed {
2636
left: 0;
2737
width: 54px;
@@ -161,7 +171,7 @@ $footerHeight: 36px;
161171
.appsMenu {
162172
overflow: auto;
163173
background: #094162;
164-
width: 300px;
174+
width: var(--sidebar-width, 300px);
165175

166176
.menuRow:hover {
167177
background: #0c5582;

src/components/Toolbar/Toolbar.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
position: fixed;
1212
top: 0;
1313
right: 0;
14-
left: 300px;
14+
left: var(--sidebar-width, 300px);
1515
background: #353446;
1616
height: 96px;
1717
color: white;

src/dashboard/Dashboard.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
@import 'stylesheets/globals.scss';
99

1010
.content {
11-
margin-left: 300px;
11+
margin-left: var(--sidebar-width, 300px);
1212
overflow: auto;
1313
max-height: 100vh;
1414
}

src/dashboard/Data/Browser/Browser.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
.browser {
1111
position: fixed;
1212
top: 96px;
13-
left: 300px;
13+
left: var(--sidebar-width, 300px);
1414
right: 0;
1515
bottom: 36px;
1616
overflow: auto;
@@ -24,7 +24,7 @@ body:global(.expanded) {
2424

2525
.empty {
2626
position: fixed;
27-
left: 300px;
27+
left: var(--sidebar-width, 300px);
2828
top: 0;
2929
bottom: 0;
3030
right: 0;

src/dashboard/Data/Browser/BrowserFooter.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
.footer {
44
position: absolute;
5-
width: calc(100% - 300px);
5+
width: calc(100% - var(--sidebar-width, 300px));
66
bottom: 0;
77
gap: 10px;
88
padding: 0px 15px;

src/dashboard/TableView.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
.headers {
1111
position: fixed;
1212
top: 96px;
13-
left: 300px;
13+
left: var(--sidebar-width, 300px);
1414
right: 0;
1515
background: #66637A;
1616
height: 30px;

src/parse-interface-guide/PIG.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
.sidebar {
1212
position: fixed;
1313
background: white;
14-
width: 300px;
14+
width: var(--sidebar-width, 300px);
1515
padding: 10px;
1616
border-right: 1px solid #b0b8bf;
1717
top: 0;
@@ -53,7 +53,7 @@
5353
}
5454

5555
.content {
56-
margin-left: 300px;
56+
margin-left: var(--sidebar-width, 300px);
5757
padding: 20px 10px 10px 10px;
5858
min-height: 100vh;
5959
}

src/stylesheets/base.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
*/
88
@import 'globals.scss';
99

10+
:root {
11+
--sidebar-width: 300px;
12+
}
13+
1014
html, body {
1115
min-height: 100vh;
1216
}

0 commit comments

Comments
 (0)