feat(ui): add resizable sidebar panels with persistence
- use-panel-resize hook: Drag-to-resize with localStorage persistence - ResizeHandle component: Visual drag handle with hover effects - UnifiedShell: Flexbox layout with resizable left/right panels - RightPanel: Removed internal width handling (now controlled by shell)
This commit is contained in:
parent
ebd3ffcbbe
commit
6250335dc8
4 changed files with 157 additions and 26 deletions
61
src/hooks/use-panel-resize.ts
Normal file
61
src/hooks/use-panel-resize.ts
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
import { useState, useEffect, useCallback } from 'react';
|
||||
|
||||
const LEFT_PANEL_KEY = 'bb.ui.leftPanelWidth';
|
||||
const RIGHT_PANEL_KEY = 'bb.ui.rightPanelWidth';
|
||||
|
||||
const DEFAULT_LEFT_WIDTH = 320;
|
||||
const DEFAULT_RIGHT_WIDTH = 332;
|
||||
|
||||
export const MIN_LEFT_WIDTH = 192;
|
||||
export const MIN_RIGHT_WIDTH = 256;
|
||||
|
||||
export function usePanelResize() {
|
||||
const [leftWidth, setLeftWidth] = useState(() => {
|
||||
if (typeof window === 'undefined') return DEFAULT_LEFT_WIDTH;
|
||||
const saved = localStorage.getItem(LEFT_PANEL_KEY);
|
||||
return saved ? parseInt(saved, 10) : DEFAULT_LEFT_WIDTH;
|
||||
});
|
||||
|
||||
const [rightWidth, setRightWidth] = useState(() => {
|
||||
if (typeof window === 'undefined') return DEFAULT_RIGHT_WIDTH;
|
||||
const saved = localStorage.getItem(RIGHT_PANEL_KEY);
|
||||
return saved ? parseInt(saved, 10) : DEFAULT_RIGHT_WIDTH;
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
localStorage.setItem(LEFT_PANEL_KEY, String(leftWidth));
|
||||
}, [leftWidth]);
|
||||
|
||||
useEffect(() => {
|
||||
localStorage.setItem(RIGHT_PANEL_KEY, String(rightWidth));
|
||||
}, [rightWidth]);
|
||||
|
||||
const clampLeftWidth = useCallback((width: number) => {
|
||||
const maxWidth = Math.floor(window.innerWidth * 0.30);
|
||||
return Math.max(MIN_LEFT_WIDTH, Math.min(width, maxWidth));
|
||||
}, []);
|
||||
|
||||
const clampRightWidth = useCallback((width: number) => {
|
||||
const maxWidth = Math.floor(window.innerWidth * 0.35);
|
||||
return Math.max(MIN_RIGHT_WIDTH, Math.min(width, maxWidth));
|
||||
}, []);
|
||||
|
||||
const handleLeftResize = useCallback((delta: number) => {
|
||||
setLeftWidth(prev => clampLeftWidth(prev + delta));
|
||||
}, [clampLeftWidth]);
|
||||
|
||||
const handleRightResize = useCallback((delta: number) => {
|
||||
setRightWidth(prev => clampRightWidth(prev + delta));
|
||||
}, [clampRightWidth]);
|
||||
|
||||
return {
|
||||
leftWidth,
|
||||
rightWidth,
|
||||
handleLeftResize,
|
||||
handleRightResize,
|
||||
clampLeftWidth,
|
||||
clampRightWidth,
|
||||
MIN_LEFT_WIDTH,
|
||||
MIN_RIGHT_WIDTH
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue