Default
Draw with the mouse, a finger or a pen. Every line is written by the same pen as the buttons: pressure swells it, felt pools where you stop, pencil has tooth.
A real drawing surface. Pointer, touch, pen pressure or the keyboard put strokes on paper, and every stroke is rendered by the interface's own pen (variable-width ribbons, pooled ends, felt / graphite / marker grain), so what people draw looks like the rest of the page. Undo, redo, export as svg, replay.
npx shadcn@latest add @wobko/sketchpad第一次使用?先把 registry 加进 components.json。 如何安装
Draw with the mouse, a finger or a pen. Every line is written by the same pen as the buttons: pressure swells it, felt pools where you stop, pencil has tooth.
Felt, brush, pencil, marker and highlighter on one page. Same points, five materials: the grain and the blend come from the pen, not from the data.
A read-only sketchpad that draws itself on again, stroke after stroke, along each center line. Reduced motion shows the finished picture.
The parts compose. A pencil-and-eraser sketchbook on graph paper, four colors, taped to the desk, with a plot already begun.
A real use: draw a card, watch a live thumbnail (the same strokes, read-only), save the picture as svg or copy the JSON to keep it in your database.
The root: it owns the strokes, the pen in hand, the history and the export handle, and lays out a toolbar and a canvas when you give it no children. Strokes are plain JSON, stored in canvas units, so a saved drawing looks identical everywhere.
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| value / defaultValue | SketchStroke[] | - | The drawing: { id, tool, color, size, pts: [x, y, pressure?][] }. Controlled or uncontrolled. Strokes without an id are given one. |
| onValueChange | (strokes: SketchStroke[]) => void | - | Called after every stroke, erase, undo, redo and clear. |
| tool / defaultTool / onToolChange | "felt" | "brush" | "pencil" | "marker" | "highlighter" | "eraser" | "felt" | The pen in hand. The eraser removes whole strokes it touches. |
| tools | SketchTool[] | ["felt","pencil","marker","highlighter","eraser"] | Which tools the toolbar shows and the keyboard offers. |
| color / defaultColor / onColorChange | SketchColor | "ink" | One of the theme's pens and accents: ink, ink-you, red, green, marker, tangerine, hi, teal, grape, bubblegum. Choosing the highlighter over a dark ink switches to yellow. |
| size / defaultSize / onSizeChange | number | 1 | Width multiplier of the tool's own nominal line. Presets: 0.6 fine, 1 medium, 1.9 bold. |
| width / height | number | 640 / 400 | The canvas's logical size. Strokes live in these units and the canvas scales to its container. |
| readOnly | boolean | false | Look, do not draw. The default toolbar is left out and the canvas becomes a labeled image. |
| disabled | boolean | false | Draws nothing, dims the toolbar, leaves the tab order. |
| replay / replaySpeed | boolean / number | false / 1 | Draw the strokes on again, in order, each one uncovered along its own center line. Reduced motion shows the finished picture. |
| apiRef | Ref<SketchpadHandle> | - | undo(), redo(), clear(), replay(), strokes(), toSVG(), toDataURL() (svg, no canvas needed), toPNG() (async, null where there is no canvas). |
| seed | string | number | - | Salts every stroke's hand. Leave it out and the same JSON draws the same picture in every browser. |
The sheet the strokes land on. Pointer events with coalesced samples and pen pressure (palm rejection while a pen is in range), touch-action none, and keyboard drawing: arrows move a cursor, Space puts the pen down and lifts it. Children are guides printed under the strokes.
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| paper | "plain" | "ruled" | "graph" | "dots" | "kraft" | "plain" | What it is drawn on. |
| paperProps | PaperProps | - | Anything the sheet takes: tape, fastener, edge, stock. |
| label | string | "Drawing" | Accessible name of the canvas. |
| seed | string | number | - | Pins the frame's hand. |
A radio group of tool buttons. Each shows a sample of what its pen writes, in the current color; the selected one is boxed and highlighted. Roving focus: arrow keys move and select.
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| tools | SketchTool[] | - | Override the root's tool list for this group. |
One tool button (Radix radio item and ink host).
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| value | SketchTool | - | Which tool. |
| seed | string | number | - | Pins the hand. |
A radio group of scribbled color swatches.
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| colors | SketchColor[] | - | Which swatches to show. |
One swatch, named for screen readers (Ink, Blue, Red…).
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| value | SketchColor | - | Which color. |
One width preset.
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| value | "fine" | "medium" | "bold" | - | Which preset. |
CLI 会复制进你项目的文件。
正在加载源码