@@ -11,6 +11,7 @@ export enum ResizeType {
1111
1212interface IProps {
1313 type : ResizeType ,
14+ adjustedSize : number ,
1415 width ?: number ,
1516 height ?: number ,
1617 minimumAdjust : number ,
@@ -19,8 +20,6 @@ interface IProps {
1920}
2021
2122export const Resizable : React . FC < IProps > = ( props ) => {
22- const [ adjustedSize , setAdjustedSize ] = React . useState ( 0 ) ;
23-
2423 const resize = ( originalX : number , originalY : number , x : number , y : number ) => {
2524 const adjustmentX =
2625 Math . min (
@@ -34,15 +33,14 @@ export const Resizable : React.FC<IProps> = (props) => {
3433 ) ;
3534 const adjustment = props . type === ResizeType . Left || props . type === ResizeType . Right ? adjustmentX : adjustmentY ;
3635
37- if ( adjustment !== adjustedSize ) {
38- setAdjustedSize ( adjustment ) ;
36+ if ( adjustment !== props . adjustedSize ) {
3937 props . onResize ( adjustment ) ;
4038 }
4139 }
4240
4341 const startTouchResize = ( e : React . TouchEvent < HTMLDivElement > ) => {
44- const originalTouchX = props . type === ResizeType . Left ? e . touches [ 0 ] . pageX + adjustedSize : e . touches [ 0 ] . pageX - adjustedSize ;
45- const originalTouchY = props . type === ResizeType . Top ? e . touches [ 0 ] . pageY + adjustedSize : e . touches [ 0 ] . pageY - adjustedSize ;
42+ const originalTouchX = props . type === ResizeType . Left ? e . touches [ 0 ] . pageX + props . adjustedSize : e . touches [ 0 ] . pageX - props . adjustedSize ;
43+ const originalTouchY = props . type === ResizeType . Top ? e . touches [ 0 ] . pageY + props . adjustedSize : e . touches [ 0 ] . pageY - props . adjustedSize ;
4644
4745 const touchResize = ( e : TouchEvent ) => resize ( originalTouchX , originalTouchY , e . touches [ 0 ] . pageX , e . touches [ 0 ] . pageY ) ;
4846 const debouncedTouchResize = debounce < typeof touchResize > ( touchResize , 10 ) ;
@@ -54,8 +52,8 @@ export const Resizable : React.FC<IProps> = (props) => {
5452 }
5553
5654 const startResize = ( e : React . MouseEvent < HTMLDivElement , MouseEvent > ) => {
57- const originalMouseX = props . type === ResizeType . Left ? e . pageX + adjustedSize : e . pageX - adjustedSize ;
58- const originalMouseY = props . type === ResizeType . Top ? e . pageY + adjustedSize : e . pageY - adjustedSize ;
55+ const originalMouseX = props . type === ResizeType . Left ? e . pageX + props . adjustedSize : e . pageX - props . adjustedSize ;
56+ const originalMouseY = props . type === ResizeType . Top ? e . pageY + props . adjustedSize : e . pageY - props . adjustedSize ;
5957
6058 const mouseResize = ( e : MouseEvent ) => resize ( originalMouseX , originalMouseY , e . pageX , e . pageY ) ;
6159 const debouncedMouseResize = debounce < typeof mouseResize > ( mouseResize , 10 ) ;
0 commit comments