Alert
Display important messages and notifications to users with various styles and customization options.
Basic Usage
This is a basic alert message.
Operation completed successfully!
An error occurred while processing your request.
Please review your settings before continuing.
import { Alert } from '@akitectio/aki-ui'
function BasicAlert() {
return (
<div className="space-y-4">
<Alert>
This is a basic alert message.
</Alert>
<Alert variant="success">
Operation completed successfully!
</Alert>
<Alert variant="danger">
An error occurred while processing your request.
</Alert>
<Alert variant="warning">
Please review your settings before continuing.
</Alert>
</div>
)
}
Alert Variants
Primary: Important information that needs attention.
Secondary: General information or updates.
Success: Action was completed successfully.
Error: Something went wrong and needs fixing.
Warning: Caution needed before proceeding.
Info: Helpful information for the user.
Light: Subtle information with light styling.
Dark: High contrast information display.
<div className="space-y-4">
<Alert variant="primary">Primary: Important information</Alert>
<Alert variant="secondary">Secondary: General information</Alert>
<Alert variant="success">Success: Action completed</Alert>
<Alert variant="danger">Error: Something went wrong</Alert>
<Alert variant="warning">Warning: Caution needed</Alert>
<Alert variant="info">Info: Helpful information</Alert>
<Alert variant="light">Light: Subtle information</Alert>
<Alert variant="dark">Dark: High contrast display</Alert>
</div>
With Icons
Your account has been created successfully!
Failed to upload file. Please try again.
Your session will expire in 5 minutes.
New features are available in the latest update.
<div className="space-y-4">
<Alert variant="success" showIcon>
Your account has been created successfully!
</Alert>
<Alert variant="danger" showIcon>
Failed to upload file. Please try again.
</Alert>
<Alert variant="warning" showIcon>
Your session will expire in 5 minutes.
</Alert>
<Alert variant="info" showIcon>
New features are available in the latest update.
</Alert>
</div>
Dismissible Alerts
This alert can be dismissed by clicking the X button.
This is a dismissible warning message.
import { useState } from 'react'
import { Alert } from '@akitectio/aki-ui'
function DismissibleAlert() {
const [showAlert, setShowAlert] = useState(true)
return (
<div>
{showAlert && (
<Alert
variant="info"
dismissible
onDismiss={() => setShowAlert(false)}
showIcon
>
This alert can be dismissed by clicking the X button.
</Alert>
)}
{!showAlert && (
<button onClick={() => setShowAlert(true)}>
Show Alert Again
</button>
)}
</div>
)
}
Custom Icons
🎉
Congratulations! You've completed all tasks.
💡
Pro tip: Use keyboard shortcuts to work faster.
⚠️
Your storage is almost full. Consider upgrading your plan.
<div className="space-y-4">
<Alert
variant="success"
icon={<span className="text-xl">🎉</span>}
>
Congratulations! You've completed all tasks.
</Alert>
<Alert
variant="info"
icon={<span className="text-xl">💡</span>}
>
Pro tip: Use keyboard shortcuts to work faster.
</Alert>
<Alert
variant="warning"
icon={<span className="text-xl">⚠️</span>}
>
Your storage is almost full. Consider upgrading your plan.
</Alert>
</div>
Border Styles
Alert with left border accent.
Success alert with left border and icon.
Error alert with left border styling.
<div className="space-y-4">
<Alert variant="primary" borderLeft>
Alert with left border accent.
</Alert>
<Alert variant="success" borderLeft showIcon>
Success alert with left border and icon.
</Alert>
<Alert variant="danger" borderLeft>
Error alert with left border styling.
</Alert>
</div>
Complex Content
Account Verified Successfully!
Your email address has been verified. You now have access to all premium features.
Update Required
A new version is available with important security updates.
- Enhanced security protocols
- Bug fixes and performance improvements
- New collaboration features
<Alert variant="success" showIcon dismissible>
<div>
<h4 className="font-semibold mb-2">Account Verified Successfully!</h4>
<p className="mb-3">
Your email address has been verified. You now have access to all premium features.
</p>
<div className="flex gap-2">
<button className="px-3 py-1 bg-green-600 text-white text-sm rounded hover:bg-green-700">
Get Started
</button>
<button className="px-3 py-1 border border-green-600 text-green-600 text-sm rounded hover:bg-green-50">
Learn More
</button>
</div>
</div>
</Alert>
API Reference
Prop | Type | Default | Description |
---|---|---|---|
children | React.ReactNode | - | The content of the alert |
variant | 'primary' | 'secondary' | 'success' | 'danger' | 'warning' | 'info' | 'light' | 'dark' | 'primary' | The visual style variant of the alert |
dismissible | boolean | false | Whether the alert is dismissible |
onDismiss | () => void | - | Callback when the alert is dismissed |
showIcon | boolean | false | Show an icon based on the variant |
icon | React.ReactNode | - | Custom icon to show in the alert |
borderLeft | boolean | false | Whether the alert has a border on the left side |
className | string | - | Additional CSS classes to apply to the alert |
Accessibility
- ✅ Proper ARIA roles and attributes
- ✅ Screen reader compatible with meaningful content
- ✅ High contrast support for all variants
- ✅ Focus management for dismissible alerts
- ✅ Semantic HTML structure
ARIA Attributes
role="alert"
- For important messages that need immediate attentionaria-live="polite"
- For informational messagesaria-live="assertive"
- For critical error messagesaria-label
- On dismiss button for screen readers
Best Practices
✅ Do
- Use appropriate variants to convey the right message type
- Keep alert messages clear and concise
- Use icons to help users quickly identify message types
- Provide actionable next steps when possible
- Use dismissible alerts for non-critical information
- Position alerts where users expect to see feedback
❌ Don't
- Use too many alerts on a single page
- Make critical error messages dismissible
- Use vague or confusing language
- Override semantic colors (red for success, green for errors)
- Use alerts for regular content that isn't status-related
- Make alerts disappear too quickly for users to read
Common Use Cases
Form Validation
Please correct the following errors before submitting:
- Email address is required
- Password must be at least 8 characters
System Status
Scheduled maintenance will occur tonight from 11 PM to 1 AM PST. Some features may be unavailable.
Success Feedback
Your profile has been updated successfully!