GithubHelp home page GithubHelp logo

web5design / react-tappable Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jedwatson/react-tappable

0.0 2.0 0.0 394 KB

Tappable component for React

License: MIT License

CSS 0.38% JavaScript 99.62%

react-tappable's Introduction

React-Tappable

Tappable component for React. Abstracts touch events to implement onTap and onPress.

The events mimic their native equivalents as closely as possible:

  • the baseClass (default: Tappable) has -active or -inactive added to it to enable pressed-state styling
  • the pressed state is visually cancelled if the touch moves too far away from the element, but resumes if the touch comes back again
  • when you start scrolling a parent element, the touch event is cancelled
  • if the onPress property is set, it will cancel the touch event after the press happens

When touch events are not supported, it will fall back to mouse events.

Demo & Examples

Live demo: jedwatson.github.io/react-tappable

To build the examples locally, run:

npm install
gulp dev

Then open localhost:8000 in a browser.

Installation

The easiest way to use React-tappable is to install it from NPM and include it in your own React build process (using Browserify, etc).

You can also use the standalone build by including dist/react-tappable.js in your page. If you use this, make sure you have already included React, and it is available as a global variable.

npm install react-tappable --save

Usage

React-tappable generates a React component (defaults to <span>) and binds touch events to it.

To disable default event handling (e.g. scrolling) set the preventDefault prop.

var Tappable = require('react-tappable');

<Tappable onTap={this.handleTapEvent}>Tap me</Tappable>

Properties

  • component component to render, defaults to 'span'
  • className optional class name for the component
  • classBase base to use for the active/inactive classes
  • moveThreshold px to allow movement before cancelling a tap; defaults to 100
  • pressDelay ms delay before a press event is detected, defaults to 1000
  • pressMoveThreshold px to allow movement before ignoring long presses; defaults to 5
  • preventDefault (boolean) automatically call preventDefault on all events
  • stopPropagation (boolean) automatically call stopPropagation on all events

Special Events

These are the special events implemented by Tappable.

  • onTap fired when touchStart or mouseDown is followed by touchEnd or mouseUp within the moveThreshold
  • onPress fired when a touch is held for the specified ms

Native Events

The following native event handlers can also be specified.

  • onTouchStart
  • onTouchMove
  • onTouchEnd
  • onMouseDown
  • onMouseUp
  • onMouseMove
  • onMouseOut

Returning false from onTouchStart or onMouseDown handlers will prevent Tappable from handling the event.

react-tappable's People

Contributors

jedwatson avatar jossmac avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.