Card stack
A deck you work through by flinging the top card left or right. It leans with your drag, the next card rises under it, a quick flick is enough, and undo brings the last one back.
npx shadcn@latest add @captain/card-stack#482 · 3 files
Fix checkout race in the webhook handler
Orders were written before Stripe confirmed payment, so one CI run in eight read a pending row.
- api/stripe/webhook.ts
- lib/orders.ts
- e2e/checkout.spec.ts
+38 −12
Builder214 tests passed
Card stack is a Pro component
The demo and the docs are free. The source comes with Pro, through this page, the shadcn CLI and the MCP.
Usage
import { CardStack } from "@/components/ui/card-stack"
<CardStack
label="Changes waiting for review"
items={queue}
getKey={(c) => c.id}
labels={{ left: "Send back", right: "Merge" }}
onSwipe={(c, dir) => (dir === "right" ? merge(c) : sendBack(c))}
renderCard={(c) => <ChangeCard change={c} />}
/>Props
| Prop | Type | Default | What it does |
|---|---|---|---|
| items | T[] | The deck, top card first. | |
| getKey | (item: T) => string | A stable key for each card. | |
| renderCard | (item: T) => ReactNode | The card face. Give it its own surface; the stack adds the motion. | |
| onSwipe | (item: T, dir: "left" | "right") => void | Called as soon as a card is sent, by drag, button or key. | |
| onUndo | (item: T, dir: "left" | "right") => void | Called when the last card comes back. | |
| labels | { left: string; right: string } | { left: "Skip", right: "Keep" } | Used on the buttons, the stamp that appears as you drag, and the announcement. |
| label | string | Names the stack for screen readers. | |
| empty | ReactNode | Shown when the deck is finished. |
Keyboard
- →
- Send right
- ←
- Send left
- Backspace / ⌘Z
- Undo
Accessibility
- The stack is one focusable group; arrows send the top card and Backspace undoes.
- Buttons below do everything the drag does, so the gesture is never required.
- A status region says what happened and how many cards are left. Cards under the top one are inert.
- Reduced motion keeps the drag, drops the lean and turns the fling into a short slide.