stardust66 / react-longpressable

Long-press component for React, with pointer events.
MIT License
10 stars 6 forks source link

React LongPressable

npm

Long-press wrapper for React that uses pointer events. Supports normal clicks as well.

Pointer events are hardware agnostic, meaning that they can be triggered by a mouse, a pen/stylus, or touch. Read more here: https://developer.mozilla.org/en-US/docs/Web/API/Pointer_events

Install

npm install --save react-longpressable

Props

Example

import React from 'react';
import LongPressable from 'react-longpressable';

export default class Example extends React.PureComponent {

  onLongPress = (e) => {
    console.log('Long pressed.');
  }

  onShortPress = (e) => {
    console.log('Short pressed.');
  }

  render() {
    return (
      <LongPressable
        onShortPress={this.onShortPress}
        onLongPress={this.onLongPress}
        longPressTime={700}>
        <button>Press Me!</button>
      </LongPressable>
    );
  }

}