Deck
A stack of cards you drag, fling or arrow through. It can cycle forever or run out, and late cards rise in from beneath.
@patternmode/deck
Earth corridor1 of 6Drag the top card past the threshold or fling it. The next card is already in place underneath.
mode="cycle" visibleCount={3}Reference
States and variants
Choose whether the deck loops, how many cards show, and which directions advance it.
Loops forever
mode="cycle"- No cards left
Runs out
mode="finite", Deck.Empty Late cards rise in
enter="rise" | "none"One direction only
allowedDirections={["right"]}- Keep
Overlay while dragging
renderOverlay Disabled
disabled
Install and use
Cards render their children unchanged, so use the image component your app already has.
npm i @patternmode/deck motionimport { Deck } from "@patternmode/deck";
import "@patternmode/deck/styles.css";
<Deck
aria-label="Project cards"
mode="cycle"
visibleCount={3}
onAdvance={({ direction }) => console.log(direction)}
>
<Deck.Card key="one">One</Deck.Card>
<Deck.Card key="two">Two</Deck.Card>
<Deck.Empty>No cards left</Deck.Empty>
</Deck>Core API
Deck
Root deck with finite and cyclic advance modes.
mode- "cycle" | "finite""cycle"Whether cards wrap forever or exhaust into Deck.Empty.
index- numberControlled active card index.
defaultIndex- number0Initial active card for uncontrolled decks.
visibleCount- number3Number of cards rendered in the visual stack.
onAdvance- (event: DeckAdvanceEvent) => voidCalled when the active card advances by drag or keyboard.
Deck.Card
A card child rendered into the animated stack.
children*- ReactNodeCard content rendered unchanged. Next.js consumers can place their own next/image Image inside the card.
className- stringClass passed to the rendered motion card.
Keyboard and accessibility
The deck is one focusable slider. Arrow keys advance it.
- ArrowRight
- Advances to the right, if right is an allowed direction.
- ArrowLeft
- Advances to the left, if left is an allowed direction.
- aria-label
- Names the deck. The current card is announced as the slider's value.
Package
- Package
- @patternmode/deck
- Version
- 0.5.4
- Needs
- react, react-dom, motion
- Licence
- MIT

