npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-handle

v1.0.2

Published

A simple, performant React hook for making draggable UIs.

Downloads

11

Readme

react-handle

A simple, performant React hook for making draggable UIs.

react-handle is a lightweight abstraction over the pointer events API. It won't actually move anything for you — instead, it handles the pointer event lifecycle. Use it as a small building block for creating graphics editors, games, timelines and more.

Example

import useHandle from "react-handle";

function CoolApp() {
  const handle = useHandle({
    onDrag(_, { distance }) {
      console.log(`Drag distance: ${distance.x}, ${distance.y}`);
    }
  });

  return <canvas {...handle} />;
}

Options

react-handle consists of one function: the useHandle hook. It takes an object of callbacks — all optional — and returns props to be spread into the element the user will be dragging.

onDragStart

function(event: PointerEvent, info: DragInfo) | optional

Called when the drag operation starts. Passed the pointer event and the DragInfo object.

onDrag

function(event: PointerEvent, info: DragInfo) | optional

If a drag operation is in progress, called repeatedly as the pointer is moved. Passed the pointer event and the DragInfo object.

onDragEnd

function(event: PointerEvent, info: DragInfo) | optional

Called when the drag operation ends. Passed the pointer event and the DragInfo object.

relativeTo

function(event: Element): Element | optional

If you'd like the DragInfo coordinates to be relative to an element other than the dragged one, return that element from this function. Passed the event target (the dragged element).

DragInfo

In addition to the pointer event, all drag callbacks are passed an object containing information about the drag operation.

Origin

{ x: number; y: number; }

The pointer coordinates when the drag operation began, relative to the top left corner of the element.

Current

{ x: number; y: number; }

The current pointer coordinates, relative to the top left corner of the element.

Distance

{ x: number; y: number; }

The difference between current and origin.