Alert
color (8) × variant canvas/solid/outline/soft/bordered · shape pill · accent · action · dismissible
A persistent inline notice with color, variant, shape, an accent stripe, an action and a close button.
Alert entering
<div class="animate-[mo-alin_6s_cubic-bezier(.2,.8,.2,1)_infinite]"><.alert color="warning" variant="soft" class="gap-2.5!"><:icon><.icon name="alert" /></:icon><span><b>Certificado vence em 3 dias.</b> Renove para continuar emitindo.</span></.alert></div>
color × variant
<div class="grid grid-cols-[70px_repeat(8,minmax(0,1fr))] items-center gap-x-3 gap-y-2.5"> <span></span> <span :for={c <- ~w(neutral primary secondary info success warning error dark)} class="text-center font-mono text-xs text-muted">{c}</span> <%= for v <- ~w(canvas soft bordered outline solid) do %> <span class="font-mono text-xs text-muted">{v}</span> <div :for={{c, icon} <- [{"neutral", "info"}, {"primary", "sparkles"}, {"secondary", "ai"}, {"info", "info"}, {"success", "check-circle"}, {"warning", "alert"}, {"error", "x-circle"}, {"dark", "info"}]} class="flex min-w-0 justify-center"> <.alert color={c} variant={v} title={String.capitalize(c)} description="Contexto curto."><:icon><.icon name={icon} /></:icon></.alert> </div> <% end %> </div>
shape="pill"
<.alert color="info" variant="soft" shape="pill" title="Dados de demonstração" description="Workspace com dados gerados."><:icon><.icon name="info" /></:icon></.alert>
accent · action · dismissible
<.alert color="warning" variant="canvas" accent="" dismissible close_label="Fechar" title="7 de 11 cancelamentos Pro vieram de falha de pagamento" description="Revise a régua de cobrança."> <:icon><.icon name="alert" /></:icon> <:action><.button color="warning" variant="soft" size="xs">Ação</.button></:action> </.alert>
API values that complete the parity
<div class="grid grid-cols-2 gap-3.5"> <div :for={a <- ~w(left right)} class="flex flex-col items-start gap-1.5"><.alert color="warning" variant="soft" accent={a} class="w-full">Certificado vence em 3 dias</.alert><span class="font-mono text-[11px] text-muted">accent={a}</span></div> </div>
Usage
<.alert color="warning" variant="soft" title="Pagamento pendente">…<:action>…</:action></.alert> <.alert color="error" variant="canvas" dismissible on_dismiss="hide">…</.alert>
Rules
canvas(default): a white panel with a colored icon;soft/bordered: a tonal background;solid: a full background;outline: outline only.shape="pill"for a single line;accentadds the color stripe (on top, no side border).- A short title + one sentence + at most one action.
API reference
Todos os function components, atributos, valores e slots que este componente cobre.
Persistent inline notice with colour, variant, shape, accent stripe, actions and a close button.
Styled only with Tailwind utilities (the colour enters as --c/--c-on/--c-soft/--c-ink, see
LedgerUI.Color).
<.alert color="warning" variant="soft" title="Certificate expires in 12 days"
description="Renew it to keep issuing.">
<:icon><.icon name="alert" /></:icon>
<:action><.button color="warning" variant="soft" size="xs">Renew</.button></:action>
</.alert>
<.alert id="saved" color="success" dismissible on_dismiss="hide_notice">Changes saved.</.alert>
loop plays the canvas loop of the alert entering (mo-alin, CSS only).
title is the bold line and description the line under it; any other content goes in the
inner block (a <b> inside it is bold too). 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>.
<.alert>
| Attr | Type | Default | Values / notes |
|---|---|---|---|
id |
:string |
nil |
|
color |
:string |
"neutral" |
nil, neutral, primary, secondary, info, success, warning, error, dark |
variant |
:string |
"canvas" |
nil, canvas, solid, outline, soft, bordered |
shape |
:string |
"rounded" |
rounded, pill |
accent |
:any |
nil |
nil, `,true,top,left,right- The colored stripe:top(or justaccent),left,right`. |
description |
:string |
nil |
The line under the title (title="..."). |
dismissible |
:boolean |
false |
|
on_dismiss |
:any |
nil |
Event name or %JS{} run when the alert is closed. |
target |
:any |
nil |
phx-target of on_dismiss. |
close_label |
:string |
"Close" |
|
open |
:boolean |
true |
|
loop |
:boolean |
false |
The canvas loop (mo-alin): the alert slides in, stays, leaves, forever (demos). |
class |
:any |
nil |
Any other HTML/phx attribute goes to the root element.
Slots:
<:action>- Controls after the content.<:icon>- attrs:boxed- Icon before the content.<:inner_block>