GithubHelp home page GithubHelp logo

smashercosmo / react-use-gesture Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pmndrs/use-gesture

0.0 1.0 0.0 17.1 MB

👇Bread n butter utility for component-tied mouse/touch gestures in React

Home Page: https://use-gesture.netlify.app

License: MIT License

TypeScript 74.53% JavaScript 17.64% CSS 7.82%

react-use-gesture's Introduction

react-use-gesture

npm (tag) npm bundle size NPM Travis (.org) branch

React-use-gesture is a hook that lets you bind richer mouse and touch events to any component or view. With the data you receive, it becomes trivial to set up gestures, and often takes no more than a few lines of code.

You can use it stand-alone, but to make the most of it you should combine it with an animation library like react-spring, though you can most certainly use any other.

The demos are real click them!

Installation

#Yarn
yarn add react-use-gesture

#NPM
npm install react-use-gesture

Simple example

import { useSpring, animated } from 'react-spring'
import { useDrag } from 'react-use-gesture'

function PullRelease() {
  const [{ x, y }, set] = useSpring(() => ({ x: 0, y: 0 }))

  // Set the drag hook and define component movement based on gesture data
  const bind = useDrag(({ down, movement: [mx, my] }) => {
    set({ x: down ? mx : 0, y: down ? my : 0 })
  })

  // Bind it to a component
  return <animated.div {...bind()} style={{ x, y }} />

The example above makes a div draggable so that it follows your mouse on drag, and returns to its initial position on release.

Available hooks

React-use-gesture exports several hooks that can handle different gestures:

Hook Description
useDrag Handles the drag gesture
useMove Handles mouse move events
useHover Handles mouse enter and mouse leave events
useScroll Handles scroll events
useWheel Handles wheel events
usePinch Handles the pinch gesture
useGesture Handles multiple gestures in one hook

react-use-gesture's People

Contributors

0xflotus avatar andrewn avatar armandabric avatar bhollis avatar brumm avatar catamphetamine avatar chroth7 avatar dbismut avatar dependabot[bot] avatar drcmda avatar grifotv avatar janbaykara avatar janniks avatar jeremybarbet avatar knpwrs avatar lyyourc avatar mateeyow avatar matis-dk avatar mesoptier avatar mpolichette avatar orouz avatar raiskila avatar salguerooo avatar stipsan avatar thibautre avatar tim-soft avatar tony-g avatar zachasme avatar zhongyuanjia avatar zvictor avatar

Watchers

 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.