Skip to content

v1.0.10

Latest

Choose a tag to compare

@debabin debabin released this 13 Jul 08:07

Add new hook

This release introduces useDraggable, a hook that makes an element draggable via pointer events, reporting both an absolute position (for left/top) and a delta offset from the drag start (for transform: translate) to its lifecycle callbacks.

Features

  • useDraggable — added a hook that makes an element draggable, exposing snapshot, dragging, set, and watch, and accepting axis, enabled, initialValue, and onStart, onMove, onEnd callbacks, with the callbacks receiving position, delta, and the originating event.
  • useDraggable — the onStart callback can return false to cancel a drag before it begins, which lets consumers restrict dragging to a handle by inspecting the event target without any dedicated handle option.
  • useDraggable — added a set method to move the element programmatically, so its position can be driven from outside the hook, for example to snap it back to its origin.
  • useDraggable — the delta passed to callbacks is measured from the pointer position at drag start, so it always begins at zero on each new drag regardless of where the element was left previously.