Alert
A contextual feedback component for displaying important messages, warnings, errors, and success confirmations. Supports 4 semantic types, 3 visual variants, dismissible behavior, custom icons, and action slots with smooth Framer Motion animations.
Live Preview
Interact with the alert component in real time. Adjust type, variant, and features to see changes instantly.
1<Alert2type="info"3variant="subtle"4title="Alert Title"5>6This is a info alert with the subtle variant.7</Alert>Installation
Install the Aidash Components package using your preferred package manager.
$ pnpm add @aidash/componentsImport
Import the Alert component into your file.
import { Alert } from '@/components/aidash/alert';Usage
The simplest way to use Alert with default props.
1<Alert title="Information">2This is a default info alert with a title and description.3</Alert>4 5<Alert type="success" title="Success">6Your changes have been saved successfully.7</Alert>Types
Four semantic types for different message contexts and severity levels.
1<Alert type="info" title="Info">Informational message.</Alert>2<Alert type="success" title="Success">Operation completed.</Alert>3<Alert type="warning" title="Warning">Review your input.</Alert>4<Alert type="error" title="Error">Something went wrong.</Alert>Variants
Three visual variants for different emphasis levels. Each variant renders all four types distinctly.
filled
1<Alert type="info" variant="filled" title="Info Alert">2This is a info alert using the filled variant style.3</Alert>4<Alert type="success" variant="filled" title="Success Alert">5This is a success alert using the filled variant style.6</Alert>7<Alert type="warning" variant="filled" title="Warning Alert">8This is a warning alert using the filled variant style.9</Alert>10<Alert type="error" variant="filled" title="Error Alert">11This is a error alert using the filled variant style.12</Alert>outline
1<Alert type="info" variant="outline" title="Info Alert">2This is a info alert using the outline variant style.3</Alert>4<Alert type="success" variant="outline" title="Success Alert">5This is a success alert using the outline variant style.6</Alert>7<Alert type="warning" variant="outline" title="Warning Alert">8This is a warning alert using the outline variant style.9</Alert>10<Alert type="error" variant="outline" title="Error Alert">11This is a error alert using the outline variant style.12</Alert>subtle
1<Alert type="info" variant="subtle" title="Info Alert">2This is a info alert using the subtle variant style.3</Alert>4<Alert type="success" variant="subtle" title="Success Alert">5This is a success alert using the subtle variant style.6</Alert>7<Alert type="warning" variant="subtle" title="Warning Alert">8This is a warning alert using the subtle variant style.9</Alert>10<Alert type="error" variant="subtle" title="Error Alert">11This is a error alert using the subtle variant style.12</Alert>filled for critical or high-priority alerts, outline for prominent but non-intrusive messages, and subtle (default) for inline contextual feedback.Features
Advanced capabilities including titles, dismissible alerts, custom icons, action buttons, and icon control.
With Title
1<Alert type="info" title="New Feature Available">2We have released a new dashboard with improved analytics.3</Alert>4 5<Alert type="success" title="Deployment Complete">6Version 2.4.1 has been deployed to production.7</Alert>Dismissible with onDismiss
1<Alert2type="info"3title="Dismissible Alert"4dismissible5onDismiss={() => console.log('Alert dismissed')}6>7Click the close button to dismiss this alert.8</Alert>9 10<Alert11type="warning"12variant="outline"13title="Attention Required"14dismissible15>16Your subscription is about to expire.17</Alert>Custom Icon
1<Alert type="info" title="Launching Soon" icon={<RocketIcon />}>2Your new project is ready to be deployed.3</Alert>4 5<Alert type="success" title="Security Verified" icon={<ShieldIcon />}>6All security checks have passed.7</Alert>Action Button
1<Alert2type="info"3title="Update Available"4variant="outline"5action={6 <button className="text-xs font-medium px-3 py-1.5 rounded-lg bg-brand-500 text-white">7 Update Now8 </button>9}10>11A new version is available. Update to get the latest features.12</Alert>Without Icon
1<Alert type="info" title="Simple Notification" showIcon={false}>2This alert has no icon, keeping the layout clean.3</Alert>4 5<Alert type="success" showIcon={false}>6A brief success message without a title or icon.7</Alert>Composition
Real-world composition patterns showing alerts integrated into larger UI contexts.
Alert in Forms
Please enter a valid email address.
Password must be at least 8 characters.
1<form>2<Alert type="error" title="Form Validation Failed">3 Please correct the following errors before submitting.4</Alert>5 6<div>7 <label>Email Address</label>8 <input type="email" className="border-danger-500/50" />9 <p className="text-danger-500">Please enter a valid email.</p>10</div>11</form>Alert Lists
1<div className="space-y-2">2<Alert type="success" variant="subtle">3 File "report.pdf" uploaded successfully.4</Alert>5<Alert type="warning" variant="subtle">6 File "image.png" exceeds recommended size.7</Alert>8<Alert type="error" variant="subtle">9 File "data.csv" failed to upload.10</Alert>11<Alert type="info" variant="subtle">12 3 files queued for processing.13</Alert>14</div>Inline Alerts
API Configuration
Settings1<div>2<label>API Key</label>3<input type="text" value="sk-xxxxxxxxxxxxxxxx" />4 5<Alert type="warning" variant="subtle">6 This API key has read-write access.7 Store it securely and never expose it in client-side code.8</Alert>9</div>Accessibility
Built-in accessibility features for inclusive user experiences.
ARIA Role
Each alert renders with role="alert", enabling assistive technologies to announce the content immediately when it appears in the DOM.
Keyboard Navigation
The dismiss button is fully keyboard accessible. Users can focus it with Tab and activate it with Enter or Space. A visible focus-visible ring provides clear focus indication.
Screen Reader Labels
The dismiss button includes aria-label="Dismiss alert" so screen readers can announce the button purpose clearly. Alert content (title + description) is read naturally in document flow.
Motion Preferences
Animations are powered by Framer Motion which respects the prefers-reduced-motion media query. Users who prefer reduced motion will see instant transitions.
1{/* Alerts use role="alert" automatically */}2<Alert type="error" title="Connection Lost">3Unable to connect to the server. Check your network.4</Alert>5 6{/* Dismiss button has aria-label="Dismiss alert" */}7<Alert type="info" dismissible onDismiss={handleDismiss}>8New update available.9</Alert>10 11{/* Use aria-live region for dynamic alert lists */}12<div aria-live="polite">13{alerts.map((alert) => (14 <Alert key={alert.id} type={alert.type}>{alert.message}</Alert>15))}16</div>API Reference
Complete list of props accepted by the Alert component.
| Prop | Type | Default | Description |
|---|---|---|---|
| type | 'info' | 'success' | 'warning' | 'error' | 'info' | Semantic type that determines color and default icon |
| variant | 'filled' | 'outline' | 'subtle' | 'subtle' | Visual style of the alert |
| title | string | — | Bold heading displayed above the description |
| children | ReactNode | — | Description content rendered below the title |
| dismissible | boolean | false | Show a close button to dismiss the alert |
| onDismiss | () => void | — | Callback fired when the alert is dismissed |
| icon | ReactNode | — | Custom icon replacing the default type icon |
| showIcon | boolean | true | Whether to display the icon area |
| action | ReactNode | — | Action element (button/link) rendered below content |
| className | string | '' | Additional CSS classes |
AnimatePresence internally for smooth exit animations when dismissed. Each Alert manages its own visibility state, so dismissed alerts animate out automatically.Examples
Realistic production examples showing alerts in context.
Form Validation
1<Alert type="error" title="Unable to Submit" variant="outline" dismissible>2Please fix the following issues: email format is invalid,3password requires at least one uppercase letter, and the4terms of service must be accepted.5</Alert>6 7<Alert type="success" title="Account Created" variant="outline" dismissible>8Welcome aboard! Check your email to verify your address.9</Alert>System Notification
1<Alert2type="info"3title="Scheduled Maintenance"4variant="filled"5dismissible6action={<button>Learn More</button>}7>8Maintenance on July 15, 2:00 AM - 6:00 AM UTC.9</Alert>10 11<Alert12type="warning"13title="Rate Limit Approaching"14action={<button>Upgrade Plan</button>}15>16You have used 85% of your API rate limit.17</Alert>Banner
1<Alert2type="success"3variant="filled"4title="New Version Released"5icon={<RocketIcon />}6dismissible7action={8 <div className="flex gap-2">9 <button>View Changelog</button>10 <button>Dismiss</button>11 </div>12}13>14Version 3.0 brings a redesigned dashboard15and 12 new components.16</Alert>Best Practices
Guidelines for using alerts effectively in your interface.
- Use the correct type for the message severity (error for failures, warning for cautions)
- Write clear, actionable alert messages that tell users what to do next
- Make non-critical alerts dismissible so users can clear them
- Provide action buttons for alerts that require user response
- Use filled variant sparingly for the most important alerts only
- Place alerts near the relevant content they refer to
- Use error type for non-critical information or general messages
- Stack too many alerts at once, overwhelming the user
- Use alerts for transient feedback (use Toast component instead)
- Write vague messages like "Something went wrong" without guidance
- Make critical error alerts dismissible without resolving the issue
- Use multiple filled alerts on the same page (visual overload)
Source Code
Full source code for the Alert component.
'use client';
import { motion, AnimatePresence } from 'framer-motion';
import { useState, type ReactNode } from 'react';
import { HugeiconsIcon } from '@hugeicons/react';
import { InformationCircleIcon, CheckmarkCircle02Icon, Alert01Icon, Cancel01Icon, MultiplicationSignIcon } from '@hugeicons/core-free-icons';
export type AlertType = 'info' | 'success' | 'warning' | 'error';
export type AlertVariant = 'filled' | 'outline' | 'subtle';
export interface AlertProps {
type?: AlertType;
variant?: AlertVariant;
title?: string;
children?: ReactNode;
dismissible?: boolean;
onDismiss?: () => void;
icon?: ReactNode;
showIcon?: boolean;
action?: ReactNode;
className?: string;
}
const typeStyles: Record<AlertType, Record<AlertVariant, string>> = {
info: {
filled: 'bg-brand-500 text-white',
outline: 'bg-(--surface-elevated) border-2 border-brand-500/30 text-(--text)',
subtle: 'bg-brand-500/5 border border-brand-500/15 text-(--text)',
},
success: {
filled: 'bg-success-600 text-white dark:bg-success-500',
outline: 'bg-(--surface-elevated) border-2 border-success-500/30 text-(--text)',
subtle: 'bg-success-500/5 border border-success-500/15 text-(--text)',
},
warning: {
filled: 'bg-warn-500 text-white',
outline: 'bg-(--surface-elevated) border-2 border-warn-500/30 text-(--text)',
subtle: 'bg-warn-500/5 border border-warn-500/15 text-(--text)',
},
error: {
filled: 'bg-danger-600 text-white dark:bg-danger-500',
outline: 'bg-(--surface-elevated) border-2 border-danger-500/30 text-(--text)',
subtle: 'bg-danger-500/5 border border-danger-500/15 text-(--text)',
},
};
const iconColors: Record<AlertType, Record<AlertVariant, string>> = {
info: { filled: 'text-white/90', outline: 'text-brand-500', subtle: 'text-brand-500' },
success: { filled: 'text-white/90', outline: 'text-success-500', subtle: 'text-success-500' },
warning: { filled: 'text-white/90', outline: 'text-warn-500', subtle: 'text-warn-500' },
error: { filled: 'text-white/90', outline: 'text-danger-500', subtle: 'text-danger-500' },
};
const defaultIcons: Record<AlertType, typeof InformationCircleIcon> = {
info: InformationCircleIcon,
success: CheckmarkCircle02Icon,
warning: Alert01Icon,
error: Cancel01Icon,
};
function DefaultIcon({ type }: { type: AlertType }) {
return (
<HugeiconsIcon icon={defaultIcons[type]} size={18} className="shrink-0 mt-0.5" />
);
}
export function Alert({
type = 'info',
variant = 'subtle',
title,
children,
dismissible = false,
onDismiss,
icon,
showIcon = true,
action,
className = '',
}: AlertProps) {
const [visible, setVisible] = useState(true);
const handleDismiss = () => {
setVisible(false);
onDismiss?.();
};
return (
<AnimatePresence>
{visible && (
<motion.div
initial={{ opacity: 0, y: -8, scale: 0.98 }}
animate={{ opacity: 1, y: 0, scale: 1 }}
exit={{ opacity: 0, y: -8, scale: 0.98 }}
transition={{ duration: 0.3, ease: [0.2, 0, 0, 1] }}
role={type === 'error' || type === 'warning' ? 'alert' : 'status'}
aria-live={type === 'error' || type === 'warning' ? 'assertive' : 'polite'}
className={`rounded-lg px-3 py-2.5 ${typeStyles[type][variant]} ${className}`}
>
<div className="flex gap-2.5">
{showIcon && (
<span className={iconColors[type][variant]} aria-hidden="true">
{icon || <DefaultIcon type={type} />}
</span>
)}
<div className="flex-1 min-w-0">
{title && (
<p className={`font-medium text-sm ${children ? 'mb-0.5' : ''}`}>
{title}
</p>
)}
{children && (
<div className={`text-xs ${variant === 'filled' ? 'text-white/80' : 'text-(--text-muted)'} leading-relaxed`}>
{children}
</div>
)}
{action && <div className="mt-2.5">{action}</div>}
</div>
{dismissible && (
<button
type="button"
onClick={handleDismiss}
className={`shrink-0 self-start p-1 rounded-lg transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-current ${
variant === 'filled'
? 'hover:bg-white/15 text-white/70 hover:text-white'
: 'hover:bg-black/5 text-(--text-muted) hover:text-(--text)'
}`}
aria-label="Dismiss alert"
>
<HugeiconsIcon icon={MultiplicationSignIcon} size={14} aria-hidden="true" />
</button>
)}
</div>
</motion.div>
)}
</AnimatePresence>
);
}Related
Other components that work well alongside Alert.