UNPKG

@wix/design-system

Version:

@wix/design-system

25 lines 879 B
import { useRef } from 'react'; export const useHorizontalSwipe = ({ onSwipe, threshold = 50, disabled = false, }) => { const touchStart = useRef({ x: 0, y: 0 }); const handleTouchStart = (event) => { if (disabled) return; const touch = event.touches[0]; touchStart.current = { x: touch.clientX, y: touch.clientY }; }; const handleTouchEnd = (event) => { if (disabled) return; const touch = event.changedTouches[0]; const deltaX = Math.abs(touch.clientX - touchStart.current.x); const deltaY = Math.abs(touch.clientY - touchStart.current.y); if (deltaX > deltaY && deltaX >= threshold) { onSwipe?.(); } }; return { onTouchStart: handleTouchStart, onTouchEnd: handleTouchEnd, }; }; //# sourceMappingURL=useHorizontalSwipe.js.map