{"bugs":{"url":"https://github.com/react-spring/react-use-gesture/issues"},"dist":{"shasum":"d678dcc795708bedd349a8a86a5600ddadacbaa5","tarball":"https://registry.npmjs.org/react-use-gesture/-/react-use-gesture-7.0.0-alpha.11.tgz","fileCount":34,"integrity":"sha512-Cdw2DLmRFc5crtpR5baYjVc/21hsAPws8Dsr0CP1wvlZ9GCI9gxBQP/jmImJjrH4h4/5BKeYUE/Z0dugQ9FF2g==","signatures":[{"sig":"MEYCIQCEj+EN7XEUygmZ9C8kNbVM5WuxUCf8qszJi5T4xRWSSQIhAJg+xOHfWbYFFvg7dJYznAzXbpwlwyk9T4vvvcP3D0d5","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":296044,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdxewCCRA9TVsSAnZWagAAdZIP/3oqYYGIPThhHMvDSXNp\nweI366EHaHdJrOFeo7QZubKoYk5lNN/IpXVF6fCNwTW+FT32RmYgFzyuH8yz\n+mwoD6yEQBeE2U/53RZIdrdRKiSuNmryfPvTh9xiFK76Zdc2lPpzJPPhwwYB\n9qWBdqJMgBiNwEG7B1yL1kt2gEPnrkT9E8+pOcjG6yn+C+AsS9y+thvlGdnP\n9RyV8o7rDCbcK5XEDCBVPKRViFW38ZxBJ4YixleAg/YVmPkIIc4XDGicXsZp\ndZbwGyyMBrRQ1hzw5/QnKHQq6dMkPFEw/Tv4enU8/r7KK9XvNG56C9PUjszi\nN+F+tn0qLvDcuemi3x3hm7Ldsyxzjci8l3YAMq89mxv0+rVjjhz1xL2ZTRna\n2rTaL1LtDauBslLD6Eq5eOtbVCvsx+HnYCgUt+RSwEo2BnUOoFb++kn7tMmb\nX8dESzGTPSi6+KH0HUuyS1DGc5bvMx2qau79VIdM7WIyXB8sluD0Vh+2T6//\n5HIxTMd+jAbKNrvjai87NZ3MTFC9gyESHgorZ5HssjKstCy35a+brOCDlfhi\nL2uph9vzjF6FTkRN6dUgMQbAHVJemSm0K+fVwwHlxPw0k5kI9RGCBWNC3wwM\ns1wjkUCbOvVPfqOx86FqwLyUSVD2OMgZ2zLkUzFKMu/RFx/YxTIGV9/UR6N0\nq0pg\r\n=L2o7\r\n-----END PGP SIGNATURE-----\r\n"},"jest":{"setupFiles":["@testing-library/react/dont-cleanup-after-each"]},"main":"dist/index.js","name":"react-use-gesture","author":{"name":"Paul Henschel"},"module":"dist/react-use-gesture.esm.js","readme":"# react-use-gesture\n\n![npm (tag)](https://img.shields.io/npm/v/react-use-gesture/alpha) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/react-use-gesture/7.0.0-alpha.11) ![NPM](https://img.shields.io/npm/l/react-use-gesture.svg) ![Travis (.org) branch](https://img.shields.io/travis/react-spring/react-use-gesture/v7)\n\n\nReact-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.\n\nYou can use it stand-alone, but to make the most of it you should combine it with an animation library like [react-spring](https://github.com/react-spring/react-spring), though you can most certainly use any other.\n\n<p align=\"middle\">\n  <a href=\"https://codesandbox.io/s/draggable-list-vp020\"><img src=\"https://i.imgur.com/qLKJod3.gif\" width=\"400\"/></a>\n  <a href=\"https://codesandbox.io/s/cards-utgqg\"><img src=\"https://i.imgur.com/H6nXQEq.gif\" width=\"400\"/></a>\n  <a href=\"https://codesandbox.io/s/react-use-gesture-sheet-fg3w0\"><img src=\"https://i.imgur.com/THKPrmR.gif\" width=\"400\"/></a>\n  <a href=\"https://codesandbox.io/s/infinite-slideshow-fu8wc\"><img src=\"https://i.imgur.com/cuOfqST.gif\" width=\"400\"/></a>\n  <a href=\"https://codesandbox.io/s/viewpager-0km3o\"><img src=\"https://i.imgur.com/iwZOfT9.gif\" width=\"400\"/></a>\n  <a href=\"https://codesandbox.io/s/9o92o24wrr\"><img src=\"https://i.imgur.com/Walt1Ip.gif\" width=\"400\"/></a>\n</p>\n\n<p align=\"middle\"><i>The demos are real click them!</i></p>\n\n## Api\n\n### Simple example\n\n<p align=\"middle\">\n  <a href=\"https://codesandbox.io/s/react-use-gesture-simple-y7yk9\"><img src=\"https://i.imgur.com/AMzsEi3.gif\" width=\"400\"/></a>\n</p>\n\n```jsx\nimport { useSpring, animated } from 'react-spring'\nimport { useDrag } from 'react-use-gesture'\n\nfunction PullRelease() {\n  const [{ xy }, set] = useSpring(() => ({ x: 0, y: 0 }))\n\n  // 1. Define the gesture\n  const bind = useDrag(({ down, movement: [mx, my] }) => set({ x: down ? mx : 0, y: down ? y : 0 }))\n\n  return (\n    <animated.div\n      // 2. Bind it to a component\n      {...bind()}\n      style={{ x, y }} />\n```\n\nThe example above makes a `div` draggable so that it follows your mouse on drag, and returns to its initial position on release.\n\n➡️ [_Why using `react-spring` instead of `React.useState`_](#why-using-react-spring-instead-of-reactusestate)?\n\n### Available hooks\n\nReact-use-gesture exports several hooks that can handle different gestures.\n\n| Hook         | Description                                                                                                     |\n|--------------|-----------------------------------------------------------------------------------------------------------------|\n| `useDrag`    | Handles the drag gesture                                                                                        |\n| `useMove`    | Handles mouse move events (touch devices not supported)                                                         |\n| `useHover`   | Handles mouse over events (touch devices not supported)                                                         |\n| `useScroll`  | Handles scroll events                                                                                           |\n| `useWheel`   | Handles wheel events                                                                                            |\n| `usePinch`   | Handles pinch events                                                                                            |\n| `useGesture` | Handles multiple gestures in one hook ([read more here](#usegesture-hook-supporting-multiple-gestures-at-once)) |\n\n### Gesture event state\n\nEvery time a handler is called, it will get passed a gesture state that includes the source event and adds multiple attributes such as speed, previous value, and much mroe.\n\n#### useDrag, useScroll, useWheel, useHover event state\n\n```jsx\nconst bind = useDrag(({\n  event,      // * the source event\n              // * event.gesture indicates which gesture originated the event\n  xy,         // [x,y] position of the pointer or scroll value for useScroll or useWheel\n  previous,   // * previous xy\n  initial,    // * xy value when the gesture has started\n  delta,      // * delta between current and previous values (xy - previous)\n  movement,   // * last gesture offset (xy - initial)\n  offset,     // * offset since the first gesture (movement with book-keeping)\n  vxvy,       // [vx, vy] momentum / speed of the gesture\n  velocity,   // combined moment / speed of the gesture\n  distance,   // offset distance\n  direction,  // * [dirx, diry] direction per axis\n  time,       // * timestamp of the current gesture\n  first,      // * true when it's the first event\n  last,       // * true when it's the last event\n  active,     // * true when the gesture is active\n  memo,       // * stores the value returned by your handler during its previous run\n  cancel,     // * function you can call to interrupt relevant gestures (drag and pinch only)\n  canceled,   // * whether the gesture has been canceled (drag and pinch only)\n  down,       // * true when a mouse button or touch is down\n  buttons,    // * buttons pressed (see https://developer.mozilla.org/fr/docs/Web/API/MouseEvent/button)\n  touches     // * numbers of touches pressing the screen\n  shiftKey, altKey, ctrlKey, metaKey,    // * true when modifier keys are pressed\n  args        // * arguments you passed to bind\n}) => {\n    /* gesture logic */\n  }\n)\n```\n\n➡️ [_How do I use `memo`?_](#how-do-i-use-memo)\n\n#### usePinch event state\n\nPinch is about scaling and rotating, therefore the keys `xy` and `vxvy` are renamed `da` (for distance and angle) and `vdva` respectively.\n\n```jsx\nconst bind = usePinch(({\n  da,         // [d,a] absolute distance and angle of the two pointers\n  vdva,       // momentum / speed of the distance and rotation\n  origin      // coordinates of the center between the two touch event\n}) => {\n  /* gesture logic */\n  }\n)\n```\n\n### Gesture options\n\nYou can pass a an object as an optional second argument to `use[Gesture]` hooks to customize their behavior.\n\n```jsx\nconst bind = useScroll(handler, {\n  // lets you specify a dom node or ref you want to attach the gesture to\n  domTarget: undefined,\n  // the event config attribute lets you configure `passive` and `capture` options passed to event listeners\n  event: { passive: true, capture: false },\n  // uses PointerEvent handlers for compatible gestures (disabled by default)\n  dragDelay: false // you can set a delay in ms that will prevent drag from triggering if you just \"click\" on your element\n  pointerEvents: false,\n  // lets you specify which window element the gesture should use.\n  window: window,\n  // enables or disables gestures\n  enabled: true,\n  // enables or disables gestures individually (relevant for the useGesture hook)\n  drag: true,\n  pinch: true,\n  scroll: true,\n  wheel: true,\n  move: true\n})\n```\n\n➡️ [_How do I use `domTarget`_](#adding-gestures-to-dom-nodes)?\n\n➡️ _See this [thread](https://github.com/react-spring/react-use-gesture/pull/43#issue-262835054) for a relevant use case of `window`._\n\n## Advanced usage\n\n#### useGesture hook: supporting multiple gestures at once\n\nIf you want your component to support multiple gestures at once, it is preferred that you use the `useGesture` hook as below.\n\n```jsx\nconst bind = useGesture({\n  onDrag: state => {...},     // fires on drag\n  onPinch: state => {...},    // fires on pinch\n  onScroll: state => {...},   // fires on scroll\n  onHover: state => {...},    // fires on mouse enter, mouse leave\n  onMove: state => {...},     // fires on mouse move over the element\n  onWheel: state => {...}     // fires on mouse wheel over the element\n})\n```\n\n#### on[Gesture]Start and on[Gesture]End handlers\n\nDrag, pinch, move, scroll and wheel gestures also have two additional handlers that let you perform actions when they start or end. For example, `onScrollEnd` fires when the user finished scrolling.\n\n> **Note #1:** `on[Gesture]Start` and `on[Gesture]End` methods are provided as a commodity. `on[Gesture]` handlers also receive `first` and `last` properties that indicate if the event fired is the first (i.e. gesture has started) or the last one (i.e. gesture has ended).\n\n```jsx\n// this:\nuseGesture({ onDragStart: doStuffOnStart, onDragEnd:doStuffOnEnd })\n\n// is equivalent to this:\nuseDrag(({first, last}) {\n  if (first) { /* do stuff on drag start */ }\n  if (last) { /* do stuff on drag end */ }\n})\n```\n\n#### Adding gestures to dom nodes\n\nReact-use-gesture also supports adding handlers to dom nodes directly (or the `window` or `document` objects). In that case, you shouldn't spread the `bind()` object returned by `use[Gesture]` hooks as a prop, but use the `React.useEffect` hook as below.\n\n```jsx\n// this will add a scroll listener to the window\nconst bind = useScroll(state => doStuff, { domTarget: window })\nReact.useEffect(bind, [bind])\n```\n\nYou can also directly pass a ref to `domTarget`:\n\n```jsx\nconst myRef = React.useRef(null)\n// this will add a scroll listener the div\nconst bind = useScroll(state => doStuff, { domTarget: myRef })\nReact.useEffect(bind, [bind])\n/*...*/\nreturn <div ref={myRef} />\n```\n\n> _Note that using `useEffect` will also take care of removing event listeners when the component is unmounted._\n\n#### How do I use memo?\n\n<p align=\"middle\">\n  <a href=\"https://codesandbox.io/s/memo-rocket-29nih\"><img src=\"https://i.imgur.com/BnZtmxE.gif\" width=\"400\"/></a>\n</p>\n\nThis demo reads out further data like velocity and direction to calculate decay. `memo` in this case is a simple storage that picks up whatever value you (optionally) return inside the event handler. It's valid as long as the gesture is active. Without this you would need to store the initial `pos` value somewhere else and conditionally update it when the gesture begins.\n\n```jsx\nconst [{ pos }, set] = useSpring(() => ({ pos: [0, 0] }))\nconst bind = useDrag(({ active, movement, velocity, direction, memo = pos.getValue() }) => {\n  set({\n    pos: addV(movement, memo),\n    immediate: active,\n    config: { velocity: scale(direction, velocity), decay: true },\n  })\n  return memo\n})\nreturn <animated.div {...bind()} style={{ transform: pos.to((x, y) => `translate3d(${x}px,${y}px,0)`) }} />\n```\n\n#### Using PointerEvents\n\nYou can set gestures to use [PointerEvent](https://developer.mozilla.org/fr/docs/Web/API/PointerEvent) instead of traditional mouse or touch events. It might be useful if you use [React-three-fiber](https://github.com/react-spring/react-three-fiber). Note that only drag, move and hover gestures currently support this option.\n\n```jsx\nconst bind = useDrag(fn, { pointerEvents: true })\n```\n\n### Other examples\n\n- [Locking Axis](https://codesandbox.io/s/25n4m933j)\n- [Boundaries](https://codesandbox.io/s/r7xnzk4x0o)\n- [Swipe](https://codesandbox.io/s/crimson-dawn-pzf9t)\n\n### Utilities\n\nReact-use-gesture also exports two methods that add or substract vectors formed as arrays. They might be handy in the case you need to manipulate positions.\n\n```jsx\nimport { addV, subV } from 'react-use-gesture'\n\nconst sum = addV([10, 10], [5, 5]) // => [15, 15]\nconst sub = subV([10, 10], [5, 5]) // => [5, 5]\n```\n\n## Frequently Asked Questions\n\n#### Why using `react-spring` instead of `React.useState`?\n\nSimply because setting state in the gesture handler would re-render the component on each gesture frame, which isn't always good for performance. `react-spring` lets us animate components without triggering renders. You could still use `useState` if you'd like though!\n\n#### ️What are the differences between using `use[Gesture]` hooks and adding listeners manually?\n\nNot a lot! Essentially these `use[Gesture]` hooks simplify the implementation of the drag and pinch gestures, calculate kinematics values you wouldn't get out of the box from the listeners, and debounce move, scroll and wheel events to let you know when they end.\n\n#### Why `onMove` when `onDrag` already exists?\n\n`onDrag` only fires while you touch or press the element. You just need to hover your mouse above the element to trigger `onMove`.\n\n#### Why `onWheel` and `onScroll`?\n\nScrolling and wheeling are structurally different events although they produce similar results (i.e. scrolling a page). First of all, `wheel` is a mouse-only event. Then, for `onScroll` to be fired, the element you're scrolling needs to actually scroll, therefore have content overflowing, while you just need to wheel over an element to trigger `onWheel`. If you use [react-three-fiber](https://github.com/drcmda/react-three-fiber), `onWheel` might prove useful to simulate scroll on canvas elements.\n\n#### Accessing source event triggers a warning in the console!\n\nYou're probably trying to access an event in `onScroll`, `onMove` or `onWheel` handlers. The last event is debounced, and therefore not accessible asynchronously because of how React pools events. A possible solution would be to make sure the event is not part of the last state update:\n\n```jsx\nuseScroll(({ event, last }) => {\n  !last && event.preventDefault() // <-- event will not be accessed in the last event\n})\n```\n\n#### Why do I need to return `memo`?\n\nAs you've seen in some examples, whenever `memo` is used, it is imperatively returned in the handler function. Essentially `memo` is a gesture state attribute that is undefined when the gesture starts, but then takes the return value of the handler function.\n\nIn many use cases, we want `memo` to hold the original value of our element position when the gesture starts so that it becomes our point of reference when adding the gesture `movement`. So we set `memo` to the value of our position when `memo` is undefined, which is in fact when the gesture starts. Usually it looks like so:\n\n```jsx\nconst [{ x }, set] = useSpring(() => ({ x: 0 }))\nconst bind = useDrag(({ movement: [mx], memo = x.getValue() }) => {\n  set({ x: ox + memo })\n  return memo\n})\n```\n\nIf we don’t return `memo`, then `memo` will remain undefined and in the next drag frame `memo` will take again the value of x, which will have updated in the meantime (therefore not being the point of reference when the gesture starts anymore).\n\nIt may sound silly but returning `memo` makes sure that we continue holding a reference to the initial value of `memo`, ie the original value of x when the gesture started.\n\n#### Why is drag being triggered when I just click on an element?\n\nThis is typically a-feature-not-a-bug situation 🙃 Drag is triggered as soon as you mouse down on your component, which means it will be triggered when you \"just\" briefly click on it. However, there is an option to not trigger the drag before a certain delay, using the config option `dragDelay`.\n\n```jsx\n// using the default delay\nconst bind = useDrag(() => {\n  console.log(`Won't show if you hold your mouse less than 180ms`)\n}, { dragDelay: true })\n\n// using a custom delay\nconst bind = useDrag(() => {\n  console.log(`Won't show if you hold your mouse less than 1000ms`)\n}, { dragDelay: 1000 })\n```\n\n#### Why am I getting warnings from `preventDefault()` after I pass `{ passive: false }`\n\nThe basic use of `<Component {...bind()) />` passes the task of attaching listeners to React. React does not [(yet)](https://github.com/facebook/react/issues/6436) support binding passive listeners via props. To have `useGesture` attach the listeners, you must also [use a domTarget](#adding-gestures-to-dom-nodes). This is only required if you plan to `preventDefault` or cancel the event.\n","gitHead":"59efa1a52dc2168819147b741a8f4a85092f063f","license":"MIT","scripts":{"lint":"tsdx lint","test":"tsdx test --env=jsdom","build":"tsdx build","start":"tsdx watch","prepare":"yarn build","test:watch":"tsdx test --env=jsdom --watchAll"},"typings":"dist/index.d.ts","_npmUser":{"name":"dbismut","email":"david.bismut@gmail.com"},"homepage":"https://github.com/react-spring/react-use-gesture#readme","keywords":["react","hook","gesture","mouse","trackpad","touch","drag","pinch","rotate","scale","zoom","scroll","wheel"],"prettier":{"semi":false,"printWidth":140,"singleQuote":true,"trailingComma":"es5"},"deprecated":"This package is no longer maintained. Please use @use-gesture/react instead","repository":{"url":"git+https://github.com/react-spring/react-use-gesture.git","type":"git"},"_npmVersion":"6.11.3","description":"React hook for receiving gestures","directories":{},"maintainers":[{"name":"drcmda","email":"drcmda@gmail.com"}],"_nodeVersion":"12.11.0","contributors":[{"url":"https://github.com/dbismut","name":"David Bismut"}],"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jest":"^24.8.0","json":"^9.0.6","tsdx":"^0.9.2","husky":"^3.0.5","react":"^16.9.0","tslib":"^1.10.0","prettier":"^1.18.2","react-dom":"^16.9.0","typescript":"^3.6.3","@types/jest":"^24.0.15","npm-run-all":"^4.1.5","@types/react":"^16.9.1","pretty-quick":"^1.11.1","@types/react-dom":"^16.9.0","@testing-library/react":"^9.1.4","@testing-library/jest-dom":"^4.1.0"},"peerDependencies":{"react":">= 16.8.0"},"_npmOperationalInternal":{"tmp":"tmp/react-use-gesture_7.0.0-alpha.11_1573252098307_0.5763159340077335","host":"s3://npm-registry-packages"},"_id":"react-use-gesture@7.0.0-alpha.11","version":"7.0.0-alpha.11"}