Skip to content

Alert

Display contextual feedback messages in four colors, with an optional title and icon.

The alert displays a colored message box: information, a success, a warning or an error. The admin panel uses it for notices inside forms and slide-overs, like the warning the variant slide-overs show when a variant with the same options already exists.

Preview

The preview shows a warning alert with a title and an icon.

Attention RequiredThis product has no price in the store currency yet.

Usage

Pass the message, and optionally a color, a title and an icon:

<x-shopper::alert
    color="warning"
    title="Attention Required"
    message="This product has no price in the store currency yet."
    icon="untitledui-alert-triangle"
/>

Props

Only the message is required. The alert has no slot: everything it shows comes from its props.

PropDefaultDescription
x-shopper::alertrenders a <div> element
message
string
required

The text of the alert.

color
string
warning

The color of the background, ring, icon and text: info, success, warning or danger.

title
string
null

A title displayed above the message.

icon
string
null

The name of an icon from an installed Blade Icons set, like untitledui-alert-triangle or heroicon-o-information-circle, rendered with Filament's icon component. Without it, the alert shows no icon.

iconSize
IconSize | string
IconSize::Medium

The size of the icon: Filament\Support\Enums\IconSize::Small, Medium or Large, or their values sm, md and lg. Pass it as the icon-size attribute.

Color Variants

Each color sets the background, the ring, the icon color and the text color of the alert, in light and dark mode.

Info

Use info for neutral guidance.

InformationPrices are displayed with tax included in the storefront.

This Blade sets the info color and the untitledui-info-circle icon:

<x-shopper::alert
    color="info"
    title="Information"
    message="Prices are displayed with tax included in the storefront."
    icon="untitledui-info-circle"
/>

Success

Use success to confirm that something worked.

SuccessThe shipping rates have been imported.

This Blade sets the success color and the untitledui-check-circle icon:

<x-shopper::alert
    color="success"
    title="Success"
    message="The shipping rates have been imported."
    icon="untitledui-check-circle"
/>

Warning

Use warning, the default color, for a situation that needs attention.

WarningDisabling this carrier hides it from the checkout of every zone.

This Blade sets the warning color and the untitledui-alert-triangle icon:

<x-shopper::alert
    color="warning"
    title="Warning"
    message="Disabling this carrier hides it from the checkout of every zone."
    icon="untitledui-alert-triangle"
/>

Danger

Use danger for an error or an action that cannot be undone.

ErrorThe payment provider rejected the refund. Try again or contact support.

This Blade sets the danger color and the untitledui-x-circle icon:

<x-shopper::alert
    color="danger"
    title="Error"
    message="The payment provider rejected the refund. Try again or contact support."
    icon="untitledui-x-circle"
/>

Examples

The examples below leave out the title or the icon, and place an alert inside a form.

Alert Without Title

Without a title, the message sits next to the icon.

Customers receive an email when their order ships.

This Blade passes the message and the icon, with no title:

<x-shopper::alert
    color="info"
    message="Customers receive an email when their order ships."
    icon="untitledui-info-circle"
/>

Alert Without Icon

Leave out the icon prop to display the text only.

NoteThis discount cannot be combined with other promotions.

This Blade passes the title and the message, with no icon:

<x-shopper::alert
    color="warning"
    title="Note"
    message="This discount cannot be combined with other promotions."
/>

Using in Forms

Alerts often sit above the fields they warn about. The class attribute is merged into the alert's classes, so you can add spacing:

<x-shopper::card title="Product Settings">
    <x-shopper::alert
        color="warning"
        message="Changing the SKU affects inventory tracking."
        icon="untitledui-alert-triangle"
        class="mb-4"
    />

    <x-shopper::label for="sku" value="SKU" />
    <x-shopper::forms.input id="sku" wire:model="sku" class="mt-1" />
</x-shopper::card>

Icon Size

Pass icon-size to change the size of the icon:

<x-shopper::alert
    color="danger"
    title="Payment failed"
    message="The customer's card was declined."
    icon="untitledui-x-circle"
    icon-size="lg"
/>

Blade Component Source

The view is resources/views/components/alert.blade.php in the shopper/framework package:

@php
    use Filament\Support\Enums\IconSize;
@endphp

@props([
    'message',
    'color' => 'warning',
    'title' => null,
    'icon' => null,
    'iconSize' => IconSize::Medium,
])

@php
    if (! $iconSize instanceof IconSize) {
        $iconSize = filled($iconSize) ? IconSize::tryFrom($iconSize) ?? $iconSize : null;
    }

    $containerClass = \Illuminate\Support\Arr::toCssClasses([
        'rounded-lg p-4 ring-1',
        match ($color) {
            'info' => 'bg-info-50 ring-info-200 dark:ring-info-400/20 dark:bg-info-800/30',
            'danger' => 'bg-danger-50 ring-danger-200 dark:ring-danger-400/20 dark:bg-danger-800/30',
            'success' => 'bg-success-50 ring-success-200 dark:ring-success-400/20 dark:bg-success-800/30',
            'warning' => 'bg-warning-50 ring-warning-200 dark:ring-warning-400/20 dark:bg-warning-800/30',
            default => 'bg-custom-50 ring-custom-200 dark:ring-custom-400/20 dark:bg-custom-800/30',
        },
    ]);

    $iconClasses = \Illuminate\Support\Arr::toCssClasses([
        'sh-icon size-4',
        match ($iconSize) {
            IconSize::Small => 'size-4',
            IconSize::Medium => 'size-5',
            IconSize::Large => 'size-6',
            default => $iconSize,
        },
        match ($color) {
            'info' => 'text-info-400 dark:text-info-500',
            'danger' => 'text-danger-400 dark:text-danger-500',
            'success' => 'text-success-400 dark:text-success-500',
            'warning' => 'text-warning-400 dark:text-warning-500',
            default => 'text-custom-400 dark:text-custom-500',
        },
    ]);

    $titleClasses = \Illuminate\Support\Arr::toCssClasses([
        'text-sm/5 font-medium',
        match ($color) {
            'info' => 'text-info-600 dark:text-info-500',
            'danger' => 'text-danger-600 dark:text-danger-500',
            'success' => 'text-success-600 dark:text-success-500',
            'warning' => 'text-warning-600 dark:text-warning-500',
            default => 'text-custom-600 dark:text-custom-500',
        },
    ]);

    $messageClasses = \Illuminate\Support\Arr::toCssClasses([
        'text-sm/5',
        'mt-2' => $title,
        match ($color) {
            'info' => 'text-info-500 dark:text-info-400',
            'danger' => 'text-danger-500 dark:text-danger-400',
            'success' => 'text-success-500 dark:text-success-400',
            'warning' => 'text-warning-500 dark:text-warning-400',
            default => 'text-custom-500 dark:text-custom-400',
        },
    ]);
@endphp

<div {{ $attributes->twMerge(['class' => $containerClass]) }}>
    <div class="flex gap-3">
        @if ($icon)
            <div class="shrink-0">
                <x-filament::icon
                    :attributes="
                        \Filament\Support\prepare_inherited_attributes(
                            new \Illuminate\View\ComponentAttributeBag([
                                'icon' => $icon,
                            ])
                        )
                            ->class([$iconClasses])
                    "
                />
            </div>
        @endif

        <div>
            @if ($title)
                <h3 @class([$titleClasses])>{{ $title }}</h3>
            @endif

            <p @class([$messageClasses])>
                {{ $message }}
            </p>
        </div>
    </div>
</div>

Last updated on

Edit on GitHub