Skip to content

Commit

Permalink
Make the sidebar resizable, closes #1842
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Jan 10, 2024
1 parent b25bf28 commit a191873
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 3 additions & 1 deletion assets/css/layout.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ body {

body {
--sidebarWidth: 300px;
--sidebarMinWidth: 300px;
--sidebarTransitionDuration: 0.3s;
background-color: var(--background);
color: var(--textBody);
Expand All @@ -23,19 +24,20 @@ body {

.main {
display: flex;
justify-content: flex-end;
height: 100%;
}

.sidebar {
display: flex;
flex-direction: column;
width: var(--sidebarWidth);
min-width: var(--sidebarMinWidth);
height: 100%;
position: fixed;
top: 0;
left: 0;
z-index: 100;
resize: horizontal;
}

.sidebar-button {
Expand Down
4 changes: 2 additions & 2 deletions assets/css/search-bar.css
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
height: 57px;
left: 56px;
right: 20px;
transition: top 0.3s;
transition: top var(--sidebarTransitionDuration) ease-in-out;
z-index: 99;
}

Expand All @@ -139,7 +139,7 @@
right: 0;
height: 70px;
background-color: var(--background);
transition: top 0.3s;
transition: all var(--sidebarTransitionDuration) ease-in-out;
z-index: 98;
}

Expand Down
8 changes: 8 additions & 0 deletions assets/js/sidebar/sidebar-drawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,11 @@ function setPreference () {
: (state.sidebarPreference = userPref.CLOSED)
}
}

const resizeObserver = new ResizeObserver((entries) => {
for (const entry of entries) {
document.body.style.setProperty('--sidebarWidth', `${entry.contentRect.width}px`);
}
});

resizeObserver.observe(document.getElementById('sidebar'));

0 comments on commit a191873

Please sign in to comment.