LedgerUI.Components.Alert (LedgerUI v0.2.0)

Copy Markdown View Source

Persistent inline notice with colour, variant, shape, accent stripe, actions and a close button.

<.alert color="warning" variant="soft">
  <:icon><.icon name="alert" /></:icon>
  <div class="t"><b>Certificate expires in 12 days</b><span>Renew it to keep issuing.</span></div>
  <:action><button class="lu-b c-warning v-soft s-xs sh-rounded" type="button">Renew</button></:action>
</.alert>

<.alert id="saved" color="success" dismissible on_dismiss="hide_notice">Changes saved.</.alert>

A short notice can use title and description instead: <.alert color="warning" title="Certificate expires" description="Renew it." />. The content is yours: write <div class="t"><b>Title</b><span>Text</span></div> for the title-plus-line layout. The close button hides the alert in the browser (no round trip) and, with on_dismiss, tells the server (%{"id" => id}). dismiss_alert/1 does the same for a button placed by hand: <button phx-click={dismiss_alert()}>Later</button>.

Summary

Functions

JS command that fades out and hides the alert around the element that runs it.

Functions

alert(assigns)

Attributes

  • id (:string) - Defaults to nil.
  • color (:string) - Defaults to "neutral". Must be one of nil, "neutral", "primary", "secondary", "info", "success", "warning", "error", or "dark".
  • variant (:string) - Defaults to "canvas". Must be one of nil, "canvas", "solid", "outline", "soft", or "bordered".
  • shape (:string) - Defaults to "rounded". Must be one of "rounded", or "pill".
  • accent (:any) - The colored stripe: top (or just accent), left, right. Defaults to nil. Must be one of nil, "", true, "top", "left", or "right".
  • description (:string) - The line under the title (title="..."): written as <div class="t"><b>title</b><span>description</span></div>. Defaults to nil.
  • dismissible (:boolean) - Defaults to false.
  • on_dismiss (:any) - Event name or %JS{} run when the alert is closed. Defaults to nil.
  • target (:any) - phx-target of on_dismiss. Defaults to nil.
  • close_label (:string) - Defaults to "Close".
  • open (:boolean) - Defaults to true.
  • class (:any) - Defaults to nil.
  • Global attributes are accepted.

Slots

  • action - Controls after the content.
  • icon - Icon before the content. Accepts attributes:
    • boxed (:boolean)
  • inner_block

dismiss_alert(js \\ %JS{})

@spec dismiss_alert(Phoenix.LiveView.JS.t()) :: Phoenix.LiveView.JS.t()

JS command that fades out and hides the alert around the element that runs it.

<button phx-click={dismiss_alert()}>Remind me later</button>