Components
Pie Chart
NativeShows how a whole splits into a few parts, as a filled disc with a list of the parts beside it.
| Part | Value | Share |
|---|---|---|
| Chrome | 5.1K | 50% |
| Safari | 3.3K | 32% |
| Firefox | 940 | 9% |
| Edge | 610 | 6% |
| Other | 270 | 3% |
Installation
npx nook-ui@latest add pie-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 "Pie Chart" component to this project, exactly as Nook ships it.
Shows how a whole splits into a few parts, as a filled disc with a list of the parts beside it.
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 pie-chart`. It writes `components/ui/pie-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/pie-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 { PieChart } from "@/components/ui/pie-chart";
const DATA = [
{ label: "Chrome", value: 5120 },
{ label: "Safari", value: 3280 },
{ label: "Firefox", value: 940 },
{ label: "Edge", value: 610 },
{ label: "Other", value: 270 },
];
export default function PieChartDefault() {
return <PieChart className="w-full" title="Visits by browser in November" data={DATA} />;
}
```
API
- `PieChart`: The chart. Takes the same props as DonutChart except the thickness and the center content.
- `data` (`{ label; value }[]`): Up to five parts. Fold smaller ones into Other.
- `title` (`string`): What the chart shows.
- `legend` (`boolean`, default true): Show the list of parts.
- `formatValue` (`(value: number) => string`): Formats 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: The same data is in a table for screen readers. Every slice has a title with its value, and the list names every part with its value and share, so color is never the only cue.
Done when the component renders like the example in light and dark mode and the project type-checks.Usage
import { PieChart } from "@/components/ui/pie-chart";
const DATA = [
{ label: "Chrome", value: 5120 },
{ label: "Safari", value: 3280 },
{ label: "Firefox", value: 940 },
{ label: "Edge", value: 610 },
{ label: "Other", value: 270 },
];
export default function PieChartDefault() {
return <PieChart className="w-full" title="Visits by browser in November" data={DATA} />;
}Examples
With currency
| Part | Value | Share |
|---|---|---|
| Team | $18,400 | 52% |
| Business | $12,900 | 36% |
| Solo | $4,300 | 12% |
Without the list
| Part | Value | Share |
|---|---|---|
| People | 55 | 55% |
| Tools | 30 | 30% |
| Travel | 15 | 15% |
Props
PieChart
The chart. Takes the same props as DonutChart except the thickness and the center content.
| Prop | Type | Default | Description |
|---|---|---|---|
| data | { label; value }[] | – | Up to five parts. Fold smaller ones into Other. |
| title | string | – | What the chart shows. |
| legend | boolean | true | Show the list of parts. |
| formatValue | (value: number) => string | – | Formats values. |
Accessibility
The same data is in a table for screen readers. Every slice has a title with its value, and the list names every part with its value and share, so color is never the only cue.
Checked against WCAG 2.1 AA with automated axe tests and keyboard tests on every release.