Item Card

Ready-made collectible cards for games: an original frame with a rarity edge, an element tint, big art, abilities, flavour text and a set footer. Cards tilt toward the pointer with a foil shine, flip to a custom back, and scale every part from one width. CardHand fans them like a hand; CardGrid lays out a binder.

View as Markdown

Pass a CardData object and you are done. Rare cards get a shimmer, epic and legendary get holo foil. Move the pointer over a card to tilt it.

River CarpHP60
Fish · RiverWater
1Splash20
Water two plots next to this card.
Jumps highest at dawn, near the bamboo bridge.
012/060Village Set
Giant PumpkinHP120
Crop · AutumnEarth
2Heavy Harvest×3
Your next harvest gives three times the coins.
Took a whole season and a lot of patience.
027/060Village Set
Moon GemHP150
New
TreasureMoon
3Full Moon99
Once a game: every crop grows at once.
Only appears when the moon is full.
060/060Village Set

Installation

npx shadcn@latest add @cozy/item-card

Usage

import { ItemCard, type CardData } from "@/components/ui/item-card"

const carp: CardData = {
  id: "carp", name: "River Carp", art: "/cards/carp.png", rarity: "rare", element: "water",
  stat: { label: "HP", value: 60 }, type: "Fish · River",
  abilities: [{ name: "Splash", cost: 1, value: 20, text: "Water two plots." }],
  footer: { number: "012/120", set: "Village Set" },
}

<ItemCard card={carp} size="md" onSelect={(c) => play(c)} />

Examples

Sizes, flip and not collected

size is "sm", "md", "lg" or a number of px; text and frame scale with it. flipOnClick turns the card over; owned={false} shows a silhouette.

Paper LanternHP80
Decor · FestivalEmber
1Warm Glow
Friends who visit stay one more turn.
3Night Market50
Earn 50 coins after sunset.
041/060Village Set

Hand

CardHand fans the cards and shrinks them to fit narrow screens. Click a card to lift it; the selected one stays up.

River CarpHP60
Fish · RiverWater
1Splash20
Water two plots next to this card.
Jumps highest at dawn, near the bamboo bridge.
012/060Village Set
Giant PumpkinHP120
Crop · AutumnEarth
2Heavy Harvest×3
Your next harvest gives three times the coins.
Took a whole season and a lot of patience.
027/060Village Set
Paper LanternHP80
Decor · FestivalEmber
1Warm Glow
Friends who visit stay one more turn.
3Night Market50
Earn 50 coins after sunset.
041/060Village Set
Moon GemHP150
New
TreasureMoon
3Full Moon99
Once a game: every crop grows at once.
Only appears when the moon is full.
060/060Village Set
Corn SproutHP40
Seed · SummerLeaf
1Grow10
Draw a card.
003/060Village Set
Jade TeapotHP90
Decor · HomeSpirit
2Tea Time
Heal 30 energy for each friend in the village.
033/060Village Set

Pick a card to play.

Binder

CardGrid with ownedIds shows the set you have and silhouettes for the rest.

API

Everything else is passed through to the underlying element or Radix primitive.

PropTypeDefaultDescription
cardCardData<T>–{ id, name, label?, art?, rarity?, element?, stat?, type?, abilities?, flavor?, footer?, foil?, badge?, data? }. `art` is a React node or an image URL.
size"sm" | "md" | "lg" | number"md"160, 240 or 320 px wide, or any width. Height follows the 5:7 card shape and everything inside scales with it. Never wider than its container.
onSelect / selected / disabled(card) => void / boolean–With onSelect the card is a button (click, Enter, Space).
flipped / defaultFlipped / onFlippedChange / flipOnClickboolean / fnfalseShow the back. flipOnClick turns the card on click instead of selecting it.
backReactNodepatternYour own card back (logo, set art).
tiltbooleantrue3D tilt and glare toward the pointer. Off under reduced motion.
ownedbooleantruefalse shows a dark silhouette with ??? for cards not collected yet.
card.foil"holo" | "shimmer" | "none"by rarityHolo for epic and legendary, shimmer for rare, none otherwise.
elements / raritiesRecord<string, { label, color, icon? }>DEFAULT_ELEMENTS / DEFAULT_RARITIESYour own element and rarity sets; colours are any CSS colour.
renderArt / renderAbility / renderFooterfn–Replace parts of the front, e.g. a 3D canvas or animated sprite as the art.
CardHand{ cards, size?, selectedId?, onSelect?, spread?, overlap?, disabledIds?, cardProps? }spread 24, overlap 0.45A fanned hand. `spread` is the total angle in degrees, `overlap` the share each card hides of the previous one.
CardGrid{ cards, size?, selectedId?, onSelect?, ownedIds?, cardProps? }–A responsive binder grid; cards not in ownedIds show as silhouettes.