LedgerUI.Components.Email (LedgerUI v0.2.0)

Copy Markdown View Source

Ledger UI's transactional e-mail: one layout for the e-mails a system sends (a sign-in code, a reset link, an order update): the logo, a card with an icon badge, an eyebrow, a title, text, a block of code, facts or steps, a main button with its address spelled out, a note and a footer. 520px wide.

<.email_layout subject="Your code" preheader="Valid for 10 minutes" brand="Acme"
               logo_url="https://acme.com/logo.png" eyebrow="Confirm your access" title="Your verification code">
  <:body>
    <.email_p>Hi <b>Ana</b>. Type this code on the sign-in screen.</.email_p>
    <.email_code value="482913" />
  </:body>
  <:action href="https://app.acme.com/confirm?token=7f3a9c">Sign in</:action>
  <:note>Not you? Ignore this e-mail.</:note>
  <:footer>Acme Ltda</:footer>
</.email_layout>

It renders a whole HTML document built for mail clients: tables for the structure, every style inline, web-safe font stacks, no script. The only <style> carries the resets, the mobile padding and the dark mode: with theme={:auto} (the default) the e-mail follows prefers-color-scheme; :light and :dark fix it. Every color is also on a hook class (em-*) that the dark block overrides with !important. Icons and logos are images with an absolute URL.

Deliver it as the html_body of your mailer (Phoenix.HTML.Safe.to_iodata/1 of the rendered component). The helpers (email_p/1, email_code/1, email_facts/1, email_steps/1) draw the light palette; with a fixed theme={:dark} layout pass theme={:dark} to them too.

variant="preview"

The default variant="document" is the mail document above. variant="preview" is the canvas picture of an e-mail for the documentation and the showcase: a page fragment (not a document, no tables) with a tray background, a panel with the brand mark and brand, the title, the :body, the :action as a primary button, a line and the :footer in small muted text. It uses the stylesheet classes, so it follows the theme of the page; do not send it as an e-mail.

Summary

Functions

A verification code, one box per character.

Rows of label and value: {label, value}, {label, value, :mono} or {label, value, :total}.

A paragraph of the e-mail body, styled for mail clients.

A row of steps: {label, done?} pairs, in order. Done ones are filled with a check.

Functions

email_code(assigns)

A verification code, one box per character.

Attributes

  • value (:string) (required)
  • hint (:string) - Defaults to nil.
  • theme (:atom) - Defaults to :auto. Must be one of :auto, :light, or :dark.

email_facts(assigns)

Rows of label and value: {label, value}, {label, value, :mono} or {label, value, :total}.

Attributes

  • rows (:list) (required)
  • theme (:atom) - Defaults to :auto. Must be one of :auto, :light, or :dark.
  • variant (:string) - Defaults to "panel". Must be one of "panel", or "table".
  • header (:any) - Defaults to nil.

email_layout(assigns)

Attributes

  • subject (:string) (required)
  • preheader (:string) - Defaults to nil.
  • brand (:string) - Defaults to nil.
  • logo_url (:string) - Defaults to nil.
  • logo_dark_url (:string) - Defaults to nil.
  • eyebrow (:string) - Defaults to nil.
  • title (:string) (required)
  • theme (:atom) - Defaults to :auto. Must be one of :auto, :light, or :dark.
  • lang (:string) - Defaults to "en".
  • alt_text (:any) - Defaults to "If the button does not work, copy and paste this address into your browser:".
  • button (:string) - Defaults to "accent". Must be one of "accent", or "ink".
  • footer_style (:string) - Defaults to "panel". Must be one of "panel", or "plain".
  • title_size (:integer) - Defaults to 22.
  • compact (:boolean) - Defaults to false.
  • variant (:string) - preview is the canvas picture of an e-mail (a page fragment, not for sending). Defaults to "document". Must be one of "document", or "preview".

Slots

  • action - Accepts attributes:
    • href (:string) (required)
  • badge
  • body (required)
  • footer
  • note - Accepts attributes:
    • icon (:string)
  • secondary - Accepts attributes:
    • href (:string)

email_p(assigns)

A paragraph of the e-mail body, styled for mail clients.

Attributes

  • theme (:atom) - Defaults to :auto. Must be one of :auto, :light, or :dark.
  • muted (:boolean) - Defaults to false.
  • Global attributes are accepted.

Slots

  • inner_block (required)

email_steps(assigns)

A row of steps: {label, done?} pairs, in order. Done ones are filled with a check.

Attributes

  • steps (:list) (required)
  • theme (:atom) - Defaults to :auto. Must be one of :auto, :light, or :dark.