Build game UI
Cozy UI ships ready-made game screens: inventory, item details, character sheet, collection book, collectible cards, a world map, a minimap, a shop with a wallet and purchase dialog, perks, a skill tree and buffs. They hold no game rules. You pass plain data, they draw it and tell you what the player did, so they fit any game state: React state, a store, a server or an ECS.
What is in the kit
| Component | What it does | Wire it with |
|---|---|---|
| Inventory | Bag, chest or hotbar: drag and drop with mouse, touch and keyboard, stacking and merging, locked slots, tabs, search and sort. | itemsonItemsChange(nextchange) |
| Item Info | Item details and tooltips: rarity, stats, compare against what is equipped (+/- in colour), action buttons. | itemcompareToactions |
| Character Info | Character sheet: portrait, level and XP, health and energy bars, attributes with bonuses, status chips, equipment slots. | characteronEquipmentSelect |
| Gallery | Collection book for items, creatures or friends: silhouettes until found, progress, filters, a big view with next and previous. | entriesonOpenChange |
| Item Card | Collectible cards with rarity frames, elements, abilities, foil, 3D tilt and flip. CardHand fans a hand; CardGrid is a binder. | cardonSelectowned |
| Currency Bar | HUD wallet: animated amounts, floating +/- deltas, caps like 35 / 60, a get-more button and a "not enough" shake. | walletonAddhighlight |
| Shop | In-game store: category tabs, featured deals with countdowns, discounts, stock, owned items and real-money currency packs. | itemswalletonBuy |
| Purchase Dialog | The confirm step: quantity, total, balance before and after, get more, then busy, success or error. Your game charges. | itemwalletonConfirm |
| Perk Picker | Pick one of a few perks on level-up, with rarity, reroll, skip and confirm. | perksonConfirmonReroll |
| Skill Tree | Talent tree: prerequisites, ranks, points, learn and refund, pan and zoom, a details panel. | nodesranksonRanksChangepoints |
| Buff Bar | Active buffs and debuffs with countdown rings, stacks and tooltips. | buffsonExpire |
| Game Map and MiniMap | World map like a maps app (pins, clusters, place panel, search, filter chips, waypoints, clouds over unexplored land) and a HUD minimap with edge arrows. | markersregionsplayeronMarkerSelect |
Two full screens show them together: the Character Screen (sheet, bag, item details, equip and sell, collection) and the Village HUD (resources, harvest button, level-up cards, minimap that opens the map) and the Village Shop (wallet, shelves, purchase dialog, gem packs).
Install
With npm, everything is in one package:
npm install @0xtrou/cozy-uiimport "@0xtrou/cozy-ui/styles.css"
import { Inventory, ItemCard, GameMap, MiniMap } from "@0xtrou/cozy-ui"Or copy the source into your project with the shadcn CLI and change anything:
npx shadcn@latest add @cozy/cozy-theme @cozy/inventory @cozy/item-info @cozy/character-info @cozy/gallery @cozy/item-card @cozy/game-map @cozy/currency-bar @cozy/shop @cozy/purchase-dialog @cozy/perk-picker @cozy/skill-tree @cozy/buff-barData in, events out
Every game component takes plain objects and calls you back. Keep the real state where your game keeps it and hand the components a view of it. Each item, card, entry and marker has a data field typed by you, so your own object comes back in every event.
import { Inventory, ItemInfo, type GameItem, type InventorySlots } from "@0xtrou/cozy-ui"
// Your game state: a store, a server snapshot or ECS components.
const bag: InventorySlots = useGame((s) => s.bag)
const [selected, setSelected] = useState<number | null>(null)
<Inventory
items={bag}
slots={24}
lockedFrom={18} // bag upgrades unlock the rest
onItemsChange={(next, change) => {
// change: { type: "move" | "merge" | "sort", from, to }
game.send({ type: "bag/update", next, change })
}}
selected={selected}
onSelect={(_, index) => setSelected(index)}
onActivate={(item) => game.send({ type: "use", id: item.id })} // double-click or Enter
/>
{selected != null && bag[selected] && <ItemInfo item={bag[selected]!} compareTo={equippedHat} />}Cards from your items
A card is one object. Art can be a React node (SVG, sprite, canvas) or an image URL; elements and rarities are your own sets.
import { ItemCard, CardHand, type CardData } from "@0xtrou/cozy-ui"
const toCard = (c: MyCard): CardData<MyCard> => ({
id: c.id, name: c.name, art: c.imageUrl, rarity: c.rarity, element: c.element,
stat: { label: "HP", value: c.hp }, type: c.typeLine,
abilities: c.moves.map((m) => ({ name: m.name, cost: m.cost, value: m.damage, text: m.text })),
footer: { number: `${c.no}/120`, set: "Village Set" }, data: c,
})
<CardHand cards={hand.map(toCard)} selectedId={picked} onSelect={(card) => play(card.data!)} />
<ItemCard card={toCard(reward)} size="lg" flipOnClick />Map and minimap from one world
Use your game's own coordinates. Both components take the same object, so the minimap and the full map never disagree. Mark a region discovered: false to keep it under clouds until the player gets there.
import { GameMap, MiniMap, useRegionChange } from "@0xtrou/cozy-ui"
const world = {
mapWidth: 1200, mapHeight: 800, background: "/maps/village.png",
kinds: { shop: { label: "Shops", icon: <CoinIcon />, color: "#7FC4E0" } },
markers: places.map((p) => ({ id: p.id, x: p.x, y: p.y, label: p.name, kind: p.kind, tracked: p.quest })),
regions, player: { x: me.x, y: me.y, heading: me.facing }, waypoint,
}
useRegionChange(world.regions, world.player, (r) => r && toast(`Entering ${r.name}`))
<MiniMap {...world} onOpen={() => setMapOpen(true)} />
<GameMap {...world} search scale={{ perUnit: 0.5, unit: "m" }}
onWaypointChange={setWaypoint}
markerActions={(m) => <Button onClick={() => travel(m.id)}>Travel</Button>} />Shop and payments
Cozy UI draws the store; it never charges anyone. In-game prices use your currencies ({ currency: "coin", amount: 120 }); real-money prices are strings your store SDK already formatted ({ real: "$4.99" }). Call the App Store or Google Play in-app purchase API (required for digital goods in mobile apps) or Stripe on the web from onConfirm, and return its Promise: the dialog shows busy, then success or the error with a retry.
import { CurrencyBar, Shop, PurchaseDialog, spend } from "@0xtrou/cozy-ui"
<Shop items={stock} wallet={wallet} categories={tabs} onBuy={setPicked} onSelect={setPicked}
headerEnd={<CurrencyBar wallet={wallet} onAdd={() => setTab("gems")} highlight={short} />} />
<PurchaseDialog
open={!!picked} onOpenChange={(o) => !o && setPicked(null)}
item={picked} wallet={wallet} maxQuantity={10}
realMoneyNote="Charged by the App Store"
onGetMore={(currency) => { setPicked(null); setTab("gems"); setShort(currency) }}
onConfirm={(item, qty) => item.data.iap
? store.purchase(item.data.sku) // your IAP / Stripe call, returns a Promise
: game.buy(item.id, qty)} // or spend(wallet, price) for in-game coins
/>Perks, skills and buffs
The game keeps the rules: which perks are offered, how many points the player has, when a buff ends. The components show them and report choices. Skill points are yours to count; spentPoints(ranks, nodes) and canLearn(...) help on the server too.
import { PerkPicker, SkillTree, BuffBar, spentPoints } from "@0xtrou/cozy-ui"
<PerkPicker perks={offer} rerolls={rerolls} onReroll={reroll} onConfirm={(perk) => game.takePerk(perk.id)} />
<SkillTree nodes={tree} ranks={ranks} onRanksChange={(next, change) => game.learn(change.id, change.to)}
points={level * 2 - spentPoints(ranks, tree)} level={level} allowRefund />
<BuffBar buffs={effects.map((e) => ({ id: e.id, name: e.name, icon: e.icon, endsAt: e.endsAt }))}
onExpire={(b) => game.removeEffect(b.id)} />Rarities, elements and look
- Rarity colours come from the palette (
--cz-rarity-common…--cz-rarity-legendary). Passraritiesto use your own names and colours. - Card elements come from
DEFAULT_ELEMENTS; passelementswith your own set. - Every
render*prop (renderCard, renderDetail, renderArt, renderMarker, renderDetails…) swaps one part and keeps the rest. - All five palettes and the glass material apply to the game components too.
Input and accessibility
- Mouse, touch and keyboard everywhere: drag items or press Space to pick up and arrow keys to move; arrow keys and +/− on the map; Enter on cards.
- Changes are announced to screen readers, and every control has a name.
- Tilt, foil, map glide and other motion turn off for people who ask for reduced motion.
Game engines
For web games (React, Phaser or PixiJS with a React overlay, Three.js) use the components directly over your canvas. For Unity, the same tokens and class names map to UI Toolkit: see the Unity guide.