Components
Sparkline
NativeA small trend line without axes, for use next to a number.
Revenue$45,231
Response time182 ms
Installation
npx nook-ui@latest add sparklinePrompt
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 "Sparkline" component to this project, exactly as Nook ships it.
A small trend line without axes, for use next to a number.
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 sparkline`. It writes `components/ui/sparkline.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/sparkline.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 { Sparkline } from "@/components/ui/sparkline";
export default function SparklineDefault() {
return (
<div className="flex flex-wrap gap-8">
<div className="grid gap-1">
<span className="text-sm text-muted-foreground">Revenue</span>
<span className="flex items-center gap-4">
<span className="text-2xl font-semibold tracking-tight tabular-nums">$45,231</span>
<Sparkline aria-label="Revenue over the last 12 weeks, rising" data={[22, 24, 23, 27, 26, 30, 29, 33, 36, 35, 41, 45]} />
</span>
</div>
<div className="grid gap-1">
<span className="text-sm text-muted-foreground">Response time</span>
<span className="flex items-center gap-4">
<span className="text-2xl font-semibold tracking-tight tabular-nums">182 ms</span>
<Sparkline area aria-label="Response time over the last 12 hours, steady" data={[190, 184, 201, 178, 186, 192, 180, 175, 188, 183, 179, 182]} />
</span>
</div>
</div>
);
}
```
API
- `Sparkline`: The line.
- `data` (`number[]`): The values, oldest first.
- `area` (`boolean`, default false): Fill under the line.
- `aria-label` (`string`): What the line shows. Required.
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: Renders a single image. Describe the trend in `aria-label`, for example "Revenue, last 12 weeks, rising".
Done when the component renders like the example in light and dark mode and the project type-checks.Usage
import { Sparkline } from "@/components/ui/sparkline";
export default function SparklineDefault() {
return (
<div className="flex flex-wrap gap-8">
<div className="grid gap-1">
<span className="text-sm text-muted-foreground">Revenue</span>
<span className="flex items-center gap-4">
<span className="text-2xl font-semibold tracking-tight tabular-nums">$45,231</span>
<Sparkline aria-label="Revenue over the last 12 weeks, rising" data={[22, 24, 23, 27, 26, 30, 29, 33, 36, 35, 41, 45]} />
</span>
</div>
<div className="grid gap-1">
<span className="text-sm text-muted-foreground">Response time</span>
<span className="flex items-center gap-4">
<span className="text-2xl font-semibold tracking-tight tabular-nums">182 ms</span>
<Sparkline area aria-label="Response time over the last 12 hours, steady" data={[190, 184, 201, 178, 186, 192, 180, 175, 188, 183, 179, 182]} />
</span>
</div>
</div>
);
}Props
Sparkline
The line.
| Prop | Type | Default | Description |
|---|---|---|---|
| data | number[] | – | The values, oldest first. |
| area | boolean | false | Fill under the line. |
| aria-label | string | – | What the line shows. Required. |
Accessibility
Renders a single image. Describe the trend in `aria-label`, for example "Revenue, last 12 weeks, rising".
Checked against WCAG 2.1 AA with automated axe tests and keyboard tests on every release.