Package Exports
- react-pointable
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (react-pointable) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
<Pointable />
A dependency free React component supporting declarative pointer event binding. Compatible with the official pointer events polyfill. Note that this component does nothing special to facilitate pointer capture.
Basic Usage
By default, a <Pointable />
component just renders a <div />
, passing through any props like className
, style
, non-pointer events, etc. What's special is that you can add pointer event props, react-style, and they will be properly bound. If a subsequent render adds or removes any pointer events, the internal listeners are updated accordingly.
When using <Pointable />
as an interactive element, this makes managing pointer events easy:
<Pointable onPointerDown={() => alert('Touched!')}>
Touch me
</Pointable>
All pointer events are supported:
onPointerMove
, onPointerDown
, onPointerUp
, onPointerOver
, onPointerOut
, onPointerEnter
, onPointerLeave
, onPointerCancel
Additional Props
<Pointable />
accepts two 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 propertytouch-action
also isn't supported. PEP therefore supports atouch-action
attribute, and this prop allows setting that in a declarative way. You can read more about the PEP attribute on its repo.
Example
Here's a CodePen using Pointable that allows toggling between pointer and mouse events, using the same components.
License
MIT