Skill Tree
A talent tree: skills on a grid, lines for prerequisites, points to spend. Nodes show their state at a glance (locked with a padlock, available with a soft glow, learned in the branch colour, maxed with a gold ring), multi-rank nodes show "2/3", and picking a node opens its details in a side panel (a bottom sheet on phones). Your game owns the ranks and the point balance; the tree tells you what changed. Big trees scale to the box and can be dragged and zoomed.
A farmer's tree with three branches. Click a node for details, press Learn (or double-click, or Enter on a focused node). Refunds are allowed unless another learned skill needs the node. +1 point and Level up unlock more; the keystone needs level 4 and a skill from each side.
Installation
Usage
State: each node is locked (prerequisites or level missing), available (rank 0 and unlocked), learned (some ranks) or maxed. It is exposed as data-state; data-learnable marks nodes that can be learned right now (they pulse, except under reduced motion).
Keyboard: arrow keys move to the nearest node in that direction, Space selects, Enter selects and learns, Escape closes the details. Learning, refunding and why a learn was blocked are announced through an aria-live region.
Pan and zoom never take over the page: a plain wheel scrolls the page, Ctrl or ⌘ + wheel zooms. On touch, drags pan only along the axes where the tree overflows, so the page can still scroll.
Examples
Minimum props
Only nodes and a height. No points means unlimited, pannable={false} scales the tree to fit the box, and the tree keeps the ranks itself.
API
Everything else is passed through to the underlying element or Radix primitive.
| Prop | Type | Default | Description |
|---|---|---|---|
nodes | SkillNode<T>[] | – | { id, name, label?, icon?, description?, x, y, requires?, requiresAny?, maxRank?, cost?, kind?, branch?, rankText?, requiresLevel?, data? }. x and y are grid cells (column, row); the tree is cropped to the cells in use. |
requires / requiresAny | string[] | – | Node ids. `requires`: all must be learned (rank 1 or more). `requiresAny`: at least one. Both can be used on one node. |
maxRank / cost | number / number | number[] | 1 / 1 | Ranks, and points per rank: one number, or one entry per rank (the last repeats), e.g. [1, 1, 2]. |
kind | "small" | "notable" | "keystone" | "small" | Circle, rounded square, big diamond. |
rankText | (rank) => ReactNode | – | Effect at a rank. The details show it for the current and the next rank. |
branches / legend | Record<string, { label, color?, icon? }> / boolean | - / true | Colours by `node.branch` (default: a palette colour per branch). The legend shows when branches are given. |
ranks / defaultRanks / onRanksChange | Record<string, number> | {} | Ranks per node id. `onRanksChange(next, { id, from, to, node })` fires after each learn or refund; in controlled mode apply `next`. |
points | number | unlimited | Points the player can spend. Learning is disabled when the next rank costs more. The tree does not subtract: use `total - spentPoints(ranks, nodes)`. A number shows the counter. |
level | number | – | Player level for `requiresLevel` (no level means no check). |
allowRefund | boolean | false | Adds a Refund button to the details. Blocked while a learned node depends on the node. |
onReset | () => void | boolean | – | Shows a Reset all button (disabled with nothing learned); the game decides the cost. Uncontrolled ranks are cleared too, unless you return false. |
selected / defaultSelected / onSelect | string | null / (node | null) => void | none | Selected node id and callback with the node (null when closed). |
cellSize / height | number / number | string | 88 / 480 | Pixels between cells at zoom 1, and the box height. The tree scales down to the box width, but not below 80%. |
pannable | boolean | true | Drag to pan and zoom (buttons, Ctrl or ⌘ + wheel) when the tree is bigger than the box. False scales the whole tree to fit. |
renderNode / renderDetails | (node, state) => ReactNode | – | Replace a node's icon area or the whole details panel. `state` has status, rank, maxRank, cost, learnable, refundable, learn() and refund(). |
labels | Partial<SkillTreeLabels> | English | Every built-in text, including the aria-live announcements and "{name}", "{rank}", "{max}" placeholders. |
canLearn(node, ranks, nodes, { points, level }) | { ok, reason? } | – | Pure helper. reason is "maxed", "requires", "level" or "points" (checked in that order). |
canRefund(node, ranks, nodes) / spentPoints(ranks, nodes) | boolean / number | – | Pure helpers. canRefund is false when it is the last rank and a learned node needs it. |