# Treemap (Lumen Halo): prompt.md (v1.0.0)

- id: `lumen-treemap` · version 1.0.0 · component · pro (Pro)
- category: Charts
- build: Base UI (one set of files; its dependencies follow the build)
- install (this build): `npx shadcn@latest add @beautiful-ui-pro/lumen-treemap`
- npm dependencies: recharts@^3
- registry dependencies: utils, @beautiful-ui/lumen-chart, @beautiful-ui/lumen-stat, https://beautiful-ui.dev/r/lumen-foundation.json
- docs: https://beautiful-ui.dev/components/lumen-treemap
- The install command carries everything this item needs (files, CSS, tokens, npm and registry dependencies). Prefer it to copying source by hand.

A whole split into nested tiles sized by value, laid out squarified so they stay near square. Click a tile (or press Enter) to step inside, and the breadcrumb, Escape or Backspace steps back out; each tile shows its own children as hairlines; arrow keys move between tiles by where they sit.

## Build it
- Stack: React 19 (`ref` is a plain prop), TypeScript, Tailwind CSS v4 utilities, a shadcn-initialised project with the `@/*` alias.
- Packages: `recharts@^3`.
- Files: `components/ui/lumen/charts/treemap.tsx`, `components/ui/lumen/charts/chart-frame.tsx`, `components/ui/lumen/charts/cartesian.tsx`.
- Registry dependencies, installed with it automatically: shadcn `utils` (cn), `lumen-chart`, `lumen-stat`, `lumen-foundation`.
- Builds: one set of files for both, but its dependencies come in Base UI and Radix builds. Install the one that matches the project (see Install): a free item's bare URL installs the Base UI build of it and its dependencies.
- Exports to keep: `Treemap`, `Breadcrumb`, and every exported type.
- CSS: the install merges this item's rules (the registry `css` field) into your global stylesheet, in `@layer components`, and adds the lumen foundation (tokens, keyframes, motion levels) once. Nothing to import by hand.
- Re-running `add` (or `--overwrite`) re-applies those rules: put overrides in your own CSS, never in the installed rules.
- Tokens: retheme with the `--lumen-*` custom properties (`--lumen-accent`, `--lumen-accent-foreground`, `--lumen-accent-text`, `--lumen-bad`, `--lumen-bad-text`, `--lumen-chart-accent`, `--lumen-chart-accent-foreground`, `--lumen-chart-accent-text`, `--lumen-focus`, `--lumen-good`, `--lumen-good-text`, `--lumen-hairline`, `--lumen-ink`, `--lumen-muted-ink`, `--lumen-series-1`, `--lumen-series-2`, `--lumen-series-3`, `--lumen-series-4`, `--lumen-series-5`, `--lumen-series-6`, `--lumen-warn`, `--lumen-warn-text`); this item's CSS also reads `--lumen-font-mono`, `--lumen-font-sans`, `--lumen-radius-k`. Never add Tailwind colour classes inside the component.

```tsx
import { Treemap, type TreemapNode } from "@/components/ui/lumen/charts/treemap";
```

## Parts

| Part | data-slot | What it is for |
|---|---|---|
| `Treemap` | — | The tiles, breadcrumb, states, summary and table. |
| `Breadcrumb` | — | The path from the top to the level shown, with its total. |

## Sound
- Keep every `data-slot` and `data-sound` attribute: the sound layer reads them.
- Installing this item adds no audio. Nothing plays until the app mounts `GlassSoundProvider` once (install: `npx shadcn@latest add https://beautiful-ui.dev/r/glass-sound.json`, import from `@/components/beautiful-ui/glass-sound`); `GlassSoundToggle` is its mute control. Without a provider the audio engine never loads.

## Match the original
- Read `components/ui/lumen/charts/treemap.tsx`, `components/ui/lumen/charts/chart-frame.tsx`, `components/ui/lumen/charts/cartesian.tsx` as the reference implementation before changing or recreating anything, and match it: sizes, colours per theme, motion timings, copy and behaviour.
- If you deviate (a prop you can't honour, a style you changed, a dependency you swapped), say so in your reply, part by part.
- Keep the accessibility contract, the keyboard map and the motion levels listed below.

## Use it when
- treemap, hierarchy, nested parts of a whole, drill down, budget breakdown, revenue by region and country, disk usage, portfolio
- A whole with two or three levels of parts, where the big pieces matter and you want to step into them

### Not when
- A handful of parts of one whole: use a Donut Chart
- Exact comparison between similar values: use a Bar Chart
- Change over time: use an Area Chart

## Mistakes
- Keep data and config stable (outside the component, or memoised)
- Give siblings unique ids (or names): the path is made of them
- Values must be zero or more; a treemap can't show negatives

## Usage

```tsx
"use client";
import * as React from "react";
import { Treemap, type TreemapNode } from "@/components/ui/lumen/charts/treemap";

const spend: TreemapNode[] = [
  { id: "eng", name: "Engineering", children: [{ name: "Cloud", value: 420000 }, { name: "Tools", value: 96000 }, { name: "Contractors", value: 180000 }] },
  { id: "gtm", name: "Go to market", children: [{ name: "Ads", value: 260000 }, { name: "Events", value: 140000 }] },
  { id: "ops", name: "Operations", children: [{ name: "Office", value: 120000 }, { name: "Legal", value: 60000 }] },
];

const config = {
  eng: { label: "Engineering", color: "var(--chart-1)" },
  gtm: { label: "Go to market", color: "var(--chart-2)" },
  ops: { label: "Operations", color: "var(--chart-3)" },
};

export function SpendTreemap() {
  const [path, setPath] = React.useState<string[]>([]);
  return <Treemap data={spend} config={config} path={path} onPathChange={setPath} valueFormat={{ style: "currency", notation: "compact" }} label="Spend by team" />;
}
```

## Props

| Prop | Type | Default | What it does |
|---|---|---|---|
| `data` | `TreemapNode[]` |  | The top level: { id?, name, value?, children? }. A parent's value is the sum of its children's. |
| `config` | `ChartConfig` |  | Colour and label per top-level id; deeper tiles take their branch's colour, brighter when bigger. |
| `path / defaultPath / onPathChange` | `string[]` | `[]` | The ids from the top to the level shown; controlled or not. |
| `onSelect` | `(path, node) => void` |  | A leaf tile was clicked or Enter pressed on it. |
| `valueFormat` | `StatFormat \| (n) => string` |  | Numbers on tiles, breadcrumb total, live region, table and summary. |
| `labels` | `{ root?, path?, of?, open? }` |  | Words for i18n: the top crumb ("All"), the breadcrumb's name, "of" and the "Enter to open" hint. |
| `gap / height` | `number / number` | `3 / 320` | Gap between tiles and plot height in px. |
| `motion` | `"full" \| "subtle" \| "off"` | `"full"` | Tiles settle in when a level opens and glide when values change; reduced motion always wins. |
| `loading / error / emptyText / label` | `boolean / string / string / string` |  | States in words with the height held, and the chart's accessible name. |

Full docs: https://beautiful-ui.dev/components/lumen-treemap

## Customising
- Motion: `motion="full"` (default) | `"subtle"` | `"off"`. prefers-reduced-motion is always respected.
- Colours: set the `--lumen-*` tokens on `:root`, or on a container with the `lumen-scope` class to retheme one area. Add the `lumen-inherit` class to follow your shadcn palette instead (`--chart-N`, `--destructive`).
- Dark mode follows the `.dark` class on an ancestor (the shadcn and next-themes convention).
- Update later by re-running the install with `--overwrite` (review the diff if you edited it). Changelog: https://beautiful-ui.dev/r/changelog.json

## Keyboard

| Keys | Action |
|---|---|
| Tab | The breadcrumb, then into the tiles (one tab stop) |
| Arrows | Move to the nearest tile in that direction |
| Home / End | Largest or smallest tile |
| Enter / Space | Step into a tile, or select a leaf (onSelect) |
| Escape / Backspace | Step back out to the level above |

## Performance

- HTML tiles positioned in percentages, so resizing doesn't re-layout; a level re-lays out when its size changes
- Fine for a few hundred tiles per level; the table becomes a 'View as table' disclosure past 500 cells

## Responsive

- The layout follows the plot's own proportions; names and then values hide when a tile is too small to hold them (container queries)

## Motion inventory

| Interaction | What moves |
|---|---|
| Open a level | Tiles settle in from 94%, largest first (motion="subtle" is faster and together) |
| Change | Tiles glide to their new place and size |

## Accessibility contract (preserve when editing)
- A labelled figure; the breadcrumb is a nav with the current level marked (aria-current)
- Tiles are buttons with one tab stop for the level; each says its name, value, share and whether it opens
- Stepping in or out is said through a polite live region, and focus returns to the tile you came from
- A one-sentence summary and the whole tree as a table (path and value) for screen readers
- Negative values are refused in words; missing and zero values take no space and stay in the table

## Install

```bash
npx shadcn@latest add @beautiful-ui-pro/lumen-treemap
```

Pro item: needs the `@beautiful-ui-pro` registry in `components.json` and `BEAUTIFUL_UI_TOKEN` in `.env.local` (https://beautiful-ui.dev/account). Setup: https://beautiful-ui.dev/docs/pro. Your components.json `style` picks the build: radix-*, new-york and default get Radix, base-* gets Base UI.

## Credits
- Squarified treemaps (Bruls, Huizing, van Wijk)

The lumen foundation (the tokens listed above, keyframes and motion levels) installs once with the first component; its CSS is public at https://beautiful-ui.dev/r/lumen-foundation.json.
