Components
Chart parts
NativeThe shared parts every Nook chart is built from: series colors, legend, tooltip, axis, grid and data table.
Installation
npx nook-ui@latest add chartPrompt
Paste this into your AI coding assistant. It adds this exact component, the same way the CLI does, and tells the assistant how to use it.
Short. For assistants that can run commands in your project.
Add the Nook "Chart parts" component to this project, exactly as Nook ships it.
The shared parts every Nook chart is built from: series colors, legend, tooltip, axis, grid and data table.
Steps
1. Check for `nook.json` in the project root. If it is missing, run `npx nook-ui@latest init` first (React or Next.js with Tailwind CSS v4). It adds the Nook tokens, the theme and `cn()`.
2. Run `npx nook-ui@latest add chart`. It writes `components/ui/chart.tsx` together with everything the component needs. Do not write the component from memory.
3. If you cannot run commands, fetch http://localhost:3000/r/chart.json, write every entry of `files` to the path it names, install the packages in `dependencies`, and repeat for each name in `registryDependencies`.
4. Use it where I ask.
API
- `ChartLegend`: Names each series next to its color.
- `items` (`string[]`): Series names, in series order.
- `ChartTable`: The data as a visually hidden table.
- `caption` (`string`): What the chart shows.
- `columns` (`string[]`): Column headers.
- `rows` (`(string | number)[][]`): One array per row.
- `ChartTooltip`: The card shown next to a hovered mark.
- `title` (`ReactNode`): Usually the category.
- `rows` (`{ label?, value, index? }[]`): One line per series.
- `niceScale(max)`: Returns a rounded top value and ticks from zero.
Rules
- Colors, radii, shadows and motion come from Nook tokens and classes such as `bg-primary`, `text-muted-foreground`, `border-border`, `rounded-lg` and `h-control`. Never hard-code them.
- Do not restyle or simplify the file. Change how it looks through `className`, its props and the theme.
- It must keep working with the keyboard, in light and dark mode, and in the sharp, soft and bold styles.
- Accessibility: Use ChartTable in every chart so the data is available without sight, and ChartLegend whenever there are two or more series.
Done when the component renders like the example in light and dark mode and the project type-checks.Usage
Props
ChartLegend
Names each series next to its color.
| Prop | Type | Default | Description |
|---|---|---|---|
| items | string[] | – | Series names, in series order. |
ChartTable
The data as a visually hidden table.
| Prop | Type | Default | Description |
|---|---|---|---|
| caption | string | – | What the chart shows. |
| columns | string[] | – | Column headers. |
| rows | (string | number)[][] | – | One array per row. |
ChartTooltip
The card shown next to a hovered mark.
| Prop | Type | Default | Description |
|---|---|---|---|
| title | ReactNode | – | Usually the category. |
| rows | { label?, value, index? }[] | – | One line per series. |
niceScale(max)
Returns a rounded top value and ticks from zero.
Accessibility
Use ChartTable in every chart so the data is available without sight, and ChartLegend whenever there are two or more series.
Checked against WCAG 2.1 AA with automated axe tests and keyboard tests on every release.