# Card Stack

> A Tinder-style stack of draggable cards that flick off left or right past a threshold.

Source: https://nyxui.com/components/card-stack

---
<ComponentPreview name="card-stack-demo" />

Card Stack is a Tinder-style React component that renders a deck of cards and lets the top one be grabbed and flicked left or right. Past the configurable drag threshold the card flies off and fires `onSwipe`; under it, the next card promotes to the top. Two more cards are mounted below in a scaled, offset stack to give a sense of depth without rendering the whole deck.

Useful for product tours, onboarding sequences, quote reels, and anywhere the "cycle through a small set" interaction beats a static carousel.

## Installation

<Tabs defaultValue="cli">

<TabsList>
  <TabsTrigger value="cli">CLI</TabsTrigger>
  <TabsTrigger value="manual">Manual</TabsTrigger>
</TabsList>

<TabsContent value="cli">

```bash
npx shadcn@latest add "https://nyxui.com/r/card-stack.json"
```

</TabsContent>

<TabsContent value="manual">

<Steps>

<Step>Copy and paste the following code into your project.</Step>

<ComponentSource name="card-stack" />

<Step>Update the import paths to match your project setup.</Step>

</Steps>

</TabsContent>

</Tabs>

## Usage

```tsx
import { CardStack } from "@/components/ui/card-stack";

const items = [
  { id: "1", title: "First" },
  { id: "2", title: "Second" },
  { id: "3", title: "Third" },
];

export function Example() {
  return (
    <div className="relative h-72 w-xs">
      <CardStack
        items={items}
        getKey={(item) => item.id}
        renderCard={(item) => (
          <div className="flex h-full items-center justify-center">
            <h3 className="text-lg font-medium">{item.title}</h3>
          </div>
        )}
        onSwipe={(item, direction) => console.log(item, direction)}
      />
    </div>
  );
}
```

## Props

| Prop            | Type                                | Default | Description                                            |
| --------------- | ----------------------------------- | ------- | ------------------------------------------------------ |
| `items`         | `T[]`                               | —       | Items to render as cards. First is on top.             |
| `renderCard`    | `(item, index) => ReactNode`        | —       | Renders each card's content.                           |
| `getKey`        | `(item, index) => string \| number` | index   | Stable key per item.                                   |
| `threshold`     | `number`                            | `120`   | Drag distance in pixels that triggers a swipe.         |
| `stackSize`     | `number`                            | `3`     | How many cards are mounted at once.                    |
| `stackOffset`   | `number`                            | `14`    | Pixel offset between stacked cards.                    |
| `stackScale`    | `number`                            | `0.06`  | Scale decrement per level back in the stack.           |
| `onSwipe`       | `(item, direction) => void`         | —       | Fires when a card is swiped off (`"left" \| "right"`). |
| `onEmpty`       | `() => void`                        | —       | Fires when the stack has no cards left.                |
| `className`     | `string`                            | —       | Extra classes on the stack wrapper.                    |
| `cardClassName` | `string`                            | —       | Extra classes on each card surface.                    |