Fix/consolidate popup bottom lines#1041
Conversation
Signed-off-by: Rudra2637 <singhrudra2637@gmail.com>
Signed-off-by: Rudra2637 <singhrudra2637@gmail.com>
Signed-off-by: Rudra2637 <singhrudra2637@gmail.com>
Signed-off-by: Rudra2637 <singhrudra2637@gmail.com>
|
Yay, your first pull request! 👍 A contributor will be by to give feedback soon. In the meantime, please review the Layer5 Community Welcome Guide and sure to join the community Slack. |
There was a problem hiding this comment.
Code Review
This pull request introduces a resizable panels feature for the documentation site, allowing users to adjust the widths of the sidebar and table of contents. The implementation includes a new JavaScript module for handling drag interactions and persisting layout preferences in local storage, along with corresponding SCSS for styling the resize handles. Feedback focuses on optimizing performance by refining event listener management and reducing redundant DOM updates, improving accuracy by using container-relative widths for calculations, and adopting modern DOM manipulation techniques like classList. Additionally, it was noted that unused constants should be removed and CSS transitions should target the width property for better compatibility with the Bootstrap grid.
| const COL_CLASSES = { | ||
| 'col-1': 8.33, | ||
| 'col-2': 16.66, | ||
| 'col-3': 25, | ||
| 'col-4': 33.33, | ||
| 'col-5': 41.66, | ||
| 'col-6': 50, | ||
| 'col-7': 58.33, | ||
| 'col-8': 66.66, | ||
| 'col-9': 75, | ||
| 'col-10': 83.33, | ||
| 'col-11': 91.66, | ||
| 'col-12': 100 | ||
| }; |
| addEventListeners() { | ||
| document.addEventListener('mousedown', (e) => this.onMouseDown(e)); | ||
| document.addEventListener('mousemove', (e) => this.onMouseMove(e)); | ||
| document.addEventListener('mouseup', (e) => this.onMouseUp(e)); | ||
| } |
| onMouseDown(e) { | ||
| if (!e.target.classList.contains('resizable-panel-handle')) { | ||
| return; | ||
| } |
There was a problem hiding this comment.
The onMouseDown handler should verify that the primary mouse button (left-click) was used before initiating a resize operation. This prevents accidental resizing when using other mouse buttons.
| onMouseDown(e) { | |
| if (!e.target.classList.contains('resizable-panel-handle')) { | |
| return; | |
| } | |
| onMouseDown(e) { | |
| if (e.button !== 0 || !e.target.classList.contains('resizable-panel-handle')) { | |
| return; | |
| } |
| onMouseMove(e) { | ||
| if (!this.isResizing) return; | ||
|
|
||
| const delta = e.clientX - this.startX; | ||
| const adjustment = delta / window.innerWidth; // Convert pixels to percentage-like ratio | ||
|
|
||
| let newWidths = { ...this.startWidths }; | ||
|
|
||
| if (this.currentResizeTarget === 'sidebar') { | ||
| // Resizing left sidebar | ||
| const sidebarPercent = (this.startWidths.sidebar * 100) / 12; // Convert col units to percentage | ||
| const mainPercent = (this.startWidths.main * 100) / 12; | ||
|
|
||
| const newSidebarPercent = sidebarPercent + (adjustment * 100); | ||
| const newMainPercent = mainPercent - (adjustment * 100); | ||
|
|
||
| // Constrain widths: min 1 col, max 5 cols for sidebar; min 4 cols for main | ||
| if (newSidebarPercent >= 8.33 && newSidebarPercent <= 41.66 && newMainPercent >= 33.33) { | ||
| newWidths.sidebar = Math.round((newSidebarPercent / 100) * 12); | ||
| newWidths.main = Math.round((newMainPercent / 100) * 12); | ||
| } | ||
| } else if (this.currentResizeTarget === 'toc') { | ||
| // Resizing right TOC panel | ||
| const tocPercent = (this.startWidths.toc * 100) / 12; | ||
| const mainPercent = (this.startWidths.main * 100) / 12; | ||
|
|
||
| const newTocPercent = tocPercent - (adjustment * 100); | ||
| const newMainPercent = mainPercent + (adjustment * 100); | ||
|
|
||
| // Constrain widths: min 1 col, max 5 cols for toc; min 4 cols for main | ||
| if (newTocPercent >= 8.33 && newTocPercent <= 41.66 && newMainPercent >= 33.33) { | ||
| newWidths.toc = Math.round((newTocPercent / 100) * 12); | ||
| newWidths.main = Math.round((newMainPercent / 100) * 12); | ||
| } | ||
| } | ||
|
|
||
| this.applyWidths(newWidths); | ||
| } |
There was a problem hiding this comment.
The onMouseMove function calls applyWidths on every mouse movement. Since applyWidths performs DOM manipulations (removing and adding classes via regex), this can lead to performance overhead. You should check if the calculated column widths have actually changed (due to the Math.round logic) before calling applyWidths.
| if (!this.isResizing) return; | ||
|
|
||
| const delta = e.clientX - this.startX; | ||
| const adjustment = delta / window.innerWidth; // Convert pixels to percentage-like ratio |
There was a problem hiding this comment.
Using window.innerWidth to calculate the resize adjustment can be inaccurate if the layout has a maximum width or side margins (common in Bootstrap containers). Using the offset width of the parent row (this.row.offsetWidth) provides a more accurate ratio relative to the grid system.
| const adjustment = delta / window.innerWidth; // Convert pixels to percentage-like ratio | |
| const adjustment = delta / this.row.offsetWidth; // Convert pixels to percentage-like ratio |
| removeBootstrapColClasses(element) { | ||
| const classes = element.className.split(' ').filter(c => !c.match(/col-xl-\d+/)); | ||
| element.className = classes.join(' ').trim(); | ||
| } |
There was a problem hiding this comment.
Directly manipulating element.className by splitting and joining strings is brittle and can accidentally remove or malform other classes. Using element.classList is the modern and safer approach for managing CSS classes.
removeBootstrapColClasses(element) {
const toRemove = Array.from(element.classList).filter(c => c.startsWith('col-xl-'));
if (toRemove.length > 0) {
element.classList.remove(...toRemove);
}
}| .td-sidebar, | ||
| .td-sidebar-toc, | ||
| main[role="main"] { | ||
| transition: flex-basis 0.3s ease; |
There was a problem hiding this comment.
Bootstrap grid columns typically use the width property to define their size, while flex-basis is often set to auto. Transitioning flex-basis may not result in the desired animation when the column class changes. Transitioning width is generally more reliable for animating Bootstrap grid changes.
| transition: flex-basis 0.3s ease; | |
| transition: width 0.3s ease; |
|
Description
This PR fixes the excessive bottom glow effect in the Kanvas popup by refining the
box-shadowstyling.Changes Made
Fixes #1035
Notes for Reviewers
Signed commits