Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/koca/vue-use-gesture
👇 Bread n butter utility for component-tied mouse/touch gestures in Vue
https://github.com/koca/vue-use-gesture
composable gesture hooks vue
Last synced: 26 days ago
JSON representation
👇 Bread n butter utility for component-tied mouse/touch gestures in Vue
- Host: GitHub
- URL: https://github.com/koca/vue-use-gesture
- Owner: koca
- License: mit
- Created: 2021-03-08T19:05:25.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-08-11T00:22:41.000Z (over 3 years ago)
- Last Synced: 2024-04-23T18:37:12.255Z (8 months ago)
- Topics: composable, gesture, hooks, vue
- Language: TypeScript
- Homepage: https://vue-use-gesture.netlify.app
- Size: 15.2 MB
- Stars: 152
- Watchers: 5
- Forks: 9
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-starred - koca/vue-use-gesture - 👇 Bread n butter utility for component-tied mouse/touch gestures in Vue (vue)
README
# Vue UseGesture
> WIP
Vue UseGesture 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 [vue-use-spring](https://github.com/posva/vue-use-spring), though you can most certainly use any other.
The demos are real (we'll add them to the codesandbox soon)
### Installation
```bash
#Yarn
yarn add vue-use-gesture#NPM
npm install vue-use-gesture
```### [Full documentation website](https://vue-use-gesture.netlify.com)
- [Available Hooks](https://vue-use-gesture.netlify.com/docs/hooks)
- [Gesture State](https://vue-use-gesture.netlify.com/docs/state)
- [Gesture Options](https://vue-use-gesture.netlify.com/docs/options)
- [Utilities](https://vue-use-gesture.netlify.com/docs/utilities)
- [FAQ](https://vue-use-gesture.netlify.com/docs/faq)### Simple example
```html
import { useDrag } from 'vue-use-gesture'
import { useSpring } from 'vue-use-spring'
import { defineComponent, computed } from 'vue'export default defineComponent({
setup() {
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 })
})const style = computed(() => ({ transform: `translate3d(${x.value}px,${y.value}px,0)`, touchAction: 'none' }))
return { bind, style }
},
})```
The example above makes a `div` draggable so that it follows your mouse on drag, and returns to its initial position on release.
**Make sure you always set [`touchAction`](https://developer.mozilla.org/en-US/docs/Web/CSS/touch-action) on a draggable element to prevent glitches with the browser native scrolling on touch devices**.
### Available hooks
`vue-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 |#### [More on the full documentation website...](https://vue-use-gesture.netlify.com)
## Thanks
> This library is a port of [React UseGesture](https://github.com/pmndrs/react-use-gesture). Thanks [Poimandres](https://twitter.com/pmndrs) 🙏
## License
MIT
[build-badge]: https://img.shields.io/circleci/project/github/koca/vue-use-gesture/master.svg?style=flat-square
[build]: https://circleci.com/gh/koca/vue-use-gesture
[downloads-badge]: https://img.shields.io/npm/dt/vue-use-gesture.svg?style=flat-square
[downloads]: https://npmjs.com/package/vue-use-gesture
[build-badge]: https://img.shields.io/npm/dm/vue-client-only.svg?style=flat
[license-badge]: https://img.shields.io/npm/l/vue-use-gesture.svg?style=flat-square
[license]: https://opensource.org/licenses/MIT
[version-badge]: https://img.shields.io/npm/v/vue-use-gesture.svg?style=flat-square
[package]: https://www.npmjs.com/package/vue-use-gesture
[bundle-size-badge]: https://img.shields.io/bundlephobia/minzip/[email protected]?style=flat-square
[bundle-size]: https://bundlephobia.com/result?p=vue-use-gesture
[covarage-badge]: https://img.shields.io/codecov/c/github/koca/vue-use-gesture?style=flat-square