# Sankey Chart (Lumen Halo): prompt.md (v1.0.0)

- id: `lumen-sankey-chart` · 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-sankey-chart`
- 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-sankey-chart
- The install command carries everything this item needs (files, CSS, tokens, npm and registry dependencies). Prefer it to copying source by hand.

Where things go, from sources through steps to outcomes: each flow is a band as thick as its value, shading from its source's colour to its target's. Point at a flow to isolate it, or at a step to light every flow through it; arrow keys walk the flows with the tooltip following.

## 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/sankey-chart.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: `SankeyChart`, 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 { SankeyChart } from "@/components/ui/lumen/charts/sankey-chart";
```

## Parts

| Part | data-slot | What it is for |
|---|---|---|
| `SankeyChart` | — | The flows, steps, tooltip, states, summary and table. |

## 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/sankey-chart.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
- sankey, flow diagram, alluvial, sources to outcomes, attribution, user journeys, budget flows, energy flows, conversion paths
- Amounts moving from sources through steps to outcomes, where the split at each step matters

### Not when
- A single path with drop-off at each step: use Flow Funnel
- Flows that loop back (A → B → A): the chart refuses them; use a table or a network diagram
- More than about 30 flows: group the small ones first

## Mistakes
- Keep links, nodes and config stable (outside the component, or memoised)
- A step's size is the larger of what flows in and what flows out; if they differ, say why (people still in trial)
- Flows must not loop back; split a cycle into before and after steps

## Usage

```tsx
"use client";
import { SankeyChart } from "@/components/ui/lumen/charts/sankey-chart";

const flows = [
  { source: "search", target: "trial", value: 1840 },
  { source: "search", target: "demo", value: 260 },
  { source: "referral", target: "trial", value: 720 },
  { source: "referral", target: "demo", value: 310 },
  { source: "trial", target: "paid", value: 610 },
  { source: "trial", target: "left", value: 1950 },
  { source: "demo", target: "paid", value: 330 },
  { source: "demo", target: "left", value: 240 },
];

const config = {
  search: { label: "Search", color: "var(--chart-1)" },
  referral: { label: "Referral", color: "var(--chart-2)" },
  trial: { label: "Trial", color: "var(--chart-3)" },
  demo: { label: "Demo", color: "var(--chart-4)" },
  paid: { label: "Paid", color: "var(--chart-2)" },
  left: { label: "Left", color: "var(--chart-5)" },
};

export function SignupFlows() {
  return <SankeyChart links={flows} config={config} label="Sign-ups by source and outcome" />;
}
```

## Props

| Prop | Type | Default | What it does |
|---|---|---|---|
| `links` | `{ source, target, value }[]` |  | The flows between step ids. Values must be more than zero; zero flows are skipped. |
| `nodes` | `{ id, label? }[]` |  | Labels and the order of steps within each column. Default: ids in order of first appearance. |
| `config` | `ChartConfig` |  | Colour and label per step id; flows shade from source to target colour. Unlisted steps take the series colours. |
| `valueFormat` | `StatFormat \| (n) => string` |  | Numbers on steps, tooltip, table and summary. |
| `active / onActiveChange` | `number \| null / (index) => void` |  | The flow in focus (its index in links), controlled; omit for uncontrolled. |
| `onSelect` | `(link, index) => void` |  | A flow was clicked, or Enter pressed on the focused flow. |
| `labels` | `{ share?, source?, target?, value? }` |  | Words for i18n: share(percent, source) in the tooltip, and the table's column names. |
| `nodeWidth / nodePadding / height` | `number` | `10 / 14 / 340` | Step bar width, space between steps, and plot height in px. |
| `tooltip` | `boolean` | `true` | The flow's value and its share of its source. |
| `motion` | `"full" \| "subtle" \| "off"` | `"full"` | Flows draw from left to right in turn; 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-sankey-chart

## 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 | Focus the plot |
| Arrows | Next or previous flow, left column first; the tooltip follows |
| Home / End | First or last flow |
| Enter / Space | Select the focused flow (onSelect) |
| Escape | Clear the focus |

## Performance

- Plain SVG: one path and one gradient per flow; layout is linear in flows times steps, fine to a few hundred flows

## Responsive

- Fills its container's width and re-lays out when it changes; step labels sit beside their bars with a halo so they read over the flows

## Motion inventory

| Interaction | What moves |
|---|---|
| Draw | Flows draw from source to target, in turn (motion="subtle" draws them together, faster) |
| Isolate | The pointed flow brightens and the rest fall back to a trace |

## Accessibility contract (preserve when editing)
- A labelled figure; the plot is one tab stop (role application) and arrow keys walk the flows, each said through a polite live region with its share of its source
- The tooltip says the flow in words (from, to, value, share), so colour is never the only cue
- A one-sentence summary and every flow as a table (from, to, value) for screen readers
- Negative flows and loops are refused in words

## Install

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

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
- Built on shadcn/ui charts conventions (https://ui.shadcn.com/charts)

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.
