Alert
An in-page box that shows the result of an action, a situation that needs attention or a persistent error.
zb:alert zubazar/ui · free (MIT)
Variants
Pick the color and icon with variant: info (default) for information, success for success, warning for attention, danger for errors.
<zb:alert variant="info">The October campaign calendar is out.</zb:alert>
<zb:alert variant="success">The October campaign calendar is out.</zb:alert>
<zb:alert variant="warning">The October campaign calendar is out.</zb:alert>
<zb:alert variant="danger">The October campaign calendar is out.</zb:alert>
<zb:alert variant="primary">The October campaign calendar is out.</zb:alert>
<zb:alert variant="secondary">The October campaign calendar is out.</zb:alert>
<zb:alert variant="dark">The October campaign calendar is out.</zb:alert>
| Prop | Values |
|---|---|
variant | primary | secondary | success | danger | warning | info | dark (default info) |
With a title
title adds a bold heading line on top; in alerts with a list or longer text, put the gist of the message there.
<zb:alert variant="danger" title="The import could not be completed">
<ul class="list-disc space-y-1 ps-4">
<li>Row 12: SKU is missing.</li>
<li>Row 27: category code (ELK-09) not found.</li>
</ul>
</zb:alert>
| Prop | Values |
|---|---|
title | Bold heading line; when empty, only the content is shown |
Dismissible
dismissible adds a close button at the top right; the alert is hidden only in the browser and comes back on reload.
<zb:alert variant="warning" dismissible>
4 team members are using an old version of the mobile app.
</zb:alert>
| Prop | Values |
|---|---|
dismissible | true | false |
Dismissing with Livewire
dismiss-action also calls a Livewire method on close, so you can mark the announcement as read on the server.
@if ($announcement)
<zb:alert title="{{ $announcement->title }}" dismiss-action="dismissAnnouncement">
{{ $announcement->body }}
</zb:alert>
@endif
| Prop | Values |
|---|---|
dismiss-action | Name of the Livewire method (e.g. dismissAnnouncement) |
Props
The values the component takes. What are props and slots?
| Prop | Type | Default | Description |
|---|---|---|---|
variant | — | info | info (sky) · success (emerald) · warning (amber) · danger (red); an unknown value falls back to info |
title | — | null | Bold heading line |
dismissible | boolean | false | Close button; hides the alert only in the browser |
dismiss-action | — | null | Livewire method called on close; when given, the close button is added as well |
Slots: default: the alert text (may be HTML) or the zb:alert.title and zb:alert.description parts.
Advanced
Rich content
The slot accepts free-form HTML: add a link, bold text or a small button. The text color comes from the variant; make links stand out with underline.
<zb:alert variant="info" title="A new version is ready">
<p>Version <strong>2.4</strong> of the mobile app supports recording orders offline.</p>
<div class="mt-3 flex flex-wrap items-center gap-3">
<zb:button size="sm">Start the update</zb:button>
<a href="#" class="font-medium underline underline-offset-2 hover:no-underline">Release notes</a>
</div>
</zb:alert>
Accessibility note
Give an important error that appears later role="alert", and screen readers announce it at once. Alerts present when the page loads read like ordinary text.
<zb:alert variant="danger" role="alert">Your session has expired. Please sign in again.</zb:alert>
| Prop | Values |
|---|---|
role | alert (urgent) | status (informational) |
Title and description parts
When the alert content includes a list, a link or a button, use the zb:alert.title and zb:alert.description parts; the icon, color and close button stay the same.
<zb:alert variant="warning" dismissible>
<zb:alert.title>3 shipments are delayed</zb:alert.title>
<zb:alert.description>
<ul class="list-disc space-y-0.5 ps-4">
<li>Kadıköy warehouse: 2 orders, estimated 1 day delay</li>
<li>Üsküdar warehouse: 1 order, address could not be verified</li>
</ul>
<div class="mt-3 flex flex-wrap gap-2">
<zb:button size="sm" variant="warning">Reschedule the shipment</zb:button>
<zb:button size="sm" variant="white">Call the carrier</zb:button>
</div>
</zb:alert.description>
</zb:alert>
<zb:alert variant="success" class="mt-4">
<zb:alert.title>Campaign published</zb:alert.title>
<zb:alert.description>
The 12-product campaign was emailed to 486 customers.
<a href="#" class="font-medium underline underline-offset-2">View the campaign</a>
</zb:alert.description>
</zb:alert>
Developer notes
- For messages that should disappear after a few seconds, use a toast (
zb:toast-container). - When
dismiss-actionis given, the close button appears even withoutdismissible.
Accessibility
- ARIA and roles
- The alert box has no
role; it reads as ordinary page content. The coloured icon is hidden from screen readers (aria-hidden). - Live announcements
- For an alert added later that must be announced at once, add
role="alert", orrole="status"for a polite one; attributes go on the box. For short-lived messages usezb:toast-container. - Dismissing
dismissibleadds a "Close" button in the tab order. Closing hides the box and does not move focus anywhere.- What you provide
- Do not rely on colour alone: put a word such as "Error" or "Warning" in the title or text.
titlerenders a bold paragraph, not a heading; add a heading yourself if the page structure needs one.