SignaturePad

Sign with a pointer, finger or stylus. The pen tip trails on a spring so strokes have the swing of ink, and line width follows speed like a nib. Undo and redo walk through strokes, the signature scales if the pad is resized, and a ref exports SVG or PNG. Inputs.

Open playground

Draw your signature

Exported SVG appears here

About

SignaturePad is a React component in the Inputs category of smoui. It is typed, ships no stylesheet, follows your theme through CSS variables, and honors prefers-reduced-motion. Import it with import { SignaturePad } from "@ashutoshswamy/smoui" and set onChange, label, height among its 5 props.

Install

Terminal
npm i @ashutoshswamy/smoui

Usage

TSX
import { SignaturePad } from "@ashutoshswamy/smoui";

const pad = useRef<SignaturePadHandle>(null);

<SignaturePad ref={pad} onChange={(svg) => setSignature(svg)} /> // svg is null when empty
// pad.current?.toPng() for a transparent PNG data URL

Props 5

onChange

After each stroke, undo or clear: the signature as standalone SVG, or null when empty.

(svg: string | null) => void
label

Accessible name of the drawing area.

stringdefault "Signature"
height

Height of the drawing area in px.

numberdefault 200
ink

Ink colour, or one per surface. The light one is used in exports.

string | { light: string; dark: string }
ref

undo(), redo(), clear(), toSvg() and toPng() for forms.

SignaturePadHandle