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-pointable

v1.1.3

Published

Declarative pointer event binding. Works well alongside PEP.

Downloads

4,611

Readme

<Pointable /> (obsolete as of React 16.4.0)

npm Travis tested with jest David

A dependency free React component supporting declarative pointer event binding.

Migrating to React 16.4+

As of React 16.4.0, pointer events are now supported out of the box! Custom DOM attributes are also supported, meaning React works well with PEP in browsers that don't natively support pointer events.

This component still works well pre React 16.4, but if you're upgrading it is simple to remove this component from your code. You can replace any instances of the <Pointable> component with a native DOM element.

// For example, this:

<Pointable onPointerDown={() => alert('Touched!')}>
  Touch me
</Pointable>

// becomes this:

<div onPointerDown={() => alert('Touched!')}>
  Touch me
</div>

Purpose

  • Allows using pointer events with React < 16.4.
  • Compatible with the official pointer events polyfill and its touch-action workaround.
  • Internal event listeners are kept up-to-date as pointer event handlers come and go.
  • Customizable wrapper element.

Note that this component does nothing special to facilitate pointer capture.

Installation

npm install --save react-pointable

Usage

By default, a <Pointable /> component renders a <div> and passes through any non-pointer event props like className, style, etc. Any pointer event props will just work as expected.

When using <Pointable /> for interactive elements, this makes managing pointer events easy:

import Pointable from 'react-pointable';

<Pointable onPointerDown={() => alert('Touched!')}>
  Touch me
</Pointable>

Composing is also easy:

const HairTrigger = ({ onTouch, disabled, children, ...otherProps }) => (
  <Pointable onPointerEnter={disabled ? null : onTouch} {...otherProps}>
    {children}
  </Pointable>
);

All pointer events are supported:

onPointerMove, onPointerDown, onPointerUp, onPointerOver, onPointerOut, onPointerEnter, onPointerLeave, onPointerCancel

Additional Props

<Pointable /> accepts special non-pointer event props:

  • tagName [string = 'div'] - If you don't want a <div /> to be rendered, you can pass any valid element type and it will be rendered instead.
  • touchAction [string = 'auto'] - When used with PEP in a browser that doesn't support pointer events, chances are the CSS property touch-action also isn't supported. PEP therefore supports a touch-action attribute, and this prop allows setting that in a fully declarative manner. You can read more about the PEP attribute on its repo.
  • elementRef [function] - Provides the generated element to a parent component. (optional)

Example

Here's a CodePen using Pointable that allows toggling between pointer and mouse events, using the same components.

TypeScript Typings

Typings for react-pointable are available on NPM.

If you're using a version of React < 16.4, run

npm install --save-dev @types/[email protected]

If you happen to be using React 16.4+ and can't yet remove this package for some reason, you can instead run

npm install --save-dev @types/react-pointable

To learn more, see the discussion in the DefinitelyTyped repo.

License

MIT