Command Palette

Search for a command to run...

Pokemon Stat

Base stat rows (HP, Attack, Defense…) composed on shadcn/ui Field and Progress, with per-stat color, recomposable parts, and a render-prop list.

Installation

Usage

Each row is a shadcn/ui Field: a FieldLabel (name + value) above a Progress, linked via htmlFor / id — the same pattern as the shadcn progress-with-label example. The root is layout + context: you compose the parts. For known stats (hp, attack, defense, special-attack, special-defense, speed) the label and color are resolved automatically; the bar scales against max (default 255).

By default PokemonStatLabel renders name … value (value pushed right with ml-auto). Pass children to recompose the label row.

Examples

Render-prop list

PokemonStatList accepts data via stats (an array of entries or a { stat: value } record) and a render prop as children that decides how each row is rendered. The list only iterates, normalizes order, and sets the key.

Tip

The render prop passes a function as children, so the consumer must be a Client Component ("use client").

Manual composition

Without stats, PokemonStatList is just a spacing wrapper — compose rows by hand.

Custom label

Because all parts read from context, you can recompose the label row freely. PokemonStatValue carries the value — place it wherever you need it.

Custom stat

For stats outside the known set, pass label, color, and max yourself.

Accessibility

PokemonStatBar is built on the shadcn/ui Progress component (which wraps Radix UI), so it already exposes role="progressbar" with aria-valuenow / aria-valuemin / aria-valuemax. Additionally:

  • The actual value (value / max, not the percentage) is announced via aria-valuetext.
  • PokemonStatLabel is a FieldLabel with htmlFor pointing to the bar's id (generated with useId), matching the shadcn progress-with-label pattern.

API Reference

PokemonStat

Root of a stat row — a shadcn/ui Field. Owns value + max, derives the percentage and color, and shares them through context. Also accepts all Field props.

PropTypeDefault
stat
valuenumber
maxnumber255
labelstringnombre del stat
colorstringcolor del stat / --primary

PokemonStatLabel

Label row above the bar, rendered as a shadcn/ui FieldLabel and linked to the bar via htmlFor. By default renders name … value; pass children to recompose. Accepts all FieldLabel props.

PokemonStatValue

Numeric stat value. Defaults to value from context; pass children to override. Accepts all native <span> props.

PokemonStatBar

The bar — a shadcn/ui Progress recolored per stat via the --stat-color CSS variable.

PropTypeDefault
...propsReact.ComponentProps<typeof Progress>

PokemonStatList

Spacing wrapper. With stats + a children render prop it renders from data; without them, compose <PokemonStat> manually. Also accepts all native <div> props.

PropTypeDefault
statsPokemonStatsInput
children

usePokemonStat

Context access hook — must be used inside <PokemonStat>.

PropertyTypeDescription
namePokemonStatName | undefinedThe stat passed to the root, if any.
value / maxnumberBase value and scale ceiling.
percentnumbervalue / max clamped to 0–100 (consumed by PokemonStatBar).
labelstringResolved display label.
colorstringResolved stat color.
idstringLinks FieldLabel (htmlFor) to the bar (id).

Constants

ExportDescription
POKEMON_STAT_ORDERCanonical stat order (as returned by PokéAPI).
POKEMON_STAT_LABELStat → label map (hpHP, special-attackSp. Atk…).
POKEMON_STAT_COLORStat → color map (inline hex values, no external tokens).
POKEMON_STAT_MAXPractical ceiling for a base stat (255).