Card Deck

PreviousNext

A swipeable, physics-based card stack component featuring autoplay, touch gestures, and customizable motion

Coffee Cup
Mountain Lake
Nature Path

Installation

pnpm dlx shadcn@latest add https://deltacomponents.dev/r/card-deck.json

Usage

The CardDeck requires an array of image objects. For the best visual result, ensure the wrapping container has a defined height or aspect ratio suitable for cards.

import { CardDeck } from "@/components/ui/card-deck"
 
const cardData = [
  { src: "/ace-spades.jpg", alt: "Ace of Spades" },
  { src: "/queen-hearts.jpg", alt: "Queen of Hearts" },
  { src: "/king-diamonds.jpg", alt: "King of Diamonds" },
]
 
export default function GameBoard() {
  return (
    <div className="h-[400px] w-full max-w-sm">
      <CardDeck images={cardData} autoplay={true} />
    </div>
  )
}

Examples

Custom Card Styles

The component is agnostic to the image content. You can use it for trading cards, tarot decks, or game assets. This example demonstrates using raw asset images without default rounded corners.

Yu-Gi-Oh Card 1
Yu-Gi-Oh Card 2
Yu-Gi-Oh Card 3
Yu-Gi-Oh Card 4
Yu-Gi-Oh Card 5
Yu-Gi-Oh Card 6
Yu-Gi-Oh Card 7
Yu-Gi-Oh Card 8

Balatro Card Deck

An example implementing Balatro-style assets, demonstrating how the stack behaves with high-fidelity, texture-heavy images.

Balatro Ace Card
Balatro King Card
Balatro Queen Card
Balatro Joker Card
Balatro Four Card

Notes

Image Aspect Ratios

For a consistent "deck" feel, all images in the images array should share the same aspect ratio. Mixing portrait and landscape images in a single deck may result in inconsistent layout shifts during swiping.

Container Sizing

The CardDeck takes up the full width and height of its parent container. You must wrap it in a container with defined dimensions (e.g., h-96 w-64 or aspect-[2/3]) to prevent it from collapsing.

API Reference

PropTypeDefaultDescription
images{ src: string; alt: string }[]-Required. Array of image objects to render.
autoplaybooleanfalseAutomatically cycles through cards at a set interval.
showPaginationbooleanfalseDisplays pagination dots below the deck.
showNavigationbooleanfalseDisplays left/right navigation arrows.
spaceBetweennumber40The horizontal offset (in pixels) between cards in the stack.
enableInitialAnimationbooleantrueTriggers a “deal” animation when the component first mounts.
classNamestring-Additional CSS classes for the wrapper.