Whiteboard

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 items

Installation

  1. 1

    Install the component:

    npx shadcn@latest add https://ui.amines.fun/registry/whiteboard.json
  2. 2

    Usage:

    jsx

    app/page.jsx

    <Whiteboard  title="Sprint roadmap sketch"  theme="dark"  background="dots"  snap="both"  snapSensitivity="medium"  fill="none"/>

Props

PropTypeDefaultDescriptionRequired
classNamestring"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
titlestring"Untitled sketch"Header text shown above the canvas and used as the SVG's accessible label.No
showTitlebooleantrueShow the title in the header row.No
showCountbooleantrueShow the live item count ("N items") in the header row.No
background"dots" | "lines" | "none""dots"Canvas grid style behind the drawing.No
gridSizenumber24Spacing between grid dots or lines, in pixels.No
gridColorstringundefined (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() => voidundefinedPass a function to show a close button in the header that calls it.No
colorstring"auto"Pen color. "auto" resolves to the theme ink color; any CSS color works.No
colorsstring[]["auto", "#6ea8fe", "#f06a8a"]Color swatches shown by the "colors" toolbar group. "auto" uses the theme ink.No
widthnumber3Stroke width in pixels (1-24 in the toolbar slider).No
opacitynumber1Stroke 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
smoothbooleantrueSmooth 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
fillOpacitynumber0.15Opacity of snapped-shape fills.No
eraserSizenumber18Eraser 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
snapDelaynumber450Milliseconds the pointer must stay still before a hold-triggered snap.No
snapShapesArray<"line" | "circle" | "ellipse" | "square" | "rectangle" | "triangle" | "diamond" | "polygon">All eight shapesWhich 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
snapAnimationbooleantrueAnimate the morph from the raw stroke into the snapped shape. Disabled automatically for reduced-motion users.No
snapDurationnumber0.35Snap morph duration in seconds.No
showToastbooleantrueShow the "Snapped to …" toast with a "Keep as drawn" undo action.No
toastDurationnumber3000Milliseconds the snap toast stays visible.No
recognizer(points: {x: number, y: number}[], options: { sensitivity }) => shape | nullundefined (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
toolbarArray<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
toolbarExtraReactNodeundefinedAny React node appended to the toolbar, for custom controls.No
defaultItemsArray<drawing item>[]Initial drawing items, as returned by ref.getItems(), for restoring a saved sketch.No
onChange(items) => voidundefinedCalled with the full items array after every change. Save these to persist the board.No
onSnap({ item, shape }) => voidundefinedCalled when a stroke snaps to a shape, with the created item and recognized shape.No
readOnlybooleanfalseView-only mode: hides the toolbar and disables all drawing and erasing.No
maxHistorynumber100Maximum number of undo steps retained.No
refReact.Ref<{ undo(): void; redo(): void; clear(): void; getItems(): item[]; exportSVG(): string }>undefinedImperative handle for external control: undo, redo, clear, getItems (serializable drawing state), and exportSVG (SVG string of the current board).No