0.0.6 • Published 1 year ago

use-micro-drag v0.0.6

Weekly downloads
-
License
-
Repository
github
Last release
1 year ago

use-micro-drag

An easy-to-use react hook to make any react element draggable.

import { useMicroDrag, DragCallbackState } from "use-micro-drag";

function Box() {
  const bindings = useMicroDrag<HTMLDivElement>(
    (dragState: DragCallbackState) => {
        //   use dragState here
        //   dragState.start => true, when user just pointed down on the element, else false after that
        //   dragState.end => true, when user releases the pointer, else false before that
        //   dragState.startX => x coordinate of the pointer when user pointed down
        //   dragState.startY => y coordinate of the pointer when user pointed down
        //   dragState.dx => dx movement in the horizontal direction wrt startX
        //   dragState.dy => dy movement in the vertical direction wrt startY
        //   dragState.movX => movement in the horizontal direction wrt last event
        //   dragState.movY => movement in the vertical direction wrt last event
        //   dragState.event => Synthetic React event, use this for preventDefault/stopPropagation
    }
  );

  return <div {...bindings} />;
}

Install

npm install use-micro-drag

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago