Cómo funciona
Strokes are stored as points with a width rather than as pixels. Coalesced pointer events give dense samples; each segment is a quadratic curve from midpoint to midpoint, and the width follows speed through a low-pass filter so it never steps. Because the data is kept, undo is exact, the canvas redraws sharply at any pixel ratio, the signature rescales when the pad changes width, and the ink colour follows the theme.
Úsalo para
- Accepting a proposal, a delivery or a consent form where a drawn signature is expected.
- Collecting a quick sketch or initials on a tablet or phone.
Busca otra opción cuando
- A legally binding signature flow on its own: pair it with identity and audit steps on the server.
- As the only way to confirm: always offer a typed-name or checkbox alternative for people who cannot draw.
Uso
import { useRef, useState } from 'react'
import { SignaturePad } from './SignaturePad.jsx'
export function SignStep() {
const pad = useRef(null)
const [empty, setEmpty] = useState(true)
return (
<>
<SignaturePad ref={pad} height={180} onChange={(s) => setEmpty(s.isEmpty)} />
<button disabled={empty} onClick={() => upload(pad.current.toSVG())}>
Accept and sign
</button>
</>
)
}Propiedades
| Propiedad | Tipo | Por defecto | Qué hace |
|---|---|---|---|
onChange | ({ isEmpty, strokes }) => void | — | Called after each stroke, undo or clear. |
defaultStrokes | [x, y][][] | — | Strokes to start with, as points normalised to the pad (0 to 1), such as a saved signature. |
height | number | 180 | Pad height in px; the width fills the container and the drawing rescales with it. |
minWidth | number | 0.9 | Thinnest line, at fast strokes. |
maxWidth | number | 3.2 | Thickest line, at slow strokes; pen pressure can add up to 30%. |
color | string | — | Ink colour. By default the ink follows --ds-sign-ink, then --ds-text, so it flips with the theme. |
baseline | boolean | true | Draws the dashed line and × mark. |
disabled | boolean | false | Locks the pad, for example after submitting. |
labels | object | — | Replaces built-in text: pad, hint, undo, clear, empty, signed, strokes(n). |
ref | { undo, clear, isEmpty, toDataURL, toSVG } | — | Imperative handle: toDataURL(type) returns an image, toSVG() a resolution-free path drawing. |
Accesibilidad
- The canvas is a focusable role="img" whose label states whether it is signed and how many strokes it has.
- Keyboard: Ctrl / Cmd+Z undoes the last stroke, Delete or Backspace clears. Drawing itself needs a pointer, so offer a typed alternative next to it.
- Undo and Clear are real buttons, 32px high, hidden only while the pad is empty.
- touch-action: none stops the page from scrolling while signing. Reduced motion removes the hint and tool fades.
Movimiento
Ink appears under the pen with no delay. The hint fades and rises 4px in 240ms when the first stroke starts; the tools fade in over 200ms once there is something to undo.
Añádelo a tu proyecto
Los miembros Pro copian un prompt y su agente de programación instala el código, igual que con los gratuitos.
SignaturePad.jsxsignature-pad.csstokens.cssREADME.md
Los dos archivos se instalan juntos. La hoja de estilos lee las variables de tokens.css y lleva valores de reserva, así que también funciona sola.







