WhiteboardWhiteboard
A responsive drawing board where freehand strokes snap to perfect lines, circles, ellipses, squares, rectangles, triangles, diamonds, and polygons. Includes pen and eraser tools, undo/redo history, customizable toolbar, light and dark themes, SVG export, and full pointer support.
Sprint roadmap sketch
0 itemsInstallation
- 1
Install the component:
npx shadcn@latest add https://ui.amines.fun/registry/whiteboard.json - 2
Usage:
jsxapp/page.jsx
1<Whiteboard2 title="Sprint roadmap sketch"3 theme="dark"4 background="dots"5 snap="both"6 snapSensitivity="medium"7 fill="none"8/>
Props
| Prop | Type | Default | Description | Required |
|---|---|---|---|---|
| className | string | "h-[480px] w-full" | Size and position classes for the root element. Any Tailwind classes; replace the default height/width as needed. | No |
| classNames | { root?: string; header?: string; canvas?: string; toolbar?: string; toast?: string; button?: string } | {} | Targeted class overrides for the root, header, canvas, toolbar, toast, and toolbar button elements. | No |
| theme | "dark" | "light" | "dark" | Color theme for the board chrome, canvas border, grid, and ink color. | No |
| title | string | "Untitled sketch" | Header text shown above the canvas and used as the SVG's accessible label. | No |
| showTitle | boolean | true | Show the title in the header row. | No |
| showCount | boolean | true | Show the live item count ("N items") in the header row. | No |
| background | "dots" | "lines" | "none" | "dots" | Canvas grid style behind the drawing. | No |
| gridSize | number | 24 | Spacing between grid dots or lines, in pixels. | No |
| gridColor | string | undefined (theme grid color) | Any CSS color for the grid; overrides the theme's default grid color. | No |
| labels | { snapped?: string; keep?: string; item?: string; items?: string; shapes?: Record<string, string> } | {} | Translate UI text: the "Snapped to" toast prefix, the "Keep as drawn" button, singular/plural item words, and per-shape names via labels.shapes. | No |
| onClose | () => void | undefined | Pass a function to show a close button in the header that calls it. | No |
| color | string | "auto" | Pen color. "auto" resolves to the theme ink color; any CSS color works. | No |
| colors | string[] | ["auto", "#6ea8fe", "#f06a8a"] | Color swatches shown by the "colors" toolbar group. "auto" uses the theme ink. | No |
| width | number | 3 | Stroke width in pixels (1-24 in the toolbar slider). | No |
| opacity | number | 1 | Stroke opacity from 0 to 1. | No |
| dash | "solid" | "dashed" | "dotted" | "solid" | Stroke dash pattern. | No |
| lineCap | "round" | "butt" | "square" | "round" | Stroke line cap style. | No |
| lineJoin | "round" | "miter" | "bevel" | "round" | Stroke line join style. | No |
| smooth | boolean | true | Smooth freehand strokes into curves; disable for raw polylines. | No |
| fill | "none" | "tint" | string (CSS color) | "none" | Fill for snapped closed shapes. "tint" uses the pen color; any CSS color fills directly. | No |
| fillOpacity | number | 0.15 | Opacity of snapped-shape fills. | No |
| eraserSize | number | 18 | Eraser diameter in pixels. | No |
| cursor | "brush" | "crosshair" | "default" | "brush" | Pointer style while drawing. "brush" shows a live pen-size dot; the eraser tool always shows its own cursor. | No |
| snap | "both" | "hold" | "release" | "off" | "both" | When strokes snap to shapes: on hold-still, on pointer release, either, or never. "off" also disables the snap toolbar toggle. | No |
| snapDelay | number | 450 | Milliseconds the pointer must stay still before a hold-triggered snap. | No |
| snapShapes | Array<"line" | "circle" | "ellipse" | "square" | "rectangle" | "triangle" | "diamond" | "polygon"> | All eight shapes | Which shapes the recognizer may snap to. A square falls back to rectangle and a circle to ellipse when only those are enabled. | No |
| snapSensitivity | "low" | "medium" | "high" | number | "medium" | How messy a drawing can be and still snap. Named presets map to tolerances 0.035/0.06/0.09; a number (about 0.02-0.15) sets it directly. | No |
| snapAnimation | boolean | true | Animate the morph from the raw stroke into the snapped shape. Disabled automatically for reduced-motion users. | No |
| snapDuration | number | 0.35 | Snap morph duration in seconds. | No |
| showToast | boolean | true | Show the "Snapped to …" toast with a "Keep as drawn" undo action. | No |
| toastDuration | number | 3000 | Milliseconds the snap toast stays visible. | No |
| recognizer | (points: {x: number, y: number}[], options: { sensitivity }) => shape | null | undefined (built-in recognizeShape) | Custom shape recognizer. Return a shape object ({ type: "line", a, b }, { type: "circle"|"ellipse", cx, cy, rx, ry }, or { type: vertex shape, vertices }) or null. The built-in recognizeShape is also exported for reuse. | No |
| toolbar | Array<string> | ["pen", "eraser", "|", "colors", "|", "snap", "undo", "redo", "clear"] | Toolbar items in order: "pen", "eraser", "colors", "snap", "undo", "redo", "clear", "width" (slider), "picker" (color input), and "|" (divider). Reorder, remove, or extend freely. | No |
| toolbarPosition | "bottom" | "top" | "left" | "right" | "bottom" | Where the floating toolbar is docked inside the canvas. | No |
| toolbarExtra | ReactNode | undefined | Any React node appended to the toolbar, for custom controls. | No |
| defaultItems | Array<drawing item> | [] | Initial drawing items, as returned by ref.getItems(), for restoring a saved sketch. | No |
| onChange | (items) => void | undefined | Called with the full items array after every change. Save these to persist the board. | No |
| onSnap | ({ item, shape }) => void | undefined | Called when a stroke snaps to a shape, with the created item and recognized shape. | No |
| readOnly | boolean | false | View-only mode: hides the toolbar and disables all drawing and erasing. | No |
| maxHistory | number | 100 | Maximum number of undo steps retained. | No |
| ref | React.Ref<{ undo(): void; redo(): void; clear(): void; getItems(): item[]; exportSVG(): string }> | undefined | Imperative handle for external control: undo, redo, clear, getItems (serializable drawing state), and exportSVG (SVG string of the current board). | No |