@@ -44,6 +44,28 @@ const HANDLER_OFFSET = 4;
4444// Extra inset added for resizable panels (to accommodate handler grab area)
4545const RESIZABLE_INSET_OFFSET = 2 ;
4646
47+ /**
48+ * Clamps a size value within min/max constraints.
49+ * Handles both number and string constraint values (only numbers are applied).
50+ */
51+ function clampPanelSize (
52+ value : number ,
53+ minSize ?: number | string ,
54+ maxSize ?: number | string ,
55+ ) : number {
56+ let result = value ;
57+
58+ if ( typeof maxSize === 'number' ) {
59+ result = Math . min ( maxSize , result ) ;
60+ }
61+
62+ if ( typeof minSize === 'number' ) {
63+ result = Math . max ( minSize , result ) ;
64+ }
65+
66+ return Math . max ( result , 0 ) ;
67+ }
68+
4769const PanelElement = tasty ( {
4870 as : 'div' ,
4971 qa : 'LayoutPanel' ,
@@ -386,28 +408,21 @@ function LayoutPanel(
386408 // Resize state
387409 const [ isDragging , setIsDragging ] = useState ( false ) ;
388410 const [ size , setSize ] = useState < number > ( ( ) => {
389- if ( typeof providedSize === 'number' ) return providedSize ;
390- if ( typeof defaultSize === 'number' ) return defaultSize ;
391- return 280 ;
411+ const initialSize =
412+ typeof providedSize === 'number'
413+ ? providedSize
414+ : typeof defaultSize === 'number'
415+ ? defaultSize
416+ : 280 ;
417+
418+ return clampPanelSize ( initialSize , minSize , maxSize ) ;
392419 } ) ;
393420
394421 const extractedStyles = extractStyles ( otherProps , CONTAINER_STYLES ) ;
395422
396423 // Clamp size to min/max constraints
397424 const clampSize = useCallback (
398- ( value : number ) => {
399- let result = value ;
400-
401- if ( typeof maxSize === 'number' ) {
402- result = Math . min ( maxSize , result ) ;
403- }
404-
405- if ( typeof minSize === 'number' ) {
406- result = Math . max ( minSize , result ) ;
407- }
408-
409- return Math . max ( result , 0 ) ;
410- } ,
425+ ( value : number ) => clampPanelSize ( value , minSize , maxSize ) ,
411426 [ minSize , maxSize ] ,
412427 ) ;
413428
0 commit comments