Signature Pad
Sign with a pen, a mouse or a finger: one part, ink that follows the pen, the strokes as a value to store and draw again — and exported, trimmed to the ink.
Usage
Usage
Sign below to agree:
import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScButton, type ScSignature, ScSignaturePad,} from '@semantic-components/ui';
/** Sign, then Clear or Save: the pad, named by the line above it, and your two buttons. */@Component({ selector: 'app-signature-pad-usage-demo',Anatomy
One part: the pad. Your buttons call it (undo(), clear()); your controls set its pen. Anything inside it — a line, "Sign here" in your words — shows under the ink.
import { ScSignaturePad, signatureToBlob, signatureToSvg } from '@semantic-components/ui';<div scSignaturePad #pad="scSignaturePad" [formField]="…" aria-label="Signature"></div><button scButton (click)="pad.undo()" [disabled]="!pad.canUndo()">Undo</button><button scButton (click)="pad.clear()" [disabled]="pad.empty()">Clear</button>The value
{ width, height, strokes: [{ points: [x, y, pressure][], color, width }] } — or null before any stroke. Plain JSON: store it, give it back, and the pad draws it again fitted to its size. Each stroke keeps its colour and width; its points carry the pressure — a pen's, or a mouse's and a finger's speed (faster, thinner).
signatureToSvg(value) and signatureToBlob(value) export it, trimmed to the ink: functions on the value, so a stored signature exports without a pad.
Accessibility
- The pad is an image of the signature: name it (aria-label or aria-labelledby). In a field, its errors are read with it; once touched and invalid, it is marked so.
- Focused: Ctrl + Z takes the last stroke back, Delete clears it.
- Drawing needs a pointer. Offer a way to sign with a keyboard — a typed name, as a second field (see Type instead).
- The ink is the text's colour by default (
currentColor), so it reads in dark mode; exported, it is black.
Examples
Form
import { Component, ViewEncapsulation, computed, signal } from '@angular/core';import { FormField, FormRoot, form, required } from '@angular/forms/signals';import { ScButton, ScField, ScFieldErrors, ScFrame, ScInput, ScLabel, type ScSignature,Pen
import { Component, ViewEncapsulation, computed, signal } from '@angular/core';import { ScButton, ScSignaturePad, ScToggleGroup, ScToggleGroupItem,} from '@semantic-components/ui';
/** * The pen from your own controls: `penColor` and `penWidth` bound to toggleExport
import { DOCUMENT } from '@angular/common';import { Component, ViewEncapsulation, inject, signal } from '@angular/core';import { ScButton, ScFrame, type ScSignature, ScSignaturePad, signatureToBlob, signatureToSvg,} from '@semantic-components/ui';Read-only
Read-only
Disabled
import { Component, ViewEncapsulation } from '@angular/core';import { type ScSignature, ScSignaturePad, type ScSignaturePoint,} from '@semantic-components/ui';
/** A saved signature given back: read-only, drawn again at the pad's size; disabled, faded too. */@Component({ selector: 'app-readonly-signature-pad-demo',Type instead
import { Component, ViewEncapsulation, signal } from '@angular/core';import { FormField, FormRoot, form, required } from '@angular/forms/signals';import { ScButton, ScField, ScFieldDescription, ScFieldErrors, ScInput, ScLabel, type ScSignature,RTL
وقّع في المربع أدناه
import { Dir } from '@angular/cdk/bidi';import { Component, LOCALE_ID, ViewEncapsulation } from '@angular/core';import { ScButton, ScSignaturePad } from '@semantic-components/ui';
/** In a right-to-left page: the pad draws as anywhere (ink has no direction); your hint and buttons follow the page. */@Component({ selector: 'app-rtl-signature-pad-demo', imports: [Dir, ScButton, ScSignaturePad], template: ` <div dir="rtl" lang="ar" class="w-full max-w-md space-y-2">API reference
The pad takes class, merged over the style (cn: a later class wins).
| Part | Selector | Description |
|---|---|---|
ScSignaturePad | div[scSignaturePad] | Where you sign, in the style’s textarea look: an image you name, focusable; a Signal Forms control (value, disabled, readonly). Your content shows under the ink. exportAs scSignaturePad: empty(), canUndo(), undo(), clear(). |
| Input | Type | Default | Description |
|---|---|---|---|
value | ScSignature | null | null | The strokes: two-way, or a [formField]. |
penColor | string | 'currentColor' | The next strokes’ colour. |
penWidth | number | 3 | The next strokes’ width, at an even pressure. |
disabled, readonly | boolean | false | From the field, or set; no drawing. |
| Input | Type | Default | Description |
|---|---|---|---|
padding | number | 8 | Space round the ink (both functions). |
type | string | 'image/png' | signatureToBlob: PNG is transparent, others on white. |
quality | number | — | signatureToBlob: 0 to 1, for JPEG and WebP. |
scale | number | 2 | signatureToBlob: pixels per signature pixel. |