仕組み
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.
向いている場面
- 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.
向かない場面
- 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.
使い方
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>
</>
)
}プロパティ
| プロパティ | 型 | 既定値 | 説明 |
|---|---|---|---|
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. |
アクセシビリティ
- 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.
モーション
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.
プロジェクトに追加
Pro メンバーはプロンプトをコピーし、コーディングエージェントが無料コンポーネントと同じ手順でソースを導入します。
SignaturePad.jsxsignature-pad.csstokens.cssREADME.md
2 つのファイルを一緒に導入します。スタイルは tokens.css の変数を読み、予備の値も持つため、単体でも表示できます。







