Components
Stacked bar chart
NativeCompare totals and their parts on a common baseline.
- Live chat
- Phone
| week | Live chat | Phone | Total | |
|---|---|---|---|---|
| Oct 5 | 124 | 86 | 34 | 244 |
| Oct 12 | 142 | 96 | 28 | 266 |
| Oct 19 | 118 | 112 | 42 | 272 |
| Oct 26 | 156 | 126 | 38 | 320 |
| Nov 2 | 134 | 148 | 32 | 314 |
Installation
npx nook-ui@latest add stacked-bar-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 "Stacked bar chart" component to this project, exactly as Nook ships it.
Compare totals and their parts on a common baseline.
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 stacked-bar-chart`. It writes `components/ui/stacked-bar-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/stacked-bar-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 { StackedBarChart } from "@/components/ui/stacked-bar-chart";
export default function Example() {
return (
<StackedBarChart
title="Support requests by channel"
categoryKey="week"
series={[
{ key: "email", label: "Email" },
{ key: "chat", label: "Live chat" },
{ key: "phone", label: "Phone" },
]}
data={[
{ week: "Oct 5", email: 124, chat: 86, phone: 34 },
{ week: "Oct 12", email: 142, chat: 96, phone: 28 },
{ week: "Oct 19", email: 118, chat: 112, phone: 42 },
{ week: "Oct 26", email: 156, chat: 126, phone: 38 },
{ week: "Nov 2", email: 134, chat: 148, phone: 32 },
]}
/>
);
}
```
API
- `StackedBarChart`: Compare totals and their parts on a common baseline.
- `data / categoryKey / series` (`ChartRow[] / string / ChartSeries[]`): Nonnegative series and category labels.
- `title` (`string`): Caption and data table name.
- `formatValue` (`(value: number) => string`): Number formatting.
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: Each category is focusable with all series and total in its name; the shared data table includes totals.
Done when the component renders like the example in light and dark mode and the project type-checks.Usage
import { StackedBarChart } from "@/components/ui/stacked-bar-chart";
export default function Example() {
return (
<StackedBarChart
title="Support requests by channel"
categoryKey="week"
series={[
{ key: "email", label: "Email" },
{ key: "chat", label: "Live chat" },
{ key: "phone", label: "Phone" },
]}
data={[
{ week: "Oct 5", email: 124, chat: 86, phone: 34 },
{ week: "Oct 12", email: 142, chat: 96, phone: 28 },
{ week: "Oct 19", email: 118, chat: 112, phone: 42 },
{ week: "Oct 26", email: 156, chat: 126, phone: 38 },
{ week: "Nov 2", email: 134, chat: 148, phone: 32 },
]}
/>
);
}Props
StackedBarChart
Compare totals and their parts on a common baseline.
| Prop | Type | Default | Description |
|---|---|---|---|
| data / categoryKey / series | ChartRow[] / string / ChartSeries[] | – | Nonnegative series and category labels. |
| title | string | – | Caption and data table name. |
| formatValue | (value: number) => string | – | Number formatting. |
Accessibility
Each category is focusable with all series and total in its name; the shared data table includes totals.
Checked against WCAG 2.1 AA with automated axe tests and keyboard tests on every release.