Perk Picker

A "Level up! Pick one" screen: a few perk cards pop in, the player chooses one and confirms. Rarity colours the card edge, upgrades show "Lv 2 → 3" or "New", and the game can offer rerolls and a skip. Cards are a row on wide containers and a vertical list on narrow ones. Controlled or uncontrolled, with radiogroup keyboard support.

View as Markdown

Three village perks of different rarities. Reroll (2 left) deals a new set and replays the reveal, Skip hands out coins, Take it confirms with a toast. Double-click or press Enter on a card to confirm it.

Level up!

Pick one perk for your village.

Installation

npx shadcn@latest add @cozy/perk-picker

Usage

import { PerkPicker, type Perk } from "@/components/ui/perk-picker"

const perks: Perk[] = [
  { id: "paddy", name: "Wider paddy", icon: <PaddyIcon />, rarity: "common", level: 1, maxLevel: 5, description: "Every plot grows bigger." },
  { id: "net", name: "Lucky net", icon: "/icons/net.png", rarity: "rare", description: "Golden carp swim by." },
]

<PerkPicker
  title="Level up!"
  perks={perks}
  rerolls={2}
  onReroll={() => setPerks(drawPerks())}
  onSkip={() => addCoins(50)}
  skipLabel="Skip, +50 coins"
  onConfirm={(perk) => applyPerk(perk.id)}
/>

Keyboard: the cards are a radio group. Arrow keys, Home and End move and select, Space selects, Enter selects and confirms. The choice is announced through a polite live region.

The picker holds no rules. After a reroll or a confirm, pass a new perks array; an uncontrolled choice that is no longer offered is cleared.

Reduced motion removes the staggered pop-in.

Examples

List in a narrow card

variant="list" forces the vertical layout. Without it the picker switches by the width of its own container, not the screen.

Pick a tool perk

Controlled, new and locked

value and onValueChange keep the choice in your state. locked can be a reason string. A perk with level: 0 shows "New".

Controlled choice

Chosen id: tea

API

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

PropTypeDefaultDescription
perksPerk<T>[]–{ id, name, label?, icon?, description?, rarity?, tags?, level?, maxLevel?, stats?, locked?, data? }. `icon` is a React node or an image URL. A new array with different ids replays the reveal.
value / defaultValue / onValueChangestring | null / (id, perk) => voidnullThe chosen perk id. Arrow keys, click and tap change it.
onConfirm / confirmLabel(perk) => void / ReactNode"Take it"Setting onConfirm shows the confirm button. Double-click and Enter on a card confirm too.
title / subtitleReactNode"Pick a perk"Heading and the line under it.
rerolls / onRerollnumber / () => void–Shows "Reroll (2)"; disabled at 0. The game decides the new perks and passes a new `perks` array.
onSkip / skipLabel() => void / ReactNode"Skip"A secondary way out, e.g. "Skip, +50 coins".
variant"cards" | "list"autoAuto uses cards when the container is at least 560px wide and a list below that.
renderPerk(perk, { selected, locked, index }) => ReactNode–Replace the inside of a card; frame, selection and keyboard stay.
raritiesRecord<string, { label, color }>DEFAULT_RARITIESYour own rarity names and colours.
labelsPartial<PerkPickerLabels>Englishtitle, new, upgrade ("Lv {from} → {to}"), max, confirm, reroll, skip, chosen ("{name} chosen"), locked, empty.