refactor(node-resizer): add keepAspectRatio to dependency array, cleanup drag handler
This commit is contained in:
@@ -103,14 +103,12 @@ function ResizeControl({
|
|||||||
} = startValues.current;
|
} = startValues.current;
|
||||||
|
|
||||||
const { x: prevX, y: prevY, width: prevWidth, height: prevHeight } = prevValues.current;
|
const { x: prevX, y: prevY, width: prevWidth, height: prevHeight } = prevValues.current;
|
||||||
|
|
||||||
const distX = Math.floor(enableX ? xSnapped - startX : 0);
|
const distX = Math.floor(enableX ? xSnapped - startX : 0);
|
||||||
const distY = Math.floor(enableY ? ySnapped - startY : 0);
|
const distY = Math.floor(enableY ? ySnapped - startY : 0);
|
||||||
|
|
||||||
let width = startWidth + (invertX ? -distX : distX);
|
let width = clamp(startWidth + (invertX ? -distX : distX), minWidth, maxWidth);
|
||||||
let height = startHeight + (invertY ? -distY : distY);
|
let height = clamp(startHeight + (invertY ? -distY : distY), minHeight, maxHeight);
|
||||||
|
|
||||||
width = clamp(width, minWidth, maxWidth);
|
|
||||||
height = clamp(height, minHeight, maxHeight);
|
|
||||||
|
|
||||||
if (keepAspectRatio) {
|
if (keepAspectRatio) {
|
||||||
const nextAspectRatio = width / height;
|
const nextAspectRatio = width / height;
|
||||||
@@ -207,7 +205,7 @@ function ResizeControl({
|
|||||||
return () => {
|
return () => {
|
||||||
selection.on('.drag', null);
|
selection.on('.drag', null);
|
||||||
};
|
};
|
||||||
}, [id, controlPosition, minWidth, minHeight, maxWidth, maxHeight, getPointerPosition]);
|
}, [id, controlPosition, minWidth, minHeight, maxWidth, maxHeight, keepAspectRatio, getPointerPosition]);
|
||||||
|
|
||||||
const positionClassNames = controlPosition.split('-');
|
const positionClassNames = controlPosition.split('-');
|
||||||
const colorStyleProp = variant === ResizeControlVariant.Line ? 'borderColor' : 'backgroundColor';
|
const colorStyleProp = variant === ResizeControlVariant.Line ? 'borderColor' : 'backgroundColor';
|
||||||
|
|||||||
Reference in New Issue
Block a user