1- import { useCallback , useEffect , useRef , useState } from 'react' ;
1+ import { useEffect , useRef , useState } from 'react' ;
22import {
33 ImperativePanelHandle ,
44 Panel ,
55 PanelGroup ,
66 PanelResizeHandle ,
77} from 'react-resizable-panels' ;
8+ import { createGlobalStyle } from 'styled-components' ;
89
910import { useCunninghamTheme } from '@/cunningham' ;
1011
12+ interface PanelStyleProps {
13+ $isResizing : boolean ;
14+ }
15+
16+ const PanelStyle = createGlobalStyle < PanelStyleProps > `
17+ ${ ( { $isResizing } ) => $isResizing && `body * { transition: none !important; }` }
18+ ` ;
19+
20+ // Convert a target pixel width to a percentage of the current viewport width.
21+ // react-resizable-panels expects sizes in %, not px.
22+ const calculateDefaultSize = ( targetWidth : number ) => {
23+ const windowWidth = window . innerWidth ;
24+ return ( targetWidth / windowWidth ) * 100 ;
25+ } ;
26+
1127type ResizableLeftPanelProps = {
1228 leftPanel : React . ReactNode ;
1329 children : React . ReactNode ;
1430 minPanelSizePx ?: number ;
1531 maxPanelSizePx ?: number ;
16- onResizingChange ?: ( isResizing : boolean ) => void ;
1732} ;
1833
1934export const ResizableLeftPanel = ( {
2035 leftPanel,
2136 children,
2237 minPanelSizePx = 300 ,
2338 maxPanelSizePx = 450 ,
24- onResizingChange,
2539} : ResizableLeftPanelProps ) => {
40+ const [ isResizing , setIsResizing ] = useState ( false ) ;
2641 const { colorsTokens } = useCunninghamTheme ( ) ;
2742 const ref = useRef < ImperativePanelHandle > ( null ) ;
2843 const resizeTimeoutRef = useRef < number | undefined > ( undefined ) ;
2944
3045 const [ minPanelSize , setMinPanelSize ] = useState ( 0 ) ;
3146 const [ maxPanelSize , setMaxPanelSize ] = useState ( 0 ) ;
3247
33- // Convert a target pixel width to a percentage of the current viewport width.
34- // react-resizable-panels expects sizes in %, not px.
35- const calculateDefaultSize = useCallback ( ( targetWidth : number ) => {
36- const windowWidth = window . innerWidth ;
37- return ( targetWidth / windowWidth ) * 100 ;
38- } , [ ] ) ;
39-
4048 // Single resize listener that handles both panel size updates and transition disabling
4149 useEffect ( ( ) => {
4250 const handleResize = ( ) => {
@@ -49,12 +57,12 @@ export const ResizableLeftPanel = ({
4957 setMaxPanelSize ( max ) ;
5058
5159 // Temporarily disable transitions to avoid flicker
52- onResizingChange ?. ( true ) ;
60+ setIsResizing ( true ) ;
5361 if ( resizeTimeoutRef . current ) {
5462 clearTimeout ( resizeTimeoutRef . current ) ;
5563 }
5664 resizeTimeoutRef . current = window . setTimeout ( ( ) => {
57- onResizingChange ?. ( false ) ;
65+ setIsResizing ( false ) ;
5866 } , 150 ) ;
5967 } ;
6068
@@ -68,29 +76,35 @@ export const ResizableLeftPanel = ({
6876 clearTimeout ( resizeTimeoutRef . current ) ;
6977 }
7078 } ;
71- } , [ calculateDefaultSize , onResizingChange , minPanelSizePx , maxPanelSizePx ] ) ;
79+ } , [ minPanelSizePx , maxPanelSizePx ] ) ;
7280
7381 return (
74- < PanelGroup autoSaveId = "docs-left-panel-persistence" direction = "horizontal" >
75- < Panel
76- ref = { ref }
77- order = { 0 }
78- defaultSize = { minPanelSize }
79- minSize = { minPanelSize }
80- maxSize = { maxPanelSize }
82+ < >
83+ < PanelStyle $isResizing = { isResizing } />
84+ < PanelGroup
85+ autoSaveId = "docs-left-panel-persistence"
86+ direction = "horizontal"
8187 >
82- { leftPanel }
83- </ Panel >
84- < PanelResizeHandle
85- style = { {
86- borderRightWidth : '1px' ,
87- borderRightStyle : 'solid' ,
88- borderRightColor : colorsTokens [ 'greyscale-200' ] ,
89- width : '1px' ,
90- cursor : 'col-resize' ,
91- } }
92- />
93- < Panel order = { 1 } > { children } </ Panel >
94- </ PanelGroup >
88+ < Panel
89+ ref = { ref }
90+ order = { 0 }
91+ defaultSize = { minPanelSize }
92+ minSize = { minPanelSize }
93+ maxSize = { maxPanelSize }
94+ >
95+ { leftPanel }
96+ </ Panel >
97+ < PanelResizeHandle
98+ style = { {
99+ borderRightWidth : '1px' ,
100+ borderRightStyle : 'solid' ,
101+ borderRightColor : colorsTokens [ 'greyscale-200' ] ,
102+ width : '1px' ,
103+ cursor : 'col-resize' ,
104+ } }
105+ />
106+ < Panel order = { 1 } > { children } </ Panel >
107+ </ PanelGroup >
108+ </ >
95109 ) ;
96110} ;
0 commit comments