Captain UI

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
Pro

#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

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

PropTypeDefaultWhat it does
itemsT[]The deck, top card first.
getKey(item: T) => stringA stable key for each card.
renderCard(item: T) => ReactNodeThe card face. Give it its own surface; the stack adds the motion.
onSwipe(item: T, dir: "left" | "right") => voidCalled as soon as a card is sent, by drag, button or key.
onUndo(item: T, dir: "left" | "right") => voidCalled 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.
labelstringNames the stack for screen readers.
emptyReactNodeShown 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.