Lab/14
Draw Pad
Strokes are smoothed with curves between midpoints and drawn at device pixel ratio, so lines stay crisp. Pen pressure is supported.
- Canvas
- Tool
Draw anywhere
lab/draw-paddraw here
Installation
Add Draw Pad to your project with the shadcn CLI. The files land in components/lab, ready to edit.
$ pnpm dlx shadcn@latest add @soultel/lab-draw-padOr by URL: https://asafefe.dev/r/lab-draw-pad.json
Brings along
- utils
- @soultel/lab-canvas
Usage
import { useRef } from "react"
import { DrawPad, type DrawPadHandle } from "@/components/lab/draw-pad"
export function Example() {
const pad = useRef<DrawPadHandle>(null)
return (
<div>
<DrawPad ref={pad} className="h-80 rounded-xl border" />
<button onClick={() => pad.current?.download("sketch.png")}>Save PNG</button>
</div>
)
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
| ref | Ref<DrawPadHandle> | - | clear(), toDataURL(), and download(filename?). |
| color | string | "var(--foreground)" | Brush color. |
| size | number | 4 | Brush width in px. |
| pressure | boolean | true | Vary the width with pen pressure. |
| exportBackground | string | "#ffffff" | Fill behind exports. "transparent" keeps alpha. |
| placeholder | ReactNode | "draw here" | Shown while empty. |
| onEmptyChange | (empty: boolean) => void | - | Called when the pad gets or loses a drawing. |
