SignaturePad
A surface to sign on with a mouse, a pen or a finger. The ink follows the speed of the hand, and the signature comes back as an SVG a form can store.
Import
import { SignaturePad } from '@vitral/vue';Basic
`v-model` is the signature as an SVG data URL, ready for an `<img>` or a form field; `v-model:strokes` is the points, to draw it again later. Undo takes back the last stroke.
The ink
The line follows the hand the way a nib does. `thinning` is how much the pressure changes the width — a pen's own pressure, or else one worked out from the speed, so a slow stroke is wider than a quick one; 0 draws a line of one width. `smoothing` takes the tremor out, `taper` narrows each end to a point over that length, and `pen-width` is the width at middling pressure. The stored SVG is drawn with the same ink. Sign, then move the sliders: the signature is drawn again.
In a form
The pad is a field like any other: it takes a label, and `toPNG()` gives an image for a service that wants one.
Read-only and disabled
Read-only shows a signature and takes no more ink; disabled is also dimmed and left out of the tab order.
API
Read from packages/vue/src/components/SignaturePad/types.ts, so it says what the component actually accepts.
Props
| Name | Type | Description |
|---|---|---|
| penColor | string | The ink's colour; the theme's (the text colour) otherwise. |
| penWidth | number | The ink's width at middling pressure, in the pad's units. Defaults to the theme's, 2.5. |
| thinning | number | How much the pressure changes the width, 0 to 1: at 0.5 the line runs from half to one and a half times `penWidth`. The pressure is a pen's own, or else worked out from the speed — slower is wider. 0 draws a line of one width. Defaults to 0.5. |
| smoothing | number | How much of the hand's tremor is smoothed away, 0 to 1. Higher is smoother, and lags a little more. Defaults to 0.5. |
| taper | number | [start: number, end: number] | Length over which each end of a stroke narrows to a point, in the pad's units: one for both, or `[start, end]`. Defaults to 0. |
| pressure | boolean | Use a pen's own pressure where it reports one; false works it out from the speed for every device. Defaults to true. |
| minDistance | number | Points closer than this to the last one, in the pad's units, are left out. Defaults to 1.5. |
| height | string | Any CSS length; the theme's (`10rem`) otherwise. |
| disabled | boolean | — |
| readonly | boolean | Shows the signature, and takes no more ink. |
| placeholder | string | false | The words above the line while the pad is empty; the locale's "Sign here" otherwise. `false` for none. |
| showControls | boolean | The undo and clear buttons in the corner. Defaults to true. |
Plus pt, dt and unstyled from BaseProps, see pass-through and unstyled mode.
Emits
| Event | Payload | Description |
|---|---|---|
| begin | — | A stroke was started. |
| end | — | A stroke was finished; the model has the signature with it. |