Components
Donut Chart
NativeShows how a whole splits into a few parts, with every part and its share listed beside the ring.
Spent$2,225
| Part | Value | Share |
|---|---|---|
| Rent | $1,200 | 54% |
| Food | $540 | 24% |
| Transport | $210 | 9% |
| Fun | $180 | 8% |
| Other | $95 | 4% |
Installation
npx nook-ui@latest add donut-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 "Donut Chart" component to this project, exactly as Nook ships it.
Shows how a whole splits into a few parts, with every part and its share listed beside the ring.
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 donut-chart`. It writes `components/ui/donut-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/donut-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. Start from this example:
```tsx
import { DonutChart } from "@/components/ui/donut-chart";
const DATA = [
{ label: "Rent", value: 1200 },
{ label: "Food", value: 540 },
{ label: "Transport", value: 210 },
{ label: "Fun", value: 180 },
{ label: "Other", value: 95 },
];
export default function DonutChartDefault() {
return (
<DonutChart className="w-full" title="Spending in November by category" data={DATA} formatValue={(v) => `$${v.toLocaleString("en")}`}>
<span className="text-xs text-muted-foreground">Spent</span>
<span className="text-xl font-semibold tracking-tight tabular-nums">$2,225</span>
</DonutChart>
);
}
```
API
- `DonutChart`: The ring and its list. Children sit in the middle.
- `data` (`{ label, value }[]`): Up to five parts.
- `title` (`string`): What the chart shows.
- `thickness` (`number`, default 6): Ring thickness on a 40 unit wide drawing.
- `formatValue` (`(value: number) => string`): Formats the values.
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: A hidden table carries the same data for screen readers, and text is never colored by its series. Values are listed next to the ring, so nothing depends on hovering.
Done when the component renders like the example in light and dark mode and the project type-checks.Usage
import { DonutChart } from "@/components/ui/donut-chart";
const DATA = [
{ label: "Rent", value: 1200 },
{ label: "Food", value: 540 },
{ label: "Transport", value: 210 },
{ label: "Fun", value: 180 },
{ label: "Other", value: 95 },
];
export default function DonutChartDefault() {
return (
<DonutChart className="w-full" title="Spending in November by category" data={DATA} formatValue={(v) => `$${v.toLocaleString("en")}`}>
<span className="text-xs text-muted-foreground">Spent</span>
<span className="text-xl font-semibold tracking-tight tabular-nums">$2,225</span>
</DonutChart>
);
}Examples
Thick ring
Tickets489
| Part | Value | Share |
|---|---|---|
| Billing | 128 | 26% |
| Bugs | 96 | 20% |
| How to | 211 | 43% |
| Feature asks | 54 | 11% |
One number, no legend
72%of 100 GB
| Part | Value | Share |
|---|---|---|
| Used | 72 | 72% |
| Free | 28 | 28% |
Props
DonutChart
The ring and its list. Children sit in the middle.
| Prop | Type | Default | Description |
|---|---|---|---|
| data | { label, value }[] | – | Up to five parts. |
| title | string | – | What the chart shows. |
| thickness | number | 6 | Ring thickness on a 40 unit wide drawing. |
| formatValue | (value: number) => string | – | Formats the values. |
Accessibility
A hidden table carries the same data for screen readers, and text is never colored by its series. Values are listed next to the ring, so nothing depends on hovering.
Checked against WCAG 2.1 AA with automated axe tests and keyboard tests on every release.