Components / Cards
Swipe Cards
A draggable deck of cards: fling the top card left or right to send it to the back.
Sage
Product · drag me left or right
River
Engineer · drag me left or right
Sky
Designer · drag me left or right
Installation
Requires React 18+ and Tailwind CSS.
- 1
Install dependencies
$ npm install motion - 2
Add the component
Copy the code from the Code tab above into
components/ui/swipe-cards.tsx. - 3
Use it
example.tsximport { SwipeCards } from "@/components/ui/swipe-cards"; const people = [ { name: "Sky", role: "Designer", from: "from-orange-400", to: "to-rose-500" }, { name: "River", role: "Engineer", from: "from-cyan-400", to: "to-blue-600" }, { name: "Sage", role: "Product", from: "from-lime-400", to: "to-emerald-600" }, { name: "Nova", role: "Founder", from: "from-fuchsia-400", to: "to-purple-600" }, ]; export default function SwipeCardsDemo() { return ( <SwipeCards cards={people.map((p) => ({ id: p.name, content: ( <div className="flex h-full flex-col"> <div className={`flex-1 bg-gradient-to-br ${p.from} ${p.to}`} /> <div className="p-4"> <p className="text-lg font-semibold text-zinc-900 dark:text-white">{p.name}</p> <p className="text-sm text-zinc-600 dark:text-zinc-400">{p.role} · drag me left or right</p> </div> </div> ), }))} /> ); }
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| cards | { id: string | number; content: ReactNode }[] | — | Cards in the deck. |
| onSwipe | (id, direction: "left" | "right") => void | — | Called after a card is swiped away. |
| className | string | "h-80 w-64" | Size of the deck. |