Alert
A callout for short, important messages with semantic variants.
Preview
Heads up
<x-ui.alert class="w-full max-w-md text-start">
<x-ui.alert.title>{{ __('Heads up') }}</x-ui.alert.title>
<x-ui.alert.description>{{ __('You can add components to your app using the CLI.') }}</x-ui.alert.description>
</x-ui.alert>
Installation
php artisan ui:add alert
Registry contract
php artisan ui:add alert
writes only the files below. The CLI validates each file hash before writing and asks before it replaces a local change, unless you pass --force.
-
resources/views/components/ui/alert.blade.php -
resources/views/components/ui/alert/title.blade.php -
resources/views/components/ui/alert/description.blade.php
- Registry dependencies
- None — installs on its own.
- Packages
-
composer: jml/brok:^0.2
Use with AI
A brief for your coding agent: install command, usage, props, guidance and the rules. Copy it, or open a prompt about this component in an assistant.
# Brok UI: Alert (`alert`)
A callout for short, important messages with semantic variants.
Brok UI is a Laravel Blade component registry. Installed components are plain Blade files the app owns.
## Install
```bash
php artisan ui:add alert
```
## Usage
```blade
<x-ui.alert class="w-full max-w-md text-start">
<x-ui.alert.title>{{ __('Heads up') }}</x-ui.alert.title>
<x-ui.alert.description>{{ __('You can add components to your app using the CLI.') }}</x-ui.alert.description>
</x-ui.alert>
```
## Props
- `variant` (default|destructive|success|warning|info, default `default`) — Semantic tone: default, info, success, warning, or destructive.
- `icon` (bool, default `true`) — Leading icon: true shows the variant's glyph, the icon slot overrides it, false hides it.
- `dismissible` (bool, default `false`) — Adds a close button that hides the alert and dispatches alert:dismiss.
- `role` (string, default `alert`) — ARIA role: alert for assertive announcement, status for a polite outcome, region or none for a static callout.
## Use when
- Use for important messages that should stay visible long enough to read and act on.
- Surfacing a short, important message inline with the page, such as a form-level error or a success confirmation.
- Needing a semantic tone (default, info, success, warning, destructive) with a consistent icon and layout.
## Avoid when
- Do not downgrade important guidance into transient messaging users can miss.
- Needing a transient, auto-dismissing notification detached from the page flow; use toaster instead.
- Announcing a page-wide incident or maintenance notice; use system-banner instead.
## Anti-patterns
- Downgrading important outcomes to transient feedback
## Rules
- Use the `<brok:alert>` tag (or `<x-ui.alert>`) in Blade; do not rewrite the component.
- Prefer the documented props and variants over utility-class overrides; when a utility must win, use the `!` important modifier.
- Use semantic design tokens (`bg-primary`, `text-muted-foreground`), never raw colour utilities.
- Keep the `data-slot` attributes; they are the styling and test hooks.
## Links
- Docs: https://brokui.dev/docs/components/alert
- Registry JSON (files, props, contract): https://brokui.dev/r/open/alert.json
Working in Claude Code, Cursor or Codex? Give the agent the whole registry through the MCP server or the Brok UI skill.
Examples
{{-- The `actions` slot: buttons or links that act on the message sit under
the text, start-aligned with it, and wrap when the alert is narrow. It
works with every tone and with a dismissible alert; the close button
stays in the top end corner. --}}
<div class="flex w-full max-w-lg flex-col gap-4 text-start">
<x-ui.alert variant="warning" role="status">
<x-ui.alert.title>{{ __('Revision 4 was saved while you edited') }}</x-ui.alert.title>
<x-ui.alert.description>{{ __('Review the newer revision before you save, or keep your changes as a new revision.') }}</x-ui.alert.description>
<x-slot:actions>
<x-ui.button size="sm">{{ __('Review revision 4') }}</x-ui.button>
<x-ui.button size="sm" variant="outline">{{ __('Keep my changes') }}</x-ui.button>
</x-slot:actions>
</x-ui.alert>
<x-ui.alert variant="info" role="status" dismissible>
<x-ui.alert.title>{{ __('A new export format is available') }}</x-ui.alert.title>
<x-ui.alert.description>{{ __('Skills can now export as a single archive.') }}</x-ui.alert.description>
<x-slot:actions>
<x-ui.button size="sm" variant="outline">{{ __('Try it') }}</x-ui.button>
<x-ui.button size="sm" variant="link" href="#">{{ __('Read the notes') }}</x-ui.button>
</x-slot:actions>
</x-ui.alert>
<div class="max-w-72" dir="rtl">
<x-ui.alert variant="destructive">
<x-ui.alert.title>{{ __('The export failed') }}</x-ui.alert.title>
<x-ui.alert.description>{{ __('Two sources could not be read.') }}</x-ui.alert.description>
<x-slot:actions>
<x-ui.button size="sm" variant="destructive">{{ __('Try again') }}</x-ui.button>
<x-ui.button size="sm" variant="outline">{{ __('Show the sources') }}</x-ui.button>
</x-slot:actions>
</x-ui.alert>
</div>
</div>
<div class="w-full max-w-md space-y-3 text-start">
<x-ui.alert>
<x-ui.alert.title>{{ __('Heads up') }}</x-ui.alert.title>
<x-ui.alert.description>{{ __('A neutral, informational message.') }}</x-ui.alert.description>
</x-ui.alert>
<x-ui.alert variant="success">
<x-ui.alert.title>{{ __('Changes saved') }}</x-ui.alert.title>
<x-ui.alert.description>{{ __('Your profile is up to date.') }}</x-ui.alert.description>
</x-ui.alert>
<x-ui.alert variant="warning">
<x-ui.alert.title>{{ __('Trial ends in three days') }}</x-ui.alert.title>
<x-ui.alert.description>{{ __('Add a payment method to keep your workspace.') }}</x-ui.alert.description>
</x-ui.alert>
<x-ui.alert variant="destructive">
<x-ui.alert.title>{{ __('Payment failed') }}</x-ui.alert.title>
<x-ui.alert.description>{{ __('Your card was declined. Update it and try again.') }}</x-ui.alert.description>
</x-ui.alert>
<x-ui.alert variant="info" dismissible>
<x-ui.alert.title>{{ __('A new version is available') }}</x-ui.alert.title>
<x-ui.alert.description>{{ __('Reload to get the latest features.') }}</x-ui.alert.description>
</x-ui.alert>
<x-ui.alert :icon="false">
<x-ui.alert.title>{{ __('No icon') }}</x-ui.alert.title>
<x-ui.alert.description>{{ __('Pass :icon="false" for a plain callout.') }}</x-ui.alert.description>
</x-ui.alert>
</div>
API
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| variant | default | destructive | success | warning | info | default | Semantic tone: default, info, success, warning, or destructive. |
| icon | bool | true | Leading icon: true shows the variant's glyph, the icon slot overrides it, false hides it. |
| dismissible | bool | false | Adds a close button that hides the alert and dispatches alert:dismiss. |
| role | string | alert | ARIA role: alert for assertive announcement, status for a polite outcome, region or none for a static callout. |
Slots
default— Alert body content, typically title and description sub-components.actions— Buttons or links that act on the message (data-slot="alert-actions"). They sit under the text, start-aligned with it, with an 8px gap, and wrap on a narrow alert. Attributes on the slot tag merge onto the row.x-ui.alert.title— Installed subcomponent from the registry item.x-ui.alert.description— Installed subcomponent from the registry item.
Data slots
Stable hooks for CSS overrides and browser tests.
Behavior
- Renders as a static callout by default; dismissible adds a close button that hides the alert and dispatches alert:dismiss.
- The actions slot renders a wrapping row of buttons or links under the title and description, inside the text column: it keeps the icon and the dismiss button in their places, mirrors under dir="rtl" and works with every tone.
- The ARIA role defaults to alert for immediate announcement; switch to status for a polite outcome message or none for a static callout.
- Static semantic alert surface with consumer-owned announcement timing.
- Declares registry capability flags: a11y, responsive, rtl, darkMode, localized.
Guidance
Keep an important message visible near its context.
Use when
- Use for important messages that should stay visible long enough to read and act on.
- Surfacing a short, important message inline with the page, such as a form-level error or a success confirmation.
- Needing a semantic tone (default, info, success, warning, destructive) with a consistent icon and layout.
Avoid when
- Do not downgrade important guidance into transient messaging users can miss.
- Needing a transient, auto-dismissing notification detached from the page flow; use toaster instead.
- Announcing a page-wide incident or maintenance notice; use system-banner instead.
Use instead
- Toast for low-priority confirmation
Anti-patterns
- Downgrading important outcomes to transient feedback
- Anatomy
- Theming hooks
Accessibility
- Keyboard
- native
- Focus
native
- Keep role="alert" only for messages that need immediate attention; overuse interrupts screen reader users.
- The dismiss button carries an accessible label so keyboard and screen reader users can close the alert.
- Semantic HTML and a stable
data-slotattribute for styling and scripting hooks. - Focus-visible rings use the
ringtoken, so keyboard focus is always visible. - Disabled and invalid states are conveyed to assistive tech, not by color alone.
- Targets WCAG 2.2 AA; verify contrast in light, dark, admin and customer surfaces in the preview.
- Labels go through
__()and layout uses logical properties (ms-*,text-start), so it mirrors underdir="rtl"— flip the preview to RTL to confirm. - Dark mode uses the same semantic tokens under the
darkclass; high contrast follows forced-color system tokens.
Livewire
Add a stable wire:key when Livewire can reorder this interactive component.
<div wire:key="alert-{{ $record->id }}">
<x-ui.alert class="w-full max-w-md text-start">
<x-ui.alert.title>{{ __('Heads up') }}</x-ui.alert.title>
<x-ui.alert.description>{{ __('You can add components to your app using the CLI.') }}</x-ui.alert.description>
</x-ui.alert>
</div>
Validation
Validation support: native. Keep the error message connected with aria-describedby.
<form wire:submit="save" class="space-y-2">
<brok:alert
wire:model="value"
:aria-invalid="$errors->has('value') ? 'true' : 'false'"
aria-describedby="value-error"
/>
@error('value')
<p id="value-error" role="alert">{{ $message }}</p>
@enderror
<brok:button type="submit" wire:loading.attr="disabled">
<span wire:loading.remove>Save</span>
<span wire:loading>Saving…</span>
</brok:button>
</form>
Source
The exact, editable files ui:add writes
into your app. Previews render this same code; there are no preview-only components.
@props([
'variant' => 'default',
// Leading icon: the variant's default glyph, an <svg> via the `icon` slot,
// or false for none.
'icon' => true,
// Renders a close button; the alert hides itself and dispatches `alert:dismiss`.
'dismissible' => false,
// ARIA role: `alert` (assertive) for a problem that needs attention now,
// `status` (polite) for an outcome banner such as "Saved", `region` or
// `none` for a static callout that is not a live region.
'role' => 'alert',
])
@php
$styles = require base_path(config('ui.component_path', 'resources/views/components/ui').'/_styles.php');
$variant = $styles['normalizeVariant']($variant);
$alert = $styles['alert'];
$classes = trim($alert['base'].' '.($alert['variants'][$variant] ?? $alert['variants']['default']));
$tone = $alert['tones'][$variant] ?? $alert['tones']['default'];
$showIcon = ! ($icon === false || $icon === 'false' || $icon === '0');
// Optional named slot: buttons or links that act on the message. They sit
// under the text, start-aligned with it, and wrap on a narrow alert.
$hasActions = ($actions ?? null) instanceof \Illuminate\View\ComponentSlot && trim((string) $actions) !== '';
$iconIsSlot = $icon instanceof \Illuminate\View\ComponentSlot && ! $icon->isEmpty();
$glyphs = [
'default' => '<circle cx="12" cy="12" r="10" /><path d="M12 16v-4M12 8h.01" />',
'info' => '<circle cx="12" cy="12" r="10" /><path d="M12 16v-4M12 8h.01" />',
'success' => '<circle cx="12" cy="12" r="10" /><path d="m9 12 2 2 4-4" />',
'warning' => '<path d="m21.7 18-8-14a2 2 0 0 0-3.4 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.7-3" /><path d="M12 9v4M12 17h.01" />',
'destructive' => '<circle cx="12" cy="12" r="10" /><path d="m15 9-6 6M9 9l6 6" />',
];
@endphp
<div
data-slot="alert"
data-variant="{{ $variant }}"
@if ($role !== 'none' && $role !== false) role="{{ $role }}" @endif
@if ($dismissible) x-data="{ open: true }" x-show="open" @endif
{{ $attributes->merge(['class' => $classes]) }}
>
@if ($showIcon)
<span data-slot="alert-icon" class="mt-px shrink-0 {{ $tone }} [&>svg]:size-4" aria-hidden="true">
@if ($iconIsSlot)
{{ $icon }}
@else
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">{!! $glyphs[$variant] ?? $glyphs['default'] !!}</svg>
@endif
</span>
@endif
<div class="min-w-0 flex-1">
{{ $slot }}
@if ($hasActions)
<div data-slot="alert-actions" {{ $actions->attributes->merge(['class' => 'mt-3 flex flex-wrap items-center gap-2']) }}>
{{ $actions }}
</div>
@endif
</div>
@if ($dismissible)
<button
type="button"
data-slot="alert-dismiss"
@click="open = false; $dispatch('alert:dismiss')"
aria-label="{{ __('Dismiss') }}"
class="-me-1 -mt-1 inline-flex size-7 shrink-0 items-center justify-center rounded-sm text-muted-foreground transition-colors hover:bg-foreground/5 hover:text-foreground focus-visible:outline-none focus-visible:ring-[length:var(--ring-width)] focus-visible:ring-ring motion-reduce:transition-none"
>
<svg class="size-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M18 6 6 18M6 6l12 12" /></svg>
</button>
@endif
</div>
{{-- The title takes the alert's tone colour (the root sets data-variant). --}}
<h5
data-slot="alert-title"
{{ $attributes->merge(['class' => 'mb-1 text-sm font-medium leading-5 group-data-[variant=destructive]/alert:text-destructive-text group-data-[variant=success]/alert:text-success-text group-data-[variant=warning]/alert:text-warning-text group-data-[variant=info]/alert:text-info-text']) }}
>
{{ $slot }}
</h5>
<div
data-slot="alert-description"
{{ $attributes->merge(['class' => 'text-sm text-muted-foreground [&_a]:underline [&_a]:underline-offset-4']) }}
>
{{ $slot }}
</div>
Ownership & lifecycle
Owner, release state, review evidence and adoption for this item.
- Owner
- Platform UI (@JoshJML)
- Current version
-
1.4.0 - Status
- Stable
- License
-
open - Accessibility reviewed
- No review date recorded
- Last breaking change
- No date recorded
- Deprecation
- Not deprecated
- Contract
-
v6 - Foundation
-
≥ 1.0.0