Alert

The alert component serves as a notification mechanism to provide feedback to the user.

Read more Read less

For supplementary information that doesn't require the user's immediate attention, use callout/1 instead.

Maturity: Developing

Usage

Minimal example:

<.alert id="some-alert"></.alert>

With title, icon and level:

<.alert id="some-alert" level={:info}>
  <:title>Info</:title>
  message
  <:icon><Heroicon.light_bulb /></:icon>
</.alert>

Dismissable:

<.alert id="some-alert" on_close={JS.push("dismiss")}>
  message
</.alert>

The close button's name and content are set in the build call:

build_alert(close_label: gettext("Dismiss"), close: ~H|<Heroicon.x_mark />|)

With an action:

<.alert id="some-alert">
  <:title>Session expired</:title>
  Your session has expired. Sign in again to continue.
  <:action>
    <.button phx-click="sign-in">Sign in</.button>
  </:action>
</.alert>

The close_label is the button's accessible name, so it is needed whether or not close is set.

Attribute Type Documentation Default Value
class :any

Any additional classes to be added.

Read more Read less
[]

Variations of the component should be expressed via modifier attributes, and it is preferable to use styles on the parent container to arrange components on the page, but if you have to, you can use this attribute to pass additional utility classes to the component.

The value can be a string or a list of strings.

Required id * :string
level :string "info"
on_close :any

Phoenix.LiveView.JS command or event name to run when the close button

Read more Read less

is clicked. If not set, no close button is rendered.

rest :global

Any additional HTML attributes.

action :slot

A slot for action buttons related to the alert, rendered after the message.

<:action><.button type="button">Sign in</.button></:action>
icon :slot

Optional slot to render an icon.

Required inner_block * :slot

The main content of the alert.

Your session has expired. Sign in again to continue.
title :slot

An optional title.

<:title>Session expired</:title>