Documents and fields
Field Editor
Place signature, text, date and checkbox fields on a PDF. The output is the agreement format's fields.
- @signnative/ui
- MIT
- Client only · no backend
The examples use a synthetic PDF made in your browser. Nothing is uploaded or sent.
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.
Two parties, controlled
Choose a party and a page, add fields, drag them. The JSON below is what onChange gives.
Arrow keys move the field, Shift with arrow keys changes its size, Delete removes it.
Loading document…
Fields (1)
{
"fields": [
{
"id": "client-signature-1",
"type": "signature",
"party": "client",
"page": 2,
"rect": [
0.1,
0.62,
0.35,
0.07
]
}
]
}import { useState } from "react";
import { FieldEditor, type EditorField, type PdfjsLib } from "@signnative/ui";
import "@signnative/ui/styles.css";
// pdf.js is not a dependency of the package: pass it in. Serve its worker yourself.
const loadPdfjs = () => import("pdfjs-dist/legacy/build/pdf.mjs") as unknown as Promise<PdfjsLib>;
export function Example({ pdf }: { pdf: Uint8Array | null }) {
const [fields, setFields] = useState<EditorField[]>([
{ id: "client-signature-1", type: "signature", party: "client", page: 2, rect: [0.1, 0.62, 0.35, 0.07] },
]);
return (
<FieldEditor
data={pdf}
pdfjs={loadPdfjs}
workerSrc="/pdf.worker.min.mjs"
parties={[
{ id: "client", label: "Client" },
{ id: "provider", label: "Provider" },
]}
fields={fields}
onChange={setFields}
/>
);
}
One party, two field types, no snapping
Arrow keys move the field, Shift with arrow keys changes its size, Delete removes it.
Loading document…
Fields (0)
No fields yet. Choose a party and a page, then add a field.
import { FieldEditor, type PdfjsLib } from "@signnative/ui";
import "@signnative/ui/styles.css";
// pdf.js is not a dependency of the package: pass it in. Serve its worker yourself.
const loadPdfjs = () => import("pdfjs-dist/legacy/build/pdf.mjs") as unknown as Promise<PdfjsLib>;
export function Example({ pdf }: { pdf: Uint8Array | null }) {
return <FieldEditor data={pdf} pdfjs={loadPdfjs} parties={[{ id: "signer", label: "Signer" }]} types={["signature", "date"]} grid={0} />;
}
Installation
npx shadcn@latest add <site>/r/field-editor.json
Not published yet
API
className and children are left out: every component that takes them passes them on.
FieldEditor
| Name | Type | Default | Description |
|---|---|---|---|
| parties | EditorParty[] | The parties (roles) fields can belong to. At least one. | |
| fields | EditorField[] | Controlled fields. Leave it out to let the editor keep its own. | |
| defaultFields | EditorField[] | Uncontrolled start value, read once. | |
| onChange | (fields: EditorField[]) => void | Every field after each change, in the shape of an agreement file's fields. | |
| types | readonly EditorFieldType[] | all four | Field types that can be added. |
| grid | number | 0.005 | Fields snap to this grid, a fraction of the page. 0 turns snapping off. |
| data | ArrayBuffer | Uint8Array | null | The PDF, as for PdfViewer. | |
| pdfjs | PdfjsLib | (() => Promise<PdfjsLib>) | pdf.js, as for PdfViewer. | |
| workerSrc | string | As for PdfViewer. | |
| assetsUrl | string | As for PdfViewer. | |
| pageWidth | number | As for PdfViewer. | |
| maxWidth | number | 820 | As for PdfViewer. |
| textLayer | boolean | true | As for PdfViewer. |
| onPagesMeasured | (sizes: PdfPageSize[]) => void | Once, with every page's size in PDF points. | |
| labels | Partial<FieldEditorLabels> | English | Every text, for translation. |
Accessibility
- Each field on the page has a name with its type, party, page and position.
- Arrow keys move a field, Shift with arrow keys changes its size, Delete removes it. Changes are announced.