SignaturePad
mode draw/type · variant canvas/classic · clear/undo
Handwritten signature capture for contracts.
Signing
<.signature_pad id="sig1" name="sig1" modes={["draw"]} variant="classic" height={140} footer={false} class="max-w-[420px]" />
mode draw · type × variant canvas/classic
<div class="flex flex-wrap items-start gap-2.5"> <.signature_pad id="sig2a" name="sig2a" modes={["draw"]} variant="classic" height={140} footer={false} class="w-[300px]" wrapper_class="w-[300px]" value={~s(<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 420 140"><path d="M30 92 C 50 40, 70 40, 66 88 C 64 110, 90 60, 110 66 C 130 72, 116 96, 140 88 C 170 78, 160 50, 190 60 C 210 66, 200 94, 230 86 C 260 78, 270 60, 300 70" fill="none" stroke="#000"/></svg>)} /> <.signature_pad id="sig2b" name="sig2b" mode="type" modes={["type"]} variant="classic" text="Ana Nogueira" name_input={false} height={140} footer={false} class="w-[300px]" wrapper_class="w-[300px]" /> </div>
Usage
<.signature_pad field={@form[:signature]} />
Rules
- Dashed baseline; Clear and Confirm buttons below.
API reference
Todos os function components, atributos, valores e slots que este componente cobre.
A signature field: sign with a finger, a pen or the mouse (pointer events), or type a name that is set in a handwriting font. The signature leaves as SVG text.
<.signature_pad field={@form[:signature]} label="Signature" />
<.signature_pad name="receipt" mode="type" text="Marcos Oliveira" locale="pt_BR" />
<.signature_pad name="sign" modes={["draw"]} height={220} />
The form gets the SVG (<svg xmlns=... viewBox="0 0 W H"><path .../></svg>, "" while the pad
is empty) through a hidden input named like the field, and every stroke, typed letter or Clear
fires a bubbling input event from it. The drawing surface is client-owned
(phx-update="ignore"
role="img"
aria-label={@l.signature_area}); the hook LedgerUI.SignaturePad
(priv/static/ledger_ui/hooks/signature_pad.js) redraws it when the server sends another
value. Show a saved signature elsewhere as an image, never as raw markup:
<img src={"data:image/svg+xml;base64," <> Base.encode64(@signature)} alt="Signature" />
confirm (a label) and on_confirm add a "confirm" button to the footer, as in the design.
<.signature_pad>
Renders the signature pad.
| Attr | Type | Default | Values / notes |
|---|---|---|---|
id |
:string |
nil |
|
name |
:string |
nil |
|
value |
:string |
||
field |
{:struct, Phoenix.HTML.FormField} |
nil |
|
label |
:string |
nil |
|
label_class |
:any |
nil |
|
help |
:string |
nil |
|
errors |
:list |
[] |
|
mode |
:string |
"draw" |
draw, type |
modes |
:list |
["draw", "type"] |
|
text |
:string |
"" |
|
name_input |
:boolean |
true |
Show the field to type the name in type mode. false draws the typed text alone in the surface (a read-only display, as in the design's canvas). |
ink |
:string |
"#0F172A" |
|
height |
:integer |
170 |
|
locale |
:string |
"en" |
en, pt_BR |
labels |
:map |
%{} |
|
disabled |
:boolean |
false |
|
variant |
:string |
"canvas" |
canvas, classic |
footer |
:boolean |
true |
|
confirm |
:string |
nil |
Label of a confirm button in the footer. |
on_confirm |
:string |
nil |
|
on_change |
:string |
nil |
|
target |
:any |
nil |
|
wrapper_class |
:any |
nil |
|
class |
:any |
nil |
Any other HTML/phx attribute goes to the root element.