Inventory
A bag of item slots with drag and drop (mouse, pen and touch), keyboard moving, stack merging, locked slots, category tabs, search, sort and item tooltips. Controlled or uncontrolled.
Controlled bag with 24 slots (the last 6 locked), tabs, search and sort. The selected slot drives an ItemInfo next to it. Drag a stack of rice seeds onto the other stack to merge them.
Arrow keys move between slots. Space picks an item up and drops it. Enter uses it.
- Weight
- 38 kg
Installation
Usage
Keyboard: arrows move between slots, Space picks an item up and drops it, Escape cancels, Enter calls onActivate. Moves are announced to screen readers.
GameItem: { id, name, icon, quantity, maxStack, stackKey, rarity, category, type, description, stats, value, level, meter, corner, locked, disabled, tags, data }. Put anything your game needs in data.
applyMove(items, from, to, stacking) is exported, so a server or game loop can apply the same rules.
Examples
Hotbar
Eight slots, no header. corner shows the hotkey, meter draws durability or cooldown. Enter or double-click calls onActivate.
Arrow keys move between slots. Space picks an item up and drops it. Enter uses it.
API
Everything else is passed through to the underlying element or Radix primitive.
| Prop | Type | Default | Description |
|---|---|---|---|
items / defaultItems | (GameItem | null)[] | – | Slot contents in order; null is empty. Use items + onItemsChange for controlled, defaultItems for uncontrolled. |
onItemsChange | (items, change) => void | – | New slots after a move, merge or sort. change is { type: "move" | "merge" | "sort", from?, to?, moved?, sortId? }. |
slots | number | items.length | Total slots; pads with empty ones. |
lockedFrom | number | – | Slots from this index on are locked (bag upgrades). |
columns / slotSize | number | fill / 64 | Fixed column count and tile size in px. |
selected / defaultSelected / onSelect | number | null | – | Selected slot index, controlled or not. |
onActivate | (item, index) => void | – | Double-click or Enter: use, equip or eat. |
canMove | (from, to, items) => boolean | – | Return false to refuse a move, e.g. quest items or a full slot type. |
movable / stacking | boolean | true | Turn off moving, or merging of stacks with the same stackKey (or name) up to maxStack. |
categories | { id, label, icon?, match? }[] | – | Filter tabs. Items match on item.category unless you pass match. Moving pauses while filtered. |
search / sorts | boolean | string / { id, label, compare }[] | – | A search box, and sort buttons that reorder the bag. |
tooltip / formatValue / rarities | boolean / fn / Record | true | Item tooltips, how values print, and custom rarity labels and colours. |
title / showCapacity / headerEnd / placeholder / emptyText | ReactNode | – | Header, used/total count, extra controls, empty-slot content and the no-match text. |