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

swipeable-react

v2.0.0

Published

React component to enable swiping in mobile browsers

Downloads

35

Readme

React component to enable swiping in mobile browsers

moubi Language grade: JavaScript moubi moubi moubi

What you could use it for

Live mobile demo!

Edit Swipeable product card

Install

yarn add swipeable-react

Usage

import Swipeable from "swipeable-react";
...

function YourOwnComponent(props) {
  return (
    <Swipeable
      onSwipeLeft={() => { console.log("swiped left"); }}
      onSwipeRight={() => { console.log("swiped right"); }}
      onSwipeUp={() => { console.log("swiped up"); }}
      onSwipeDown={() => { console.log("swiped down"); }}
    >
      {innerRef => (
        <div ref={innerRef}>
          I will detect swiping!
        </div>
      )}
    </Swipeable>
  );
}

Then it's up to you on how to react on these swiping events.

Basic example

Sliding on horizontal/vertical swipe

Live mobile demo!

Edit Swiping views

API

| Prop | Type | Default | Description | | ------------- | ------------- | -------- | ----------- | | children | function | | Function that passes the ref down to the DOM element which will get touch events attached to. | | minDistance | number | 20 | min distance in px between touchstart and touchend | | maxDistance | number | Infinity | max distance in px between touchstart and touchend | | timeout | number | 500 | the time in ms between touchstart and touchend | | onSwipeLeft | function | | handler for successful swipe left | | onSwipeRight | function | | handler for successful swipe right | | onSwipeUp | function | | handler for successful swipe up | | onSwipeDown | function | | handler for successful swipe down |

* All props are optional except the children.

Notes

  • Supports both vertical and horizontal swiping.
  • Uses touchstart, touchmove and touchend events
  • Multiple nested Swipeables are supported.

In the last scenario successful nested swipe will prevent triggering parent swipeables. That is done by calling stopPropagation() inside touchend handler.

Requirements ✅

Swipeable has been rewritten using React hooks ↩ as per v2.0.0.

In order to work properly any consumer project should have version of react >= 16.8.0 (when hooks were introduced officially).

If hooks are not an option try Swipeable v1.3.0 which is using classes and depends on react >= 15.5.0.

Development

The code is built on node v10.15.1. Set as default in .nvmrc for nvm users.

nvm use
yarn

Tests run in jest --watch mode:

yarn test

Deploying by:

yarn build

That will create a lib/ folder with index.js file containing transpiled code from the src/Swipeable.js component

Contributing

Contribution is always welcome in the form of new features, bug fixes, ideas or simply tweating about Swipeable. Check the relavant guides here.

Credits

Non-react swiped-events by John Doherty

Product card design by Virgil Pana

License

MIT License