LedgerUI.Components.SignaturePad (LedgerUI v0.2.0)

Copy Markdown View Source

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.

Summary

Functions

Renders the signature pad.

Functions

signature_pad(assigns)

Renders the signature pad.

Attributes

  • id (:string) - Defaults to nil.
  • name (:string) - Defaults to nil.
  • value (:string)
  • field (Phoenix.HTML.FormField) - Defaults to nil.
  • label (:string) - Defaults to nil.
  • label_class (:any) - Defaults to nil.
  • help (:string) - Defaults to nil.
  • errors (:list) - Defaults to [].
  • mode (:string) - Defaults to "draw". Must be one of "draw", or "type".
  • modes (:list) - Defaults to ["draw", "type"].
  • text (:string) - Defaults to "".
  • ink (:string) - Defaults to "#0F172A".
  • height (:integer) - Defaults to 170.
  • locale (:string) - Defaults to "en". Must be one of "en", or "pt_BR".
  • labels (:map) - Defaults to %{}.
  • disabled (:boolean) - Defaults to false.
  • variant (:string) - Defaults to "canvas". Must be one of "canvas", or "classic".
  • footer (:boolean) - Defaults to true.
  • confirm (:string) - Label of a confirm button in the footer. Defaults to nil.
  • on_confirm (:string) - Defaults to nil.
  • on_change (:string) - Defaults to nil.
  • target (:any) - Defaults to nil.
  • wrapper_class (:any) - Defaults to nil.
  • class (:any) - Defaults to nil.
  • Global attributes are accepted.