Pro unlocks unlimited templates48:00:00Get Pro →

Signature Pad

Capture handwritten signatures with mouse or touch via signature_pad. Imperative clear, undo, and PNG export through a ref.

Gallery

Undo, clear, and preview a PNG. ref exposes clear / undo / toDataURL.

Loading…

Installation

CLI
npx @sonojs/ui@latest add signature-pad
Also needs
npm i signature_pad

Usage

signature-pad.tsx
import * as React from "react"
import {
  SignaturePad,
  type SignaturePadHandle,
} from "@/components/signature-pad"

export function Example() {
  const ref = React.useRef<SignaturePadHandle>(null)

  return (
    <>
      <SignaturePad ref={ref} guide="Sign here" />
      <button type="button" onClick={() => ref.current?.clear()}>
        Clear
      </button>
    </>
  )
}

Props

PropTypeDefaultDescription
penColorstring"#0a0a0a"Ink color.
strokeWidthnumber2Base stroke width (maps to pressure min/max).
guidestring-Caption + dashed baseline under the pad.
disabledbooleanfalseBlocks drawing (read-only stored signatures).
invalidbooleanfalseDestructive border for empty-required states.
onEmptyChange(empty: boolean) => void-Fires when the pad becomes empty or has ink.
onBegin / onEnd() => void-Stroke lifecycle callbacks.
classNamestring-Merged onto the pad stage (default `h-48`).

Handle (ref)

PropTypeDefaultDescription
clear()void-Erase the pad.
undo()void-Remove the last stroke.
isEmpty()boolean-Whether any ink is present.
toDataURL()string-PNG (or other MIME) data URL.
toBlob()Promise<Blob · null>-Blob for upload / download.
toData() / fromData()PointGroup[]-Serialize / restore stroke data.

Related