Xzero UI
Pro library

Card stack

Review a deck one card at a time, with a throw and an undo.

$ pnpm dlx shadcn@4.23.0 add @xzero-ui/card-stack
Live · keyboard ready

When to use

When not to use

Installation

Register both Xzero UI namespaces in your project's components.json:

{
  "registries": {
    "@xzero-ui": "https://mcp.xzero.co.uk/r/{name}.json",
    "@xzero-ui-pro": "https://mcp.xzero.co.uk/r/pro/{name}.json"
  }
}
npx shadcn@4.23.0 add @xzero-ui/card-stack

Install xzero-foundation once, and import @/components/xzero/foundation.css in your app root. No Xzero token is used by this snapshot. For sample portraits, photos, fonts, or logos, download https://mcp.xzero.co.uk/install-assets.mjs and run node xzero-install-assets.mjs <receiving-project>.

Usage

import { CardStack } from "@/components/xzero/card-stack/card-stack";

const cities = [{ id: "lis", name: "Lisbon" }, { id: "osl", name: "Oslo" }, { id: "kyo", name: "Kyoto" }];

export function Shortlist() {
  return (
    <CardStack
      items={cities}
      getKey={city => city.id}
      getLabel={city => city.name}
      renderCard={city => <h3>{city.name}</h3>}
      labels={{ left: "Skip", right: "Shortlist" }}
      onDecide={(city, decision) => save(city.id, decision)}
    />
  );
}

API reference

CardStack

A deck reviewed one card at a time by swiping left or right, with buttons, undo, and reset.

PropTypeDefaultDescription
items (required)T[]–Cards in order.
getKey (required)(item: T) => string–Stable key per item.
getLabel (required)(item: T) => string–Short name for labels and announcements, such as "Lisbon".
renderCard (required)(item: T) => ReactNode–Card content.
onDecide(item: T, decision: "left" | "right") => void–Called when a card is swiped or decided by button or key.
onUndo(item: T, decision: "left" | "right") => void–Called when the last decision is undone.
onReset() => void–Called when all cards come back.
labels{ left: string; right: string }{ left: "Pass", right: "Keep" }Action names on the buttons and drag stamps.
outcomes{ left: string; right: string }–Past tense of each action for announcements, such as "skipped".
labelstring"Cards"Accessible name for the stack.
renderEmpty(reset: () => void) => ReactNode–Shown once every card is decided. Defaults to a Start over button.
classNamestring–Class for the root.

Keyboard interactions

KeysAction
ArrowLeft / ArrowRightDecides the top card left or right when the stack is focused.
Backspace / Cmd+Z / Ctrl+ZUndoes the last decision.

Accessibility

Motion

Responsive behavior

Performance

Notes for AI

Also in media

Guidance for AI tools

Card stack: Review a deck one card at a time, with a throw and an undo. Follow the declared prop types and do not invent props. Keep keyboard access, reduced motion support, and both light and dark themes intact when adapting it.

Full library index: https://ui.xzero.co.uk/llms.txt

Browse all components