Signature
Signature Pad
Draw a signature with a mouse, a pen or a finger. Gives you a PNG with a transparent background.
- @signnative/ui
- MIT
- Client only · no backend
A signature image is a picture, not an identity check. What makes a signature mean something is how the signer was identified and what the evidence records.
The CSS variables this sets
:root {
--signing-accent: #3157e8;
--sig-accent: #3157e8;
--sig-accent-soft: color-mix(in oklab, #3157e8 14%, white);
--sig-radius: 8px;
--radius-control: 8px;
--radius-panel: 12px;
--font-sans: var(--font-inter), ui-sans-serif, system-ui, sans-serif;
}In the signer page kit, set the accent with accentProps(accent) on the element around the surface; it sets data-signing-accent and --signing-accent. The secure elements take the same values as a checked appearance object instead.
Default
Draw with a mouse, a pen or a finger. onChange gets a base64 PNG after each stroke, or null after Clear.
onChange: null (empty)
import { useState } from "react";
import { SignaturePad } from "@signnative/ui";
import "@signnative/ui/styles.css";
export function Example() {
const [png, setPng] = useState<string | null>(null);
return (
<div>
<SignaturePad onChange={setPng} />
<p>{png ? "Signed" : "Empty"}</p>
</div>
);
}
Controlled, with Undo and the image
Pass value to control it: null from outside empties the pad. signatureDataUrl turns the PNG into an image source.
import { useState } from "react";
import { SignaturePad, signatureDataUrl } from "@signnative/ui";
import "@signnative/ui/styles.css";
export function Example() {
const [png, setPng] = useState<string | null>(null);
return (
<div>
<SignaturePad value={png} onChange={setPng} undo />
{png && <img alt="Your signature" src={signatureDataUrl(png)} height={120} />}
<button disabled={!png} onClick={() => setPng(null)}>
Clear from outside
</button>
</div>
);
}
Ink, line width and height
Any CSS colour. Keep the default ink for documents: the PDF uses the same.
import { SignaturePad } from "@signnative/ui";
import "@signnative/ui/styles.css";
export function Example() {
return <SignaturePad height={140} lineWidth={4} ink="#1d7a4c" undo />;
}
Other wording
Every text the pad shows or announces can be replaced, for translation or your own tone.
import { SignaturePad } from "@signnative/ui";
import "@signnative/ui/styles.css";
export function Example() {
return (
<SignaturePad
labels={{
placeholder: "Sign with your finger",
clear: "Start over",
drawnAnnouncement: "Thanks, your signature is drawn.",
}}
/>
);
}
Theming with CSS variables
The paper stays light, but its colours are variables. Set them on any element around the pad.
import { SignaturePad } from "@signnative/ui";
import "@signnative/ui/styles.css";
// In your CSS:
// .pad-paper {
// --sig-paper: #fffdf6;
// --sig-paper-border: #e3d9b8;
// --sig-paper-line: #c7b98a;
// --sig-paper-hint: #7a6a3a;
// --sig-radius: 2px;
// }
export function Example() {
return (
<div className="pad-paper">
<SignaturePad ink="#2b2a6e" />
</div>
);
}
Phone width
The width follows the container. A touch draws and never scrolls the page.
import { SignaturePad } from "@signnative/ui";
import "@signnative/ui/styles.css";
export function Example() {
return <SignaturePad height={160} undo />;
}
Installation
npx shadcn@latest add <site>/r/signature-pad.json
Not published yet
API
className and children are left out: every component that takes them passes them on.
SignaturePad
| Name | Type | Default | Description |
|---|---|---|---|
| onChange | (png: string | null) => void | After each stroke, Undo and Clear. A base64 PNG without the data: prefix, or null when empty. | |
| value | string | null | Controlled value. A new value the pad did not report is drawn; null empties the pad. | |
| defaultValue | string | null | null | Uncontrolled start value, read once on mount. |
| height | number | 180 | Height of the drawing area in CSS pixels. The width follows the container. |
| lineWidth | number | 2.5 | Stroke width in CSS pixels. |
| ink | string | "#0b1f4d" | Stroke colour, any CSS colour. |
| undo | boolean | false | Show an Undo button that removes the last stroke. |
| labels | Partial<SignaturePadLabels> | English | Every text the pad shows or announces, for translation. |
Accessibility
- The drawing area is an image whose name says whether it is empty. A status line announces “Signature drawn.” and “Signature cleared.”
- A canvas cannot be drawn on with a keyboard. Clear and Undo can be reached and pressed, but that is not a way to sign: put a typed name next to the pad, or use Signature Capture.
- Clear and Undo are buttons with text, at least 44 px tall, with a visible focus outline.
- A touch on the pad draws and never scrolls the page (touch-action: none). A second finger is ignored while one draws.