Components
Sketchpad
NativeA pressure-aware freehand canvas with theme ink, an eraser, stroke history and PNG export.
Think out loud.
Sketch the journey from a first visit to a first order.
Draw with a mouse, pen or touch. Drawing needs a pointer; all toolbar controls work with a keyboard.
4 strokes
Installation
npx nook-ui@latest add sketchpadPrompt
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 "Sketchpad" component to this project, exactly as Nook ships it.
A pressure-aware freehand canvas with theme ink, an eraser, stroke history and PNG export.
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 sketchpad`. It writes `components/ui/sketchpad.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/sketchpad.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 { Sketchpad, type SketchStroke } from "@/components/ui/sketchpad";
const initial: SketchStroke[] = [
{ tool: "pen", color: 1, size: 4, points: [{ x: 0.15, y: 0.28, pressure: 0.6 }, { x: 0.4, y: 0.25, pressure: 0.6 }, { x: 0.43, y: 0.58, pressure: 0.6 }, { x: 0.16, y: 0.62, pressure: 0.6 }, { x: 0.15, y: 0.28, pressure: 0.6 }] },
{ tool: "pen", color: 3, size: 4, points: [{ x: 0.58, y: 0.27, pressure: 0.6 }, { x: 0.83, y: 0.3, pressure: 0.6 }, { x: 0.81, y: 0.61, pressure: 0.6 }, { x: 0.6, y: 0.58, pressure: 0.6 }, { x: 0.58, y: 0.27, pressure: 0.6 }] },
{ tool: "pen", color: "foreground", size: 3, points: [{ x: 0.46, y: 0.43, pressure: 0.6 }, { x: 0.55, y: 0.43, pressure: 0.6 }, { x: 0.52, y: 0.4, pressure: 0.6 }] },
{ tool: "pen", color: "foreground", size: 3, points: [{ x: 0.55, y: 0.43, pressure: 0.6 }, { x: 0.52, y: 0.46, pressure: 0.6 }] },
];
export default function SketchpadDefault() {
return <div className="grid w-full gap-4"><div><h3 className="text-base font-medium">Think out loud.</h3><p className="mt-1 text-sm text-muted-foreground">Sketch the journey from a first visit to a first order.</p></div><Sketchpad label="Customer journey whiteboard" defaultValue={initial} filename="customer-journey.png" /></div>;
}
```
API
- `Sketchpad`: A responsive drawing region and keyboard-operable toolbar. Pointer events support mouse, pressure-sensitive pens and touch.
- `label` (`string`): Required accessible description of the drawing.
- `value / defaultValue` (`SketchStroke[]`, default []): Controlled or initial vector strokes. Points use zero-to-one coordinates; colors are foreground or chart numbers 1–5.
- `onValueChange` (`(strokes: SketchStroke[]) => void`): Receives committed strokes, including undo, redo and clear.
- `onChange` (`(dataUrl: string) => void`): Receives a PNG data URL after committed changes and environment redraws.
- `filename` (`string`, default sketch.png): The PNG download filename.
- `...props` (`React.HTMLAttributes<HTMLDivElement>`): Everything the native element accepts, such as `id`, `aria-*` and event handlers.
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: All toolbar controls have names and work with a keyboard. The canvas has a required label and a visible note that drawing needs a pointer. Undo can restore Clear. Vector strokes retain their theme token and normalized positions when the canvas resizes or the theme changes.
Done when the component renders like the example in light and dark mode and the project type-checks.Usage
import { Sketchpad, type SketchStroke } from "@/components/ui/sketchpad";
const initial: SketchStroke[] = [
{ tool: "pen", color: 1, size: 4, points: [{ x: 0.15, y: 0.28, pressure: 0.6 }, { x: 0.4, y: 0.25, pressure: 0.6 }, { x: 0.43, y: 0.58, pressure: 0.6 }, { x: 0.16, y: 0.62, pressure: 0.6 }, { x: 0.15, y: 0.28, pressure: 0.6 }] },
{ tool: "pen", color: 3, size: 4, points: [{ x: 0.58, y: 0.27, pressure: 0.6 }, { x: 0.83, y: 0.3, pressure: 0.6 }, { x: 0.81, y: 0.61, pressure: 0.6 }, { x: 0.6, y: 0.58, pressure: 0.6 }, { x: 0.58, y: 0.27, pressure: 0.6 }] },
{ tool: "pen", color: "foreground", size: 3, points: [{ x: 0.46, y: 0.43, pressure: 0.6 }, { x: 0.55, y: 0.43, pressure: 0.6 }, { x: 0.52, y: 0.4, pressure: 0.6 }] },
{ tool: "pen", color: "foreground", size: 3, points: [{ x: 0.55, y: 0.43, pressure: 0.6 }, { x: 0.52, y: 0.46, pressure: 0.6 }] },
];
export default function SketchpadDefault() {
return <div className="grid w-full gap-4"><div><h3 className="text-base font-medium">Think out loud.</h3><p className="mt-1 text-sm text-muted-foreground">Sketch the journey from a first visit to a first order.</p></div><Sketchpad label="Customer journey whiteboard" defaultValue={initial} filename="customer-journey.png" /></div>;
}Props
Sketchpad
A responsive drawing region and keyboard-operable toolbar. Pointer events support mouse, pressure-sensitive pens and touch.
| Prop | Type | Default | Description |
|---|---|---|---|
| label | string | – | Required accessible description of the drawing. |
| value / defaultValue | SketchStroke[] | [] | Controlled or initial vector strokes. Points use zero-to-one coordinates; colors are foreground or chart numbers 1–5. |
| onValueChange | (strokes: SketchStroke[]) => void | – | Receives committed strokes, including undo, redo and clear. |
| onChange | (dataUrl: string) => void | – | Receives a PNG data URL after committed changes and environment redraws. |
| filename | string | sketch.png | The PNG download filename. |
| ...props | React.HTMLAttributes<HTMLDivElement> | – | Everything the native element accepts, such as `id`, `aria-*` and event handlers. |
Accessibility
All toolbar controls have names and work with a keyboard. The canvas has a required label and a visible note that drawing needs a pointer. Undo can restore Clear. Vector strokes retain their theme token and normalized positions when the canvas resizes or the theme changes.
Checked against WCAG 2.1 AA with automated axe tests and keyboard tests on every release.