Tracks the user's gesture on an element using the TinyGesture library.
npm i stimulus-use-tinygesture
yarn add stimulus-use-tinygesture
useTinyGesture(controller, (options = {}))
controller : a Stimulus Controller (usually 'this'
)
options :
Option | Description | Default value |
---|---|---|
element |
The element used to recognize user's gesture | The controller element |
tinygesture |
Constructor and Options | |
handlers |
Listening to Gesture Events |
import { Controller } from '@hotwired/stimulus'
import { useTinyGesture } from 'stimulus-use-tinygesture'
class TappableController extends Controller {
connect() {
useTinyGesture(this, {
element: this.element,
tinygesture: {
// threshold: (type, self) => ...
// velocityThreshold: 10,
// disregardVelocityThreshold: (type, self) => ...
// ...
},
handlers: {
// tap
// doubletap
// swipeleft
// swiperight
// ...
tap: [this.tapHandler]
}
})
}
tapHandler(event, gesture) {
console.log(event)
console.log(gesture)
}
}