Skip to content
react-cards-opening

CardPack

CardPack is the pack opening card games are known for. A sealed pack floats until it is pressed, bursts, and deals its cards face down on a table. A card glows in its tier's colour under the pointer, which is the tease, and turns over when it is pressed, in any order. Done gathers them into a row.

5 cards inside. Press the pack.

Press the pack. Hover a card before you turn it.

Usage

tsx
import { useOpenedCards } from "@react-cards-opening/core";
import { CardPack } from "@react-cards-opening/ui";
import "@react-cards-opening/ui/styles.css";

function Pack({ cards }) {
  const { opened, open } = useOpenedCards("pack:42");
  return <CardPack cards={cards} opened={opened} onOpen={open} />;
}

cards is the pack, in the order it is dealt, and each card names its tier in rarity. What is in the pack is decided before it is opened: deal it with rollCards on your server and the tearing is only the show.

How it lays the table

  • Five cards sit in a ring, one at the top, the layout a pack of five is known by. Any other count sits in rows. Up to ten sit well.
  • The table is measured against the pack's own width, with a container query, so a pack in a sidebar lays itself out like one on a phone: two or three to a row.
  • A card moves by changing two numbers. Gathering them on Done is the same cards with new seats, and the stylesheet glides them there.

What each tier does

Every card throws sparks as it turns. A loud tier opens rays behind itself and jolts the table. A legendary lights the whole table. On top of that each tier plays its signature show, and effects swaps it for a set or a plan of your own.

tsx
import { CardPack, EFFECT_SETS } from "@react-cards-opening/ui";

<CardPack cards={cards} opened={opened} onOpen={open} effects={EFFECT_SETS.radiant} />;

Props

PropTypeWhat it does
cardsreadonly C[]The cards in the pack, in the order they are dealt.
openedreadonly string[]Ids already turned over. A pack that comes back with some of them is dealt, not sealed.
onOpen(id: string) => voidA card was turned face up for the first time.
theme?CardThemeThe colours. moss in the dark when left out.
rarities?readonly RarityTier[]Your tiers. The six defaults when left out.
emblem?PixelArtThe glyph on the front of the sealed pack. A question mark when left out.
onDone?() => voidEvery card is turned and Done was pressed.
labels?Partial<CardPackLabels>Every word the pack says, and what a screen reader hears.
actions?ReactNodeExtra buttons under the table once the pack is done.
renderFace?(card, info) => ReactNodeThe front of a card, instead of the ready-made face.
renderBack?(card) => ReactNodeThe back of a card, instead of the question glyph.
readingOf?(card, info) => readonly string[]The text on a face of your own, so a card brought up close stays 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 pack's root.
classNames?CardPackClassNamesA class of your own for each part.
style?CSSPropertiesInline styles for the root: the place for --rco-pack-width.

Parts and variables

KeyThe library's classThe part
root.rco-packThe pack's panel. The same as className. It carries data-stage.
table.rco-pack-tableThe table the cards are dealt on.
sealed.rco-pack-sealedThe sealed pack: a button.
packFlash.rco-pack-flashThe flash over the table as the pack bursts, and as a legendary turns.
seat.rco-pack-seatA card's place on the table. It carries data-up and data-effect.
seatPress.rco-pack-pressThe button around each card.
seatRays.rco-pack-raysThe rays a loud card opens behind itself.
seatBit.rco-pack-bitEach spark a turning card throws.
foot.rco-pack-footThe row under the table: the hint and the buttons.
hint.rco-pack-hintThe line that says what to do next.
mainButton.rco-button-mainDone.
sideButton.rco-button-againDeal them again.
VariableWhat it setsWhen left out
--rco-pack-widthThe widest the table is laid out for. Past it the cards stop growing.880px
--rco-pack-sizeThe sealed pack's width.min(40cqw, 180px)
--rco-panel-radiusThe corners of the pack's panel.28px

Without the component

The rules are useCardPack in the core package: sealed, dealt, done, and which cards are up. Draw the table yourself and keep the rules.

Last updated . Read this page as Markdown.