To make a custom stencil interactive, connect the onMove and onMoveEnd callbacks of DraggableElement or DraggableArea to the cropper's API.
Resizing with DraggableElement
DraggableElement provides an onMove callback with a shift object of type MoveDirections ({ left: number; top: number; }). This represents the pixel delta of the movement.
To resize, call cropper.resizeCoordinates. You can use the compensate: true option to allow the stencil to resize in other directions if it hits the cropper boundary.
Moving with DraggableArea
To move the stencil, call cropper.moveCoordinates(directions) where directions is a MoveDirections object.
To finalize the interaction, call cropper.resizeCoordinatesEnd or cropper.moveCoordinatesEnd in the onMoveEnd callback.
const onResize = (shift: MoveDirections) => {
// Example: resizing from center
cropper.resizeCoordinates('center', {
left: shift.left,
top: shift.left,
}, {
compensate: true,
});
};
const onMove = (directions: MoveDirections) => {
cropper.moveCoordinates(directions);
};