@@ -157,6 +157,7 @@ export interface Props {
157157  enableUserSelectHack ?: boolean ; 
158158  allowAnyClick ?: boolean ; 
159159  scale ?: number ; 
160+   resizeSymmetry ?: "none"  |  "horizontal"  |  "vertical"  |  "central" 
160161  [ key : string ] : any ; 
161162} 
162163
@@ -488,21 +489,64 @@ export class Rnd extends React.PureComponent<Props, State> {
488489  )  { 
489490    // INFO: Apply x and y position adjustments caused by resizing to draggable 
490491    const  newPos  =  {  x : this . originalPosition . x ,  y : this . originalPosition . y  } ; 
491-     const  left  =  - delta . width ; 
492-     const  top  =  - delta . height ; 
493-     const  directions : ResizeDirection [ ]  =  [ "top" ,  "left" ,  "topLeft" ,  "bottomLeft" ,  "topRight" ] ; 
494- 
495-     if  ( directions . includes ( direction ) )  { 
496-       if  ( direction  ===  "bottomLeft" )  { 
497-         newPos . x  +=  left ; 
498-       }  else  if  ( direction  ===  "topRight" )  { 
499-         newPos . y  +=  top ; 
500-       }  else  { 
492+     if  ( ! this . props . resizeSymmetry  ||  this . props . resizeSymmetry  ==  "none" ) 
493+     { 
494+       const  left  =  - delta . width ; 
495+       const  top  =  - delta . height ; 
496+       const  directions : ResizeDirection [ ]  =  [ "top" ,  "left" ,  "topLeft" ,  "bottomLeft" ,  "topRight" ] ; 
497+       if  ( directions . includes ( direction ) )  { 
498+         if  ( direction  ===  "bottomLeft" )  { 
499+           newPos . x  +=  left ; 
500+         }  else  if  ( direction  ===  "topRight" )  { 
501+           newPos . y  +=  top ; 
502+         }  else  { 
503+           newPos . x  +=  left ; 
504+           newPos . y  +=  top ; 
505+         } 
506+       } 
507+     } 
508+     else  if  ( ! this . props . resizeSymmetry  ||  this . props . resizeSymmetry  ==  "vertical" ) 
509+     { 
510+       const  left  =  - delta . width  /  2 ; 
511+       const  top  =  - delta . height ; 
512+       const  directions : ResizeDirection [ ]  =  [ "top" ,  "left" ,  "right" ,  "topLeft" ,  "bottomLeft" ,  "topRight" ,  "bottomRight" ] ; 
513+       if  ( directions . includes ( direction ) )  { 
514+         if  ( direction  ===  "bottomLeft"  ||  direction  ===  "bottomRight" )  { 
515+           newPos . x  +=  left ; 
516+         }  else  if  ( direction  ===  "right" )  { 
517+           newPos . x  -=  - left ; 
518+           newPos . y  +=  top ; 
519+         }  else  { 
520+           newPos . x  +=  left ; 
521+           newPos . y  +=  top ; 
522+         } 
523+       } 
524+     } 
525+     else  if  ( ! this . props . resizeSymmetry  ||  this . props . resizeSymmetry  ==  "horizontal" ) 
526+     { 
527+       const  left  =  - delta . width ; 
528+       const  top  =  - delta . height  /  2 ; 
529+       const  directions : ResizeDirection [ ]  =  [ "left" ,  "bottom" ,  "top" ,  "bottomLeft" ,  "bottomRight" ,  "topLeft" ,   "topRight" ,  "bottomLeft" ] ; 
530+       if  ( directions . includes ( direction ) )  { 
531+         if  ( direction  ===  "bottomRight"  ||  direction  ===  "topRight" )  { 
532+           newPos . y  +=  top ; 
533+         }  else  { 
534+           newPos . x  +=  left ; 
535+           newPos . y  +=  top ; 
536+         } 
537+       } 
538+     } 
539+     else  if  ( ! this . props . resizeSymmetry  ||  this . props . resizeSymmetry  ==  "central" ) 
540+     { 
541+       const  left  =  - delta . width  /  2 ; 
542+       const  top  =  - delta . height  /  2 ; 
543+       const  directions : ResizeDirection [ ]  =  [ "top" ,  "left" ,  "right" ,  "bottom" ,  "topLeft" ,  "bottomLeft" ,  "topRight" ,  "bottomRight" ] ; 
544+       if  ( directions . includes ( direction ) )  { 
501545        newPos . x  +=  left ; 
502546        newPos . y  +=  top ; 
503547      } 
504548    } 
505- 
549+      
506550    const  draggableState  =  this . draggable . state  as  unknown  as  {  x : number ;  y : number  } ; 
507551    if  ( newPos . x  !==  draggableState . x  ||  newPos . y  !==  draggableState . y )  { 
508552      flushSync ( ( )  =>  { 
@@ -623,6 +667,13 @@ export class Rnd extends React.PureComponent<Props, State> {
623667    // INFO: Make uncontorolled component when resizing to control position by setPostion. 
624668    const  pos  =  this . state . resizing  ? undefined  : draggablePosition ; 
625669    const  dragAxisOrUndefined  =  this . state . resizing  ? "both"  : dragAxis ; 
670+     let  resizeRatio :number  |  [ number ,  number ]  |  undefined  =  [ 1 ,  1 ] ; 
671+     if  ( this . props . resizeSymmetry  ==  "vertical" ) 
672+       resizeRatio  =  [ 2 ,  1 ] ; 
673+     else  if  ( this . props . resizeSymmetry  ==  "horizontal" ) 
674+       resizeRatio  =  [ 1 ,  2 ] ; 
675+     else  if  ( this . props . resizeSymmetry  ==  "central" ) 
676+       resizeRatio  =  [ 2 ,  2 ] ; 
626677
627678    return  ( 
628679      < Draggable 
@@ -677,6 +728,7 @@ export class Rnd extends React.PureComponent<Props, State> {
677728          handleClasses = { resizeHandleClasses } 
678729          handleComponent = { resizeHandleComponent } 
679730          scale = { this . props . scale } 
731+           resizeRatio = { resizeRatio } 
680732        > 
681733          { children } 
682734        </ Resizable > 
0 commit comments