Swipe Deck

A card stack you fling left or right, with undo that throws it back.

Preview

"use client";

import { SwipeDeck, type SwipeDeckItem } from "@/components/motion/swipe-deck";

type Stay = SwipeDeckItem & {
  place: string;
  price: string;
  image: string;
  alt: string;
};

const stays: Stay[] = [
  {
    id: "lake-cabin",
    label: "Lake Cabin",
    place: "Lofoten, Norway",
    price: "$180 night",
    image:
      "https://images.unsplash.com/photo-1470770841072-f978cf4d019e?auto=format&fit=crop&w=720&h=960&q=80",
    alt: "A lakeside cabin beneath mountains, reflected in the water",
  },
  {
    id: "studio-loft",
    label: "Studio Loft",
    place: "Lisbon, Portugal",
    price: "$95 night",
    image:
      "https://images.unsplash.com/photo-1497366754035-f200968a6e72?auto=format&fit=crop&w=720&h=960&q=80",
    alt: "Bright open-plan studio with long desks and plants",
  },
  {
    id: "concrete-house",
    label: "Concrete House",
    place: "Valencia, Spain",
    price: "$240 night",
    image:
      "https://images.unsplash.com/photo-1511818966892-d7d671e672a2?auto=format&fit=crop&w=720&h=960&q=80",
    alt: "Sculptural architecture",
  },
  {
    id: "valley-retreat",
    label: "Valley Retreat",
    place: "Dolomites, Italy",
    price: "$160 night",
    image:
      "https://images.unsplash.com/photo-1500530855697-b586d89ba3ee?auto=format&fit=crop&w=720&h=960&q=80",
    alt: "Open landscape",
  },
];

export function SwipeDeckPreview() {
  return (
    <SwipeDeck
      items={stays}
      sound
      renderCard={(stay) => (
        <div className="relative size-full">
          <img
            src={stay.image}
            alt={stay.alt}
            draggable={false}
            className="size-full object-cover"
          />
          <div className="absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/70 to-transparent p-3 pt-10 text-white">
            <p className="font-semibold text-sm">{stay.label}</p>
            <p className="text-xs text-white/80">
              {stay.place} · {stay.price}
            </p>
          </div>
        </div>
      )}
    />
  );
}

Install

Add it with the shadcn CLI, or copy the source manually.

$ bunx --bun shadcn add @beui/swipe-deck

API Reference

items
T[]

Every card, top of the deck first. Swiped cards stay in the list and are skipped.

renderCard
(item: T) => ReactNode

The card's content. Fills the card frame.

value?
SwipeDeckDecision[]

Swipes made so far, oldest first, for controlled use.

defaultValue?
SwipeDeckDecision[]

Swipes already made when uncontrolled. Default: []

Default[]
onValueChange?
((value: SwipeDeckDecision[]) => void)

Called with every swipe made so far after a swipe or an undo.

onSwipe?
((item: T, direction: SwipeDirection) => void)

Called with the card and direction when a card is swiped away.

onUndo?
((item: T, direction: SwipeDirection) => void)

Called with the card and the direction it had left in when an undo brings it back.

threshold?
number

Drag distance that swipes a card away on release (px). A fast flick needs less. Default: 110

Default110
visible?
number

Cards drawn in the stack, the top card included. Default: 3

Default3
controls?
boolean

Show the pass, undo and like buttons under the deck. Default: true

Defaulttrue
leftIcon?
ReactNode

Icon for the pass button. Default: an X icon

rightIcon?
ReactNode

Icon for the like button. Default: a heart icon

empty?
ReactNode

Shown once every card is swiped. Default: the "No more cards" message

sound?
boolean

Play a whoosh on each swipe and a lift on undo. Default: false

Defaultfalse
aria-label?
string

Accessible name for the deck. Default: "Card deck"

labels?
Partial<{ label: string; card: string; left: string; right: string; undo: string; swipedLeft: string; swipedRight: string; restored: string; empty: string; }>

Override any built-in string.

className?
string

Classes merged onto the root element.

cardClassName?
string

Classes merged onto each card frame.

Keep in mind

Some components on this site are inspired by or recreated from existing work across the web. I'm not here to take credit; just to learn, experiment, and sometimes push things a bit further. If something looks familiar and I forgot to mention you, reach out and I'll fix that right away.

Updated