Skip to content

feat: Make sidebar width adjustable #2872

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: alpha
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/FlowFooter/FlowFooter.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
.footer {
@include animation('footer-enter 0.5s cubic-bezier(0.165, 0.84, 0.44, 1)');
position: fixed;
left: 300px;
left: var(--sidebar-width, 300px);
right: 0;
bottom: 0;
background: #fbfbfc;
Expand Down
29 changes: 28 additions & 1 deletion src/components/Sidebar/Sidebar.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import AppsMenu from 'components/Sidebar/AppsMenu.react';
import AppName from 'components/Sidebar/AppName.react';
import isInsidePopover from 'lib/isInsidePopover';
import Pin from 'components/Sidebar/Pin.react';
import React, { useEffect, useState, useContext } from 'react';
import React, { useEffect, useState, useContext, useRef } from 'react';
import SidebarHeader from 'components/Sidebar/SidebarHeader.react';
import SidebarSection from 'components/Sidebar/SidebarSection.react';
import SidebarSubItem from 'components/Sidebar/SidebarSubItem.react';
Expand All @@ -36,6 +36,9 @@ const Sidebar = ({
const [appsMenuOpen, setAppsMenuOpen] = useState(false);
const [collapsed, setCollapsed] = useState(false);
const [fixed, setFixed] = useState(true);
const initialWidth = parseInt(localStorage.getItem('sidebarWidth') || '300', 10);
const [width, setWidth] = useState(initialWidth);
const widthRef = useRef(initialWidth);
const [dashboardUser, setDashboardUser] = useState('');
fetch(mountPath).then(response => {
setDashboardUser(response.headers.get('username'));
Expand Down Expand Up @@ -66,6 +69,11 @@ const Sidebar = ({
};
});

useEffect(() => {
document.documentElement.style.setProperty('--sidebar-width', `${width}px`);
widthRef.current = width;
}, [width]);

const sidebarClasses = [styles.sidebar];
if (fixed) {
document.body.className = document.body.className.replace(' expanded', '');
Expand Down Expand Up @@ -112,6 +120,24 @@ const Sidebar = ({
}
};

const startResize = e => {
e.preventDefault();
const startX = e.clientX;
const startWidth = widthRef.current;
const doDrag = ev => {
const newWidth = Math.max(200, startWidth + ev.clientX - startX);
widthRef.current = newWidth;
setWidth(newWidth);
};
const stopDrag = () => {
document.removeEventListener('mousemove', doDrag);
document.removeEventListener('mouseup', stopDrag);
localStorage.setItem('sidebarWidth', widthRef.current.toString());
};
document.addEventListener('mousemove', doDrag);
document.addEventListener('mouseup', stopDrag);
};

let sidebarContent;
if (appsMenuOpen) {
const apps = []
Expand Down Expand Up @@ -192,6 +218,7 @@ const Sidebar = ({
</a>
</div>
)}
<div className={styles.resizeHandle} onMouseDown={startResize} />
</div>
);
};
Expand Down
14 changes: 12 additions & 2 deletions src/components/Sidebar/Sidebar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,24 @@ $footerHeight: 36px;

.sidebar {
position: fixed;
width: 300px;
width: var(--sidebar-width, 300px);
top: 0;
left: 0;
bottom: 0;
background: #0c5582;
color: #fff;
z-index: 100;

.resizeHandle {
position: absolute;
top: 0;
right: 0;
bottom: 0;
width: 5px;
cursor: col-resize;
user-select: none;
}

&.collapsed {
left: 0;
width: 54px;
Expand Down Expand Up @@ -161,7 +171,7 @@ $footerHeight: 36px;
.appsMenu {
overflow: auto;
background: #094162;
width: 300px;
width: var(--sidebar-width, 300px);

.menuRow:hover {
background: #0c5582;
Expand Down
2 changes: 1 addition & 1 deletion src/components/Toolbar/Toolbar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
position: fixed;
top: 0;
right: 0;
left: 300px;
left: var(--sidebar-width, 300px);
background: #353446;
height: 96px;
color: white;
Expand Down
2 changes: 1 addition & 1 deletion src/dashboard/Dashboard.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@import 'stylesheets/globals.scss';

.content {
margin-left: 300px;
margin-left: var(--sidebar-width, 300px);
overflow: auto;
max-height: 100vh;
}
Expand Down
4 changes: 2 additions & 2 deletions src/dashboard/Data/Browser/Browser.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
.browser {
position: fixed;
top: 96px;
left: 300px;
left: var(--sidebar-width, 300px);
right: 0;
bottom: 36px;
overflow: auto;
Expand All @@ -24,7 +24,7 @@ body:global(.expanded) {

.empty {
position: fixed;
left: 300px;
left: var(--sidebar-width, 300px);
top: 0;
bottom: 0;
right: 0;
Expand Down
2 changes: 1 addition & 1 deletion src/dashboard/Data/Browser/BrowserFooter.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

.footer {
position: absolute;
width: calc(100% - 300px);
width: calc(100% - var(--sidebar-width, 300px));
bottom: 0;
gap: 10px;
padding: 0px 15px;
Expand Down
2 changes: 1 addition & 1 deletion src/dashboard/TableView.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
.headers {
position: fixed;
top: 96px;
left: 300px;
left: var(--sidebar-width, 300px);
right: 0;
background: #66637A;
height: 30px;
Expand Down
4 changes: 2 additions & 2 deletions src/parse-interface-guide/PIG.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
.sidebar {
position: fixed;
background: white;
width: 300px;
width: var(--sidebar-width, 300px);
padding: 10px;
border-right: 1px solid #b0b8bf;
top: 0;
Expand Down Expand Up @@ -53,7 +53,7 @@
}

.content {
margin-left: 300px;
margin-left: var(--sidebar-width, 300px);
padding: 20px 10px 10px 10px;
min-height: 100vh;
}
Expand Down
4 changes: 4 additions & 0 deletions src/stylesheets/base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
*/
@import 'globals.scss';

:root {
--sidebar-width: 300px;
}

html, body {
min-height: 100vh;
}
Expand Down
Loading