Parts of a whole as rectangles sized by value, with groups you can zoom into.
$ pnpm dlx shadcn@latest add https://dashral.com/r/treemap.jsonInstallation
$ pnpm dlx shadcn@latest add https://dashral.com/r/treemap.jsonAdds the component, the components it builds on, its npm packages and the theme tokens it uses. Using Dashral often? Add the registry to components.json once:
{
"registries": {
"@dashral": "https://dashral.com/r/{name}.json"
}
}Then add components by name:
$ pnpm dlx shadcn@latest add @dashral/treemapUsage
import { Treemap } from "@/components/dashral/treemap"
<Treemap
data={[
{
label: "Marketing",
children: [
{ label: "Ads", value: 420 },
{ label: "Events", value: 180 },
],
},
{ label: "Engineering", value: 960 },
]}
formatOptions={{ style: "currency", currency: "USD" }}
aria-label="Spend by team"
/>Examples
Flat, as currency
Without children every tile is a value; formatOptions writes them.
API reference
Treemap
Also takes every prop of <div>(opens in a new tab).
| Prop | Type | Default |
|---|---|---|
data | { label: string; value?: number; color?: string; children? }[]The tiles; one with children is a group (its value is theirs added up). Colors default to --chart-1 … --chart-5, and children take their group's. Required. | — |
height | numberIn pixels; the width fills the container. | 280 |
rootLabel | stringThe top level's name in the trail. | "All" |
showHeader | booleanThe trail with the total, and the hovered tile's value and share. | true |
locale / formatOptions | string / Intl.NumberFormatOptionsHow values are written. | LocaleProvider's |
aria-label | stringWhat the chart shows. | "Treemap" |
classNames | { header, tile, label, value }Classes for each part. | — |
className | stringExtra classes, merged with cn() so yours win. | — |
Keyboard
| Keys | Action |
|---|---|
| Tab | Move between groups |
| EnterorSpace | Zoom into the focused group |
| Escape | Zoom out a level |
Accessibility
- Every tile carries its label, value and share as text, also when it's too small to show them; groups are buttons that say they zoom in.
- The trail is a nav with the current level marked; zooming in moves focus to it, zooming out back to the group you left.
- Tiles are tinted, with the text in the theme's foreground, so labels keep their contrast whatever the color.
Motion
- Tiles grow from their middle when it first shows. Zooming in grows a group's items out of where they sat inside it; zooming out shrinks it back (--duration-considered). When values change, tiles slide to their new size instead of starting over. Instant with reduced motion.