Skip to content
react-cards-opening

CardSpin

CardSpin is the reel a case opening is known for. A strip of tiles races under a marker, slows down, and stops on a card. The winning tile lights up, the rest dim, and the card lifts out of it into the reveal. One press is one spin.

5 spins left.

Every spin stops on one of your cards.

  • Not won yet
  • Not won yet
  • Not won yet
  • Not won yet
  • Not won yet

Press Spin. The reel stops on the next card of the deal.

Usage

tsx
import { useOpenedCards } from "@react-cards-opening/core";
import { CardSpin } from "@react-cards-opening/ui";

function Spins({ won, catalog }) {
  const { opened, open } = useOpenedCards("spins:42");
  return <CardSpin cards={won} pool={catalog} opened={opened} onOpen={open} />;
}

The spin decides nothing

cards is what was won, decided before anything moves. pool is everything that could have come up, and it only fills the strip. Tiles are drawn from the pool by tier weight with pickCard, so rare cards pass less often and the strip looks like the odds, and the tile under the marker at the end is always the card that was dealt. The strip is built from a seed, so a server and a browser lay out the same tiles.

Props

PropTypeWhat it does
cardsreadonly C[]What was won, in the order the spins stop on them.
openedreadonly string[]Ids already won on the reel.
onOpen(id: string) => voidA card was turned face up for the first time.
pool?readonly C[]What slides past on the reel. The deal itself when left out.
theme?CardThemeThe colours. moss in the dark when left out.
rarities?readonly RarityTier[]Your tiers. They weigh what the strip is filled with.
actions?ReactNodeExtra buttons in the header, next to the spin button.
onRunChange?(running: boolean) => voidA spin started or came to rest.
labels?Partial<CardSpinLabels>Every word in the panel.
landing?(card) => HTMLElement | nullWhere a won card lands, instead of its badge here.
renderFace?(card, info) => ReactNodeThe front of the card, instead of the ready-made face.
renderBack?(card) => ReactNodeThe back of the card.
readingOf?(card, info) => readonly string[]The text on a face of your own, so the card stays up long enough to read.
effects?EffectPlan | falseWhat each tier plays on top of the card's own reveal. The signature shows when left out, false for none.
className?stringA class for the panel.
classNames?CardSpinClassNamesA class of your own for each part: the panel's, the reel's and the reveal's.
style?CSSPropertiesInline styles for the panel.

SpinReel on its own

CardSpin is SpinReel and CardOpening wired to useCardOpening. When the layout is yours, take the reel alone. Its handle has one call: spin plays the reel and hands back what launch on CardOpening takes, so the card waits for the reel and then lifts out of the winning tile.

tsx
import { CardOpening, SpinReel, type SpinReelHandle } from "@react-cards-opening/ui";

const reel = useRef<SpinReelHandle>(null);

<SpinReel handle={reel} winner={hunt.current} pool={catalog} spinKey={spins} />
<CardOpening opening={hunt.opening} launch={(card, show) => reel.current?.spin(show) ?? null} />
PropTypeWhat it does
winnerC | nullThe card the next spin stops on. With none, the strip shows what could come up and waits.
poolreadonly C[]What slides past: every card that could have come up.
spinKey?string | numberChanges with every spin, so two spins for the same card deal two different strips.
theme?CardThemeThe colours.
rarities?readonly RarityTier[]Your tiers.
handle?Ref<SpinReelHandle>spin(show, { flash, onLock }): plays the reel and answers a launch.
className?stringA class for the reel's root.
classNames?SpinReelClassNamesA class of your own for each part of the reel.
style?CSSPropertiesInline styles for the root: the place for --rco-tile.

Parts and variables

KeyThe library's classThe part
reel.rco-reelThe reel's window. className on a SpinReel used alone.
strip.rco-reel-stripThe strip that slides.
tile.rco-reel-tileEvery tile. The winner also gets data-won.
tileName.rco-reel-nameThe card's name under a tile's glyph.
marker.rco-reel-markerThe line the reel stops under.
KeyThe library's classThe part
root.rco-panelThe panel. The same as className.
flash.rco-panel-flashThe flash over the whole panel on a loud card.
head.rco-panel-headThe row that holds the words and the buttons.
headline.rco-panel-headlineThe headline.
subline.rco-panel-sublineThe line under it.
actions.rco-panel-actionsThe buttons' row.
mainButton.rco-button-mainThe main button: Spin, or Open the case.
sideButton.rco-button-skipTake all during a run, and the replay button after it.
finds.rco-findsThe list of badges.
badge.rco-badgeEach badge, won or not. A won one is a button.
badgeArt.rco-badge-artThe little glyph's box in a badge.
badgeName.rco-badge-nameThe card's name in a badge.
badgeWhere.rco-badge-whereThe second line of a badge.
VariableWhat it setsWhen left out
--rco-tileA tile's width and height.112px, and 92px on a narrow screen

Last updated . Read this page as Markdown.