Shop
An in-game store grid: category tabs, a featured deal row with countdowns, discounts, low stock, sold-out and owned states, a wallet check that greys out what the player cannot afford, and currency packs for real money. It only draws the shop. Your game keeps the wallet and the stock, and charges the player from the `onBuy` event.
A village general store. Buying updates a local wallet with spend(); the corn is 20% off, the banana sapling is low on stock, the pumpkin is sold out, the watering can is owned, and the teapot is too expensive (red price, disabled Buy). Arrow keys move between cards, Enter buys.
Installation
Usage
The Buy button reads "Buy" with the price shown above it. Real-money prices and free items put the price (or "Free") on the button instead, so a pack always says what it will charge.
Cards use a roving tabindex: Tab enters the grid once, arrow keys, Home and End move between cards, Enter buys or selects. Sold-out and owned cards say so to screen readers. Announcing a purchase (toast, aria-live) is up to your game.
Cozy UI never charges real money. For { real: "$4.99" } items, call your store SDK (App Store, Google Play, Stripe) from onBuy.
Examples
Gem packs for real money
kind: "pack" items with a { real: "$4.99" } price show a big amount, a bonus ribbon and the price on the button. tag adds a ribbon such as "Best value"; featured lifts the starter bundle into a wide card.
Controlled, sorted and translated
A controlled category, sort, a fixed columns count, labels in Vietnamese and renderItem for the card body. onSelect takes over card clicks (for a detail view), so only the Buy button buys.
API
Everything else is passed through to the underlying element or Radix primitive.
| Prop | Type | Default | Description |
|---|---|---|---|
items | ShopItem<T>[] | – | { id, name, label?, icon?, description?, price, rarity?, category?, badge?, discount?, stock?, soldOut?, owned?, limit?, endsAt?, featured?, kind?, amount?, bonus?, tag?, disabled?, data? }. `price` is a `Price` or an array of prices that are all paid. `icon` is a React node or an image URL. |
wallet | Wallet | – | What the player has. Items the wallet cannot cover get a red price and a disabled Buy button (the card stays selectable). Without it nothing is greyed out. |
currencies | Record<string, Currency> | DEFAULT_CURRENCIES | Names and icons of your currencies (coins and gems by default). |
categories | { id, label, icon? }[] | – | Tabs. An "All" tab is added first. Items match by `category`. |
category / defaultCategory / onCategoryChange | string / string / (id) => void | "all" | Control the open tab. Use "all" for the first tab. |
allLabel | ReactNode | "All" | Text of the first tab. |
onBuy | (item) => void | – | Buy was pressed. Only called for items that can be bought (not sold out, owned, disabled or too expensive). Takes the money in your game. |
onSelect | (item) => void | – | The card body was clicked or Enter was pressed on it, e.g. to open details. Works for every item. If you do not set it, clicking the card buys. |
title / headerEnd | ReactNode | – | Header text and a slot at its end, e.g. a `CurrencyBar`. |
refreshAt | number | – | Epoch ms of the next stock refresh. The header shows "New stock in 3h 12m" until then. |
item.endsAt | number | – | Epoch ms when a deal ends. The card counts down and hides the countdown once the time has passed. |
cardSize / columns | number | 168 / auto | Minimum card width in px (cards grow to fill the row), or a fixed column count (it falls back to `cardSize` on narrow containers). Cards in a row share one height. |
lowStock | number | 5 | Shows "3 left" when `stock` is at or below this. |
sort | (a, b) => number | items order | Sort function for the featured row and the grid. |
renderItem | (item, state) => ReactNode | – | Replace the inside of the card body. `state` is { soldOut, owned, affordable, canBuy, lowStock, featured }. Keep it non-interactive; the price and Buy button stay. |
labels | Partial<ShopLabels> | English | buy, soldOut, owned, all, free, left(n), newStockIn(time), endsIn(time), bonus(bonus), discount(percent), notEnough. |
emptyText / rarities / label | ReactNode / Record<string, RarityConfig> / string | "Nothing for sale right now" | Empty message, your own rarity set, and the accessible name of the list (defaults to the title). |