MCPcopy
hub / github.com/bokuweb/react-rnd / onResize

Method onResize

src/index.tsx:484–525  ·  view source on GitHub ↗
(
    e: MouseEvent | TouchEvent,
    direction: ResizeDirection,
    elementRef: HTMLElement,
    delta: { height: number; width: number },
  )

Source from the content-addressed store, hash-verified

482 }
483
484 onResize(
485 e: MouseEvent | TouchEvent,
486 direction: ResizeDirection,
487 elementRef: HTMLElement,
488 delta: { height: number; width: number },
489 ) {
490 // INFO: Apply x and y position adjustments caused by resizing to draggable
491 const newPos = { x: this.originalPosition.x, y: this.originalPosition.y };
492 const left = -delta.width;
493 const top = -delta.height;
494 const directions: ResizeDirection[] = ["top", "left", "topLeft", "bottomLeft", "topRight"];
495
496 if (directions.includes(direction)) {
497 if (direction === "bottomLeft") {
498 newPos.x += left;
499 } else if (direction === "topRight") {
500 newPos.y += top;
501 } else {
502 newPos.x += left;
503 newPos.y += top;
504 }
505 }
506
507 const draggableState = this.draggable.state as unknown as { x: number; y: number };
508 if (newPos.x !== draggableState.x || newPos.y !== draggableState.y) {
509 flushSync(() => {
510 this.draggable.setState(newPos);
511 });
512 }
513
514 this.updateOffsetFromParent();
515 const offset = this.offsetFromParent;
516 const x = this.getDraggablePosition().x + offset.left;
517 const y = this.getDraggablePosition().y + offset.top;
518
519 this.resizingPosition = { x, y };
520 if (!this.props.onResize) return;
521 this.props.onResize(e, direction, elementRef, delta, {
522 x,
523 y,
524 });
525 }
526
527 onResizeStop(
528 e: MouseEvent | TouchEvent,

Callers

nothing calls this directly

Calls 2

getDraggablePositionMethod · 0.95

Tested by

no test coverage detected