Signature
Fonts and style helpers
The faces, the ink, the signing line and small helpers the components and the PDF share.
- @signnative/ui
- MIT
- Client only · no backend
The typed faces need fonts.css from the package (about 400 kB, each face loaded when first shown), or your own @font-face rules for the family names in SIGNATURE_FONTS.
Theme
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.
The four faces
- Ada Exampledelafield
Mrs Saint Delafield - Ada Examplemuellerhoff
Herr Von Muellerhoff - Ada Exampleallura
Allura - Ada Exampleaurore
La Belle Aurore
tsx
import { SIGNATURE_FONTS, SIGNATURE_INK, signatureFontFamily } from "@signnative/ui";
import "@signnative/ui/fonts.css";
export function Example() {
return (
<ul>
{SIGNATURE_FONTS.map((f) => (
<li key={f.id} style={{ fontFamily: signatureFontFamily(f.id), color: SIGNATURE_INK, fontSize: 30 }}>
Ada Example
</li>
))}
</ul>
);
}
Line, baseline and ink
Ada Example
signatureLineFor(120) = {"height":122,"below":31} · baseline 0.74 · ink #0b1f4d
tsx
import { SIGNATURE_BASELINE, SIGNATURE_INK, SignatureLine, SignaturePreview, signatureLineFor } from "@signnative/ui";
import "@signnative/ui/styles.css";
export function Example() {
return (
<div>
<SignatureLine {...signatureLineFor(120)}>
<SignaturePreview signature={{ kind: "typed", text: "Ada Example", font: "delafield" }} />
</SignatureLine>
<p>
Baseline {SIGNATURE_BASELINE}, ink {SIGNATURE_INK}
</p>
</div>
);
}
Download the PNG
Draw, then download the PNG.
tsx
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 height={140} onChange={setPng} />
{png && (
<a href={signatureDataUrl(png)} download="signature.png">
Download signature.png
</a>
)}
</div>
);
}
Installation
npx shadcn@latest add …
Not published yet
Not in the registry (packages/ui/registry.json) yet.
API
className and children are left out: every component that takes them passes them on.
Fonts and style
| Name | Type | Default | Description |
|---|---|---|---|
| SIGNATURE_FONTS | { id, label, family, fontName }[] | The four typed faces (SIL Open Font License 1.1). | |
| SIGNATURE_FONT_IDS | SignatureFontId[] | Their ids, for validation. | |
| DEFAULT_SIGNATURE_FONT | SignatureFontId | "delafield" | The face used when none is chosen. |
| isSignatureFontId | (x: unknown) => x is SignatureFontId | Checks a value from outside, such as a request body. | |
| signatureFontFamily | (id?: SignatureFontId) => string | CSS font-family for a face, with fallbacks. | |
| SIGNATURE_INK | string | "#0b1f4d" | Signature ink, a deep blue-black. The PDF uses the same. |
| SIGNATURE_INK_RGB | [number, number, number] | The ink as 0 to 1 RGB, for PDF libraries. | |
| SIGNATURE_BASELINE | number | 0.74 | Where the signing line sits in the pad and in every drawn image, from the top. |
| SIGNATURE_PAD_HEIGHT | number | 180 | Default pad height in CSS pixels. |
| signatureDataUrl | (png: string) => string | A PNG from onChange as a data: URL. | |
| signatureLineFor | (padHeight: number) => { height, below } | SignatureLine props that match a pad, so a drawing shows 1:1. | |
| SIGNATURE_PAD_LABELS | SignaturePadLabels | The pad's English texts, to start a translation from. | |
| SIGNATURE_CAPTURE_LABELS | SignatureCaptureLabels | The capture's English texts. |