framer-motion
Version:
A simple and powerful JavaScript animation library
47 lines (44 loc) • 1.53 kB
JavaScript
import { Feature, press } from 'motion-dom';
import { handleGestureEvent } from './hover.mjs';
function handlePressEvent(node, event, lifecycle, isRepeat) {
if (node.current instanceof HTMLButtonElement && node.current.disabled) {
return;
}
handleGestureEvent(node, event, "Tap", lifecycle, isRepeat);
}
class PressGesture extends Feature {
constructor() {
super(...arguments);
/**
* press() reads its options on each press, so this object is kept
* and updated in place when props change.
*/
this.options = {};
}
mount() {
const { current } = this.node;
if (!current)
return;
this.update();
this.unmount = press(current, (_element, startEvent) => {
handlePressEvent(this.node, startEvent, "Start");
return {
onComplete: (endEvent, { success }) => handlePressEvent(this.node, endEvent, success ? "" : "Cancel"),
onRepeat: () => handlePressEvent(this.node, startEvent, "", true),
};
}, this.options);
}
update() {
const { options, node } = this;
const { globalTapTarget, propagate, tap } = node.props;
for (const key in options)
delete options[key];
Object.assign(options, tap, {
useGlobalTarget: globalTapTarget,
stopPropagation: propagate?.tap === false,
});
}
unmount() { }
}
export { PressGesture };
//# sourceMappingURL=press.mjs.map