BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/ui-beats/card-stack

Card Stack

ui-beats/card-stack
FreeComponent

The CardStack component deals your content as a deck: drag the top card aside to throw it away, the cards behind rise a step, and the dismissed card loops around to the back.

Install it

npx shadcn@latest add https://uibeats.com/r/card-stack.json

Source

components/demo/card/card-stack.tsxuibeats.com/r/card-stack.json · first 6 KB
1"use client";
2
3import {
4 AnimatePresence,
5 motion,
6 useReducedMotion,
7 type PanInfo,
8} from "motion/react";
9import {
10 Children,
11 useCallback,
12 useEffect,
13 useRef,
14 useState,
15 type KeyboardEvent,
16 type ReactNode,
17} from "react";
18import { cn } from "@/lib/utils";
19
20interface CardStackProps {
21 /** One card per child. Each is given the stack's own card chrome. */
22 children: ReactNode;
23 /** How many cards are rendered, counting the one on top. */
24 visible?: number;
25 /** Vertical gap between each card and the one in front of it, in pixels. */
26 offset?: number;
27 /** How much smaller each card is than the one in front of it. */
28 scaleStep?: number;
29 /** Milliseconds between automatic advances. `0` turns autoplay off. */
30 autoplay?: number;
31 /** Distance, in pixels, a card must be dragged before it is dismissed. */
32 dismissAt?: number;
33 className?: string;
34}
35
36/**
37 * A deck of cards you can throw away: drag the top one aside and it flies off,
38 * the rest rise a step, and the dismissed card returns to the back of an
39 * endless loop.
40 *
41 * Only `visible` cards are ever mounted, so a hundred-card deck costs the same
42 * as a three-card one. Keys carry the lap number as well as the card index,
43 * which is what lets a card leave and come back: without it a short deck would
44 * find the dismissed card already in the window and shrink it into the stack
45 * instead of dealing it away.
46 */
47export function CardStack({
48 children,
49 visible = 3,
50 offset = 14,
51 scaleStep = 0.05,
52 autoplay = 0,
53 dismissAt = 90,
54 className = "",
55}: CardStackProps) {
56 const cards = Children.toArray(children);
57 const prefersReducedMotion = useReducedMotion();
58
59 const [index, setIndex] = useState(0);
60 const [direction, setDirection] = useState(1);
61 const [paused, setPaused] = useState(false);
62 const dragging = useRef(false);
63
64 const advance = useCallback(
65 (towards: 1 | -1 = 1) => {
66 if (cards.length === 0) return;
67 setDirection(towards);
68 setIndex((current) => (current + 1) % cards.length);
69 },
70 [cards.length],
71 );
72
73 /*
74 * Autoplay pauses on hover, focus and drag.
75 *
76 * A deck that keeps dealing while someone is reading the card in front of
77 * them — or halfway through dragging it — is actively working against them.
78 */
79 useEffect(() => {
80 if (!autoplay || paused || cards.length < 2) return;
81 const timer = setTimeout(() => advance(1), autoplay);
82 return () => clearTimeout(timer);
83// … truncated

What it pulls in

npm packages

  • motion

Other registry items

  • utils

Files it writes

  • components/ui/card-stack.tsx

Facts

Registry
ui-beats
Type
registry:ui
Access
Free
Files written
1
Licence
the repository states none
First indexed
2026-08-13
Last confirmed
today

Go to the source

uibeats.com Raw registry item This item as JSON

More from ui-beats

All 34 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
Animated Beamanimated-beamui-beatsComponentsFree1 dep
Animated Listanimated-listui-beatsComponentsFree1 dep
Border Beamborder-beamui-beatsComponentsFree1 dep
Bouncebounceui-beatsComponentsFree1 dep
Dockdockui-beatsComponentsFree1 dep
Fade Infade-inui-beatsComponentsFree1 dep
Fade In Unblurfade-in-unblurui-beatsComponentsFree1 dep
Flip Cardflip-cardui-beatsComponentsFree2 deps
BlockDex

Built by

Kynth Studios

the studio behind StoreReady, ToolDrift and BreachProbe

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product.

BlockDex

BlockDex

Built by

Kynth Studios

the studio behind StoreReady, ToolDrift and BreachProbe

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product.

BlockDex

BlockDex

Built by

Kynth Studios

the studio behind StoreReady, ToolDrift and BreachProbe

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product.

BlockDex