"use client" // Basic Swipeable Card - Free Version "use client" import * as React from "react" import { cn } from "../../lib/utils" export interface SwipeableCardProps extends React.HTMLAttributes { children: React.ReactNode onSwipeLeft?: () => void onSwipeRight?: () => void threshold?: number disabled?: boolean } export const SwipeableCard = React.forwardRef( ({ className, children, onSwipeLeft, onSwipeRight, threshold = 100, disabled = false, ...props }, ref) => { const [startX, setStartX] = React.useState(0) const [currentX, setCurrentX] = React.useState(0) const [isSwiping, setIsSwiping] = React.useState(false) const handleTouchStart = (e: React.TouchEvent) => { if (disabled) return setStartX(e.touches[0].clientX) setIsSwiping(true) } const handleTouchMove = (e: React.TouchEvent) => { if (disabled || !isSwiping) return setCurrentX(e.touches[0].clientX) } const handleTouchEnd = () => { if (disabled || !isSwiping) return const deltaX = currentX - startX if (Math.abs(deltaX) > threshold) { if (deltaX > 0 && onSwipeRight) { onSwipeRight() } else if (deltaX < 0 && onSwipeLeft) { onSwipeLeft() } } setIsSwiping(false) setCurrentX(0) setStartX(0) } return (
{children}
) } ) SwipeableCard.displayName = "SwipeableCard"