-
Notifications
You must be signed in to change notification settings - Fork 195
[UI]: Make sidebards resizable and add local persistence #1098
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
Merged
banana-three-join
merged 3 commits into
layer5io:master
from
banana-three-join:feature/banana-three-join/resizable-side-panels
Jun 23, 2026
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| (function () { | ||
| try { | ||
| var leftWidth = parseInt(localStorage.getItem("left-sidebar-width"), 10); | ||
| var tocWidth = parseInt(localStorage.getItem("toc-width"), 10); | ||
| var cssStyles = ""; | ||
|
|
||
| if (!isNaN(leftWidth)) cssStyles += "--left-sidebar-width: " + leftWidth + "px;"; | ||
| if (!isNaN(tocWidth)) cssStyles += "--toc-width: " + tocWidth + "px;"; | ||
|
|
||
| if (cssStyles) { | ||
| var styleTag = document.createElement("style"); | ||
| styleTag.innerHTML = ".td-resizable-grid .td-main > .row.flex-xl-nowrap {" + cssStyles + "}"; | ||
| document.head.appendChild(styleTag); | ||
| } | ||
| } catch (e) { | ||
| console.warn("LocalStorage blocked or unavailable:", e); | ||
| } | ||
| })(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| (function () { | ||
| document.addEventListener("DOMContentLoaded", () => { | ||
| const gridContainer = document.querySelector(".td-resizable-grid .td-main > .row.flex-xl-nowrap"); | ||
| const leftResizer = document.getElementById("left-resizer"); | ||
| const rightResizer = document.getElementById("right-resizer"); | ||
|
|
||
| if (!gridContainer) return; | ||
|
|
||
| const LEFT_SIDEBAR_KEY = "left-sidebar-width"; | ||
| const TOC_KEY = "toc-width"; | ||
|
|
||
| const storage = { | ||
| get: (key) => { | ||
| try { return localStorage.getItem(key); } | ||
| catch (e) { return null; } | ||
| }, | ||
| set: (key, value) => { | ||
| try { localStorage.setItem(key, value); } | ||
| catch (e) { return null; } | ||
| } | ||
| }; | ||
|
|
||
| function setupResizer(resizer, type) { | ||
| resizer.addEventListener("pointerdown", (e) => { | ||
| e.preventDefault(); | ||
|
|
||
| resizer.setPointerCapture(e.pointerId); | ||
| resizer.classList.add("is-dragging"); | ||
|
|
||
| document.body.style.cursor = "col-resize"; | ||
| document.body.style.userSelect = "none"; | ||
|
|
||
| const startX = e.clientX; | ||
| const styles = window.getComputedStyle(gridContainer); | ||
| const gridColumns = styles.gridTemplateColumns ? styles.gridTemplateColumns.split(" ") : []; | ||
|
|
||
| /* | ||
| grid-template-columns over in _styles_project.scss has the following structure: | ||
|
|
||
| min(768px) | ||
| --left-sidebar-width --sidebar-resize-width 1fr | ||
|
|
||
| min(1200px) | ||
| --left-sidebar-width --sidebar-resize-width 1fr --sidebar-resize-width --toc-width; | ||
|
|
||
| so gridcolumns[0] targets the left sidebar and gridcolumns[4] targets the toc | ||
| */ | ||
|
|
||
| let initialLeftSidebarWidth, initialTocWidth; | ||
| if (gridColumns.length >= 5 && gridColumns[0] !== "none") { | ||
| initialLeftSidebarWidth = parseInt(gridColumns[0], 10); | ||
| initialTocWidth = parseInt(gridColumns[4], 10); | ||
| } else { | ||
| initialLeftSidebarWidth = parseInt(styles.getPropertyValue('--left-sidebar-width'), 10); | ||
| initialTocWidth = parseInt(styles.getPropertyValue('--toc-width'), 10); | ||
| } | ||
|
|
||
| const minWidth = parseInt(styles.getPropertyValue(type === "left" ? '--left-sidebar-min-width' : '--toc-min-width'), 10); | ||
| const maxWidth = parseInt(styles.getPropertyValue(type === "left" ? '--left-sidebar-max-width' : '--toc-max-width'), 10); | ||
| let currentWidth = type === "left" ? initialLeftSidebarWidth : initialTocWidth; | ||
| let ticking = false; | ||
| let animationFrameId = null; | ||
|
|
||
| function onPointerMove(moveEvent) { | ||
| const deltaX = moveEvent.clientX - startX; | ||
|
|
||
| if (type === "left") { | ||
| currentWidth = Math.max(minWidth, Math.min(maxWidth, initialLeftSidebarWidth + deltaX)); | ||
| } else if (type === "right") { | ||
| currentWidth = Math.max(minWidth, Math.min(maxWidth, initialTocWidth - deltaX)); | ||
| } | ||
|
|
||
| if (!ticking) { | ||
| animationFrameId = window.requestAnimationFrame(() => { | ||
| const varName = type === "left" ? "--left-sidebar-width" : "--toc-width"; | ||
| gridContainer.style.setProperty(varName, `${currentWidth}px`); | ||
| ticking = false; | ||
| }); | ||
| ticking = true; | ||
| } | ||
| } | ||
|
|
||
| function onPointerUp(upEvent) { | ||
| if (animationFrameId) { | ||
| window.cancelAnimationFrame(animationFrameId); | ||
| animationFrameId = null; | ||
| ticking = false; | ||
| } | ||
|
|
||
| resizer.releasePointerCapture(upEvent.pointerId); | ||
| resizer.classList.remove("is-dragging"); | ||
|
|
||
| document.body.style.cursor = ""; | ||
| document.body.style.userSelect = ""; | ||
|
|
||
| const storageKey = type === "left" ? LEFT_SIDEBAR_KEY : TOC_KEY; | ||
| storage.set(storageKey, currentWidth); | ||
|
|
||
| document.removeEventListener("pointermove", onPointerMove); | ||
| document.removeEventListener("pointerup", onPointerUp); | ||
| document.removeEventListener("pointercancel", onPointerUp); | ||
| } | ||
|
|
||
| document.addEventListener("pointermove", onPointerMove); | ||
| document.addEventListener("pointerup", onPointerUp); | ||
| document.addEventListener("pointercancel", onPointerUp); | ||
| }); | ||
| } | ||
|
|
||
| if (leftResizer) setupResizer(leftResizer, "left"); | ||
| if (rightResizer) setupResizer(rightResizer, "right"); | ||
| }); | ||
| })(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| {{ $resizerScript := resources.Get "js/sidebar-load-width.js" | minify | fingerprint }} | ||
| <script src="{{ $resizerScript.RelPermalink }}"></script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| {{ $resizerScript := resources.Get "js/sidebar-resizer.js" | minify | fingerprint }} | ||
| <script src="{{ $resizerScript.RelPermalink }}" defer></script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.