Skip to main content

Component <SwipeCards />

Props

PropsTypeMeaningPossible values
flickOnSwipebooleanWhether or not to let the element be flicked away off-screen after a swipetrue / false
preventSwipearrayAn array of directions for which to prevent swiping out of screenup / left / down / right
preventTouchbooleanAdd or remove preventDefault function for a cardtrue / false
swipeManualobjectConfig for card autoswipe{ swipe: boolean, power?: number, direction?: DirectionType }
onSwipefunctionCallback that will be executed when a swipe has been completed(dir: string) => void
onCardClickfunctionCallback that will be executed when card was clicked() => void
onCardLeftScreenfunctionCallback that will be executed when a card has left the screen(dir: string) => void



Demo

const SwipeCardsDemo = () => {
const [autoSwipe, setAutoSwipe] = useState([])

return (
<>
<button className="btn" type="button" onClick={() => setAutoSwipe(prev => [...prev, 'D'])}>
Swipe D
</button>
<button className="btn" type="button" onClick={() => setAutoSwipe(prev => [...prev, 'C'])}>
Swipe C
</button>
<button className="btn" type="button" onClick={() => setAutoSwipe(prev => [...prev, 'B'])}>
Swipe B
</button>
<button className="btn" type="button" onClick={() => setAutoSwipe(prev => [...prev, 'A'])}>
Swipe A
</button>

<div className="cards">
<SwipeCards
swipeManual={{ swipe: autoSwipe.includes('D') }}
onCardLeftScreen={() => setAutoSwipe(prev => prev.filter(current => current !== 'D'))}
>
d
</SwipeCards>
<SwipeCards
swipeManual={{ swipe: autoSwipe.includes('C') }}
preventTouch
onCardLeftScreen={() => setAutoSwipe(prev => prev.filter(current => current !== 'C'))}
>
c
</SwipeCards>
<SwipeCards
swipeManual={{ swipe: autoSwipe.includes('B') }}
onCardLeftScreen={() => setAutoSwipe(prev => prev.filter(current => current !== 'B'))}
>
b
</SwipeCards>
<SwipeCards
swipeManual={{ swipe: autoSwipe.includes('A') }}
preventTouch
onCardLeftScreen={() => setAutoSwipe(prev => prev.filter(current => current !== 'A'))}
>
a
</SwipeCards>
</div>
</>
)
}
d
c
b
a