Alert

Display important messages and notifications

Alert

Alerts display short, important messages in a way that attracts the user's attention without interrupting the user's task.

Installation

Add the alert component to your project:

npx velyx add alert
pnpm dlx velyx add alert
yarn dlx velyx add alert
bunx --bun velyx add alert

Alpine.js Required: The alert component requires Alpine.js for interactivity (dismiss functionality). Make sure Alpine.js is installed in your project.

Usage

Default Alert

Loading preview...

Failed to load preview

Code

Success Alert

Loading preview...

Failed to load preview

Code

Destructive Alert

Loading preview...

Failed to load preview

Code

Warning Alert

Loading preview...

Failed to load preview

Code

Info Alert

Loading preview...

Failed to load preview

Code

Non-dismissible Alert

Loading preview...

Failed to load preview

Code

Alert Without Title

Loading preview...

Failed to load preview

Code

Props

Prop Type Default Description
variant string default Alert style variant (default, success, destructive, warning, info)
dismissible boolean false Show dismiss button
title string null Alert title
icon string null Override default icon

Variants

  • default - Default gray styling
  • success - Green styling with check icon
  • destructive - Red styling with alert icon
  • warning - Amber/yellow styling with warning icon
  • info - Blue styling with info icon

Examples

Form Success Message

Loading preview...

Failed to load preview

Code

Form Validation Errors

Loading preview...

Failed to load preview

Code

System Status

Loading preview...

Failed to load preview

Code

Custom Icon

Loading preview...

Failed to load preview

Code

Customization

You can customize the alert component by modifying the variant classes:

@

@props([
    'variant' => 'default',
    'dismissible' => false,
    'title' => null,
    'icon' => null,
])

@php
$variantClasses = match($variant) {
    'success' => 'bg-emerald-50 dark:bg-emerald-950/30 border-emerald-200 dark:border-emerald-800 text-emerald-900 dark:text-emerald-100',
    'destructive' => 'bg-destructive/10 border-destructive/20 text-destructive',
    // ... add your custom variants
};
@endphp

<div {{ $attributes->class(['relative w-full rounded-lg border p-4', $variantClasses]) }}>
    {{ $slot }}
</div>

Accessibility

Alerts include:

  • ARIA role="alert" - Screen readers announce alerts immediately
  • Dismissible button - Properly labeled for screen readers
  • Color contrast - Meets WCAG AA standards
  • Keyboard accessible - Dismissible via keyboard

Animation

Alerts include smooth transitions for dismiss action:

  • Fade in - Smooth appearance
  • Scale - Subtle scale effect
  • Fade out - Smooth dismissal

Next Steps