Skip to content

components/item-grid

ItemGridItem = object

One item placed on the grid. Coordinates are cells from the top left.

id: string

label: string

Accessible name, e.g. “Axe” or “Bread”.

x: number

y: number

optional w?: number

Footprint width in cells after rotation. Defaults to 1.

optional h?: number

Footprint height in cells after rotation. Defaults to 1.

optional icon?: ReactNode

Decorative art: a sprite, an image or an SVG.

optional quantity?: number

Stack count, drawn in pixel numerals when above 1.

optional selected?: boolean


ItemGridGhost = object

A drop preview: where the held item would land, and whether it may.

x: number

y: number

w: number

h: number

legal: boolean

optional reason?: string

Why an illegal drop is refused, in the host’s words.


ItemGridCell = object

A grid cell, with the item covering it if any.

x: number

y: number

item: ItemGridItem | null


ItemGridCellSize = "sm" | "md" | "lg"

Cell sizes: pockets, a backpack and a big chest view.


ItemGridProps = Omit<HTMLAttributes<HTMLDivElement>>, "children"> > & object

Props accepted by ItemGrid.

label: string

Accessible name of the container, e.g. “Backpack”.

columns: number

rows: number

items: readonly ItemGridItem[]

optional ghost?: ItemGridGhost | null

optional cellSize?: ItemGridCellSize

optional activeCell?: object

Controlled keyboard cursor. Omit to let the grid keep its own.

x: number

y: number

optional onActiveCellChange?: (cell) => void

The keyboard cursor moved to another cell.

ItemGridCell

void

optional onCellActivate?: (cell) => void

Click, Enter or Space on a cell. The host decides pick up, drop or use.

ItemGridCell

void

optional onCellHover?: (cell) => void

Pointer over a cell, or null on leaving the grid; for drag ghosts.

ItemGridCell | null

void


ItemSlotState = "idle" | "legal" | "illegal"

How a slot answers the item being held over it.


ItemSlotProps = Omit<ButtonHTMLAttributes<HTMLButtonElement>>, "children"> > & object

Props accepted by ItemSlot.

label: string

Slot name, e.g. “Head” or “Main hand”.

optional item?: { label: string; icon?: ReactNode; } | null

The equipped item, if any.

optional placeholder?: ReactNode

Faint outline art shown while the slot is empty.

optional state?: ItemSlotState

const ItemGrid: ForwardRefExoticComponent<Omit<HTMLAttributes<HTMLDivElement>>, "children"> > & object & RefAttributes<HTMLDivElement>>>>

A Diablo-style item grid. Cells carry the keyboard and pointer interface; items and the drop ghost are drawn above them from the host’s facts. The grid never moves, merges or validates items: it shows what the host says.


const ItemSlot: ForwardRefExoticComponent<Omit<ButtonHTMLAttributes<HTMLButtonElement>>, "children"> > & object & RefAttributes<HTMLButtonElement>>>>

One equipment slot for a paper doll: a pocket, its item and its name.