The Alert component is a wrapper around @dashflowx/core that provides a consistent way to display notifications, warnings, and informational messages. It leverages the existing, tested components from the core package while maintaining a clean API. The component supports multiple variants, sizes, and configurations to accommodate different types of notifications and design requirements.
Key Features:
- Built on
@dashflowx/core: Uses the existing, tested Alert component - Flexible prefix support: Accepts both JSX elements and strings for icons
- Automatic icon fallback: Provides default icons when no prefix is specified
- Consistent styling: Maintains visual consistency across all variants
- Type-safe: Full TypeScript support with proper prop validation
Icons are controlled through the prefix prop, giving you full control over the visual representation. When using Markdoc tags, you can pass string prefixes (like "✓", "⚠", "ℹ") and they will be automatically converted to proper icon elements.
import { Alert } from '@dashflowx/core'import { InformationCircleIcon } from '@heroicons/react/24/outline'export default function AlertExample() {return (<Alertvariant="basic"title="Information"description="This is an informational alert message that provides important information to the user."prefix={<InformationCircleIcon className="w-5 h-5 text-gray-600" />}/>)}
Preview:
Information
This is an informational alert message that provides important information to the user.
The Alert component supports multiple variants to convey different types of messages. Each variant has distinct colors and styling:
Default alert style with neutral colors.
import { InformationCircleIcon } from '@heroicons/react/24/outline'<Alertvariant="basic"title="Information"description="This is a basic informational alert with neutral styling."prefix={<InformationCircleIcon className="w-5 h-5 text-gray-600" />}/>
Preview:
Information
This is a basic informational alert with neutral styling.
Used for successful operations and positive feedback.
import { CheckCircleIcon } from '@heroicons/react/24/outline'<Alertvariant="success"title="Success"description="Your action was completed successfully. The changes have been saved."prefix={<CheckCircleIcon className="w-5 h-5 text-green-600" />}/>
Preview:
Success
Your action was completed successfully. The changes have been saved.
Used for warnings and cautionary messages.
import { ExclamationTriangleIcon } from '@heroicons/react/24/outline'<Alertvariant="warning"title="Warning"description="Please review your input before proceeding. Some fields may need attention."prefix={<ExclamationTriangleIcon className="w-5 h-5 text-yellow-600" />}/>
Preview:
Warning
Please review your input before proceeding. Some fields may need attention.
Used for errors and critical issues.
import { XCircleIcon } from '@heroicons/react/24/outline'<Alertvariant="error"title="Error"description="Something went wrong. Please check your connection and try again."prefix={<XCircleIcon className="w-5 h-5 text-red-600" />}/>
Preview:
Error
Something went wrong. Please check your connection and try again.
Used for informational messages and updates.
import { InformationCircleIcon } from '@heroicons/react/24/outline'<Alertvariant="info"title="Update Available"description="A new version is available for download. Click here to update."prefix={<InformationCircleIcon className="w-5 h-5 text-blue-600" />}/>
Preview:
Update Available
A new version is available for download. Click here to update.
The Alert component supports three different sizes:
Compact size for inline alerts.
import { CheckCircleIcon } from '@heroicons/react/24/outline'<Alertvariant="success"size="sm"title="Success"description="Operation completed."prefix={<CheckCircleIcon className="w-4 h-4 text-green-600" />}/>
Standard size for most use cases.
import { InformationCircleIcon } from '@heroicons/react/24/outline'<Alertvariant="info"size="md"title="Information"description="This is the default medium size."prefix={<InformationCircleIcon className="w-5 h-5 text-blue-600" />}/>
Prominent size for important messages.
import { ExclamationTriangleIcon } from '@heroicons/react/24/outline'<Alertvariant="warning"size="lg"title="Important Notice"description="This is a large, prominent alert."prefix={<ExclamationTriangleIcon className="w-6 h-6 text-yellow-600" />}/>
Size Examples Preview:
Small Size:
Success
Operation completed.
Medium Size:
Information
This is the default medium size.
Large Size:
Important Notice
This is a large, prominent alert.
| Prop | Type | Default | Description |
|---|---|---|---|
variant | 'basic' | 'success' | 'warning' | 'error' | 'info' | 'basic' | The visual style variant of the alert |
size | 'sm' | 'md' | 'lg' | 'md' | The size of the alert |
title | string | JSX.Element | - | The title/heading of the alert |
description | string | JSX.Element | - | The main content/description of the alert |
prefix | JSX.Element | - | Custom icon or prefix element (controls icon display) |
className | string | - | Additional CSS classes for the alert container |
titleClassName | string | - | Additional CSS classes for the alert title |
descriptionClassName | string | - | Additional CSS classes for the alert description |
children | React.ReactNode | - | Alternative to description for content |
dismissible | boolean | false | Whether the alert can be dismissed |
onDismiss | () => void | - | Callback when alert is dismissed |
import { CheckCircleIcon } from '@heroicons/react/24/outline'<Alertvariant="success"title="Success"description="Your changes have been saved successfully."prefix={<CheckCircleIcon className="w-5 h-5 text-green-600" />}/>
Preview:
Success
Your changes have been saved successfully.
<Alertvariant="info"title="No Icon"description="This alert doesn't show an icon."/>
Preview:
No Icon
This alert doesn't show an icon.
import { useState } from 'react'import { Alert } from '@dashflowx/core'import { CheckCircleIcon } from '@heroicons/react/24/outline'export default function DismissibleAlertExample() {const [showAlert, setShowAlert] = useState(true)if (!showAlert) return nullreturn (<Alertvariant="success"title="Success"description="Your changes have been saved successfully."prefix={<CheckCircleIcon className="w-5 h-5 text-green-600" />}dismissible={true}onDismiss={() => setShowAlert(false)}/>)}
Preview:
Success
Your changes have been saved successfully.
import { ExclamationTriangleIcon } from '@heroicons/react/24/outline'<Alertvariant="warning"title="Complex Content"description={<div><p>This alert contains JSX content with multiple elements:</p><ul className="mt-2 list-disc list-inside"><li>Formatted text</li><li>Lists and other elements</li><li>Custom styling</li></ul></div>}prefix={<ExclamationTriangleIcon className="w-5 h-5 text-yellow-600" />}/>
Preview:
Complex Content
This alert contains JSX content with multiple elements and formatting options.
import { InformationCircleIcon } from '@heroicons/react/24/outline'<Alertvariant="info"title="Custom Styling"description="This alert has custom styling applied."prefix={<InformationCircleIcon className="w-5 h-5 text-blue-600" />}className="border-purple-300 bg-purple-50 shadow-lg"titleClassName="text-purple-800 font-bold text-lg"descriptionClassName="text-purple-700 mt-2"/>
Preview:
Custom Styling
This alert has custom styling applied.
The Alert component uses the prefix prop to control icon display. This gives you complete control over the icon appearance:
import {CheckCircleIcon,ExclamationTriangleIcon,XCircleIcon,InformationCircleIcon} from '@heroicons/react/24/outline'// Success alert with checkmark<Alertvariant="success"title="Success"description="Operation completed successfully."prefix={<CheckCircleIcon className="w-5 h-5 text-green-600" />}/>// Warning alert with triangle<Alertvariant="warning"title="Warning"description="Please review your input."prefix={<ExclamationTriangleIcon className="w-5 h-5 text-yellow-600" />}/>// Error alert with X circle<Alertvariant="error"title="Error"description="Something went wrong."prefix={<XCircleIcon className="w-5 h-5 text-red-600" />}/>// Info alert with info circle<Alertvariant="info"title="Information"description="Here's some useful information."prefix={<InformationCircleIcon className="w-5 h-5 text-blue-600" />}/>
Success:
Success
Operation completed successfully.
Warning:
Warning
Please review your input.
Error:
Error
Something went wrong.
Information:
Information
Here's some useful information.
const CustomIcon = () => (<svg className="w-5 h-5" fill="currentColor" viewBox="0 0 20 20"><path d="M10 18a8 8 0 100-16 8 8 0 000 16zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z" /></svg>)<Alertvariant="info"title="Custom Icon"description="This alert uses a custom SVG icon."prefix={<CustomIcon />}/>
Preview:
Custom Icon
This alert uses a custom SVG icon.
<Alertvariant="success"title="Success"description="Your action was completed successfully."prefix={<span className="text-lg">🎉</span>}/>
Preview:
Success
Your action was completed successfully.
The Alert component also supports a composition pattern using sub-components:
import { Alert, AlertTitle, AlertDescription } from '@dashflowx/core'<Alert variant="success"><AlertTitle>Success</AlertTitle><AlertDescription>Your action was completed successfully.</AlertDescription></Alert>
Preview:
Success
Your action was completed successfully.
The Alert component includes comprehensive accessibility features:
- ARIA role: Uses
role="alert"for screen readers - ARIA live: Uses
aria-live="polite"for dynamic content - Semantic structure: Proper heading hierarchy with title and description
- Screen readers: Properly announces alert content and importance
- Focus management: Dismissible alerts include proper focus handling
- Keyboard navigation: Full keyboard support for dismissible alerts
Choose Appropriate Variants Use variants that match the message type and user expectations.
import { CheckCircleIcon, ExclamationTriangleIcon, XCircleIcon } from '@heroicons/react/24/outline'// ✅ Good - Success for completed actions<Alertvariant="success"title="Payment Complete"description="Your order has been processed."prefix={<CheckCircleIcon className="w-5 h-5 text-green-600" />}/>// ✅ Good - Warning for potential issues<Alertvariant="warning"title="Session Expiring"description="Your session will expire in 5 minutes."prefix={<ExclamationTriangleIcon className="w-5 h-5 text-yellow-600" />}/>// ✅ Good - Error for actual problems<Alertvariant="error"title="Upload Failed"description="The file could not be uploaded."prefix={<XCircleIcon className="w-5 h-5 text-red-600" />}/>
Use Meaningful Icons Choose icons that clearly represent the alert's purpose.
// ✅ Good - Clear icon choice<Alertvariant="success"title="Success"prefix={<CheckCircleIcon className="w-5 h-5 text-green-600" />}description="Your profile has been updated."/>// ✅ Good - Appropriate warning icon<Alertvariant="warning"title="Warning"prefix={<ExclamationTriangleIcon className="w-5 h-5 text-yellow-600" />}description="Please review your settings before proceeding."/>
Clear and Actionable Messages Provide clear, actionable information in your alerts.
import { XCircleIcon } from '@heroicons/react/24/outline'// ❌ Bad - Vague message<Alertvariant="error"title="Error"description="Something went wrong."prefix={<XCircleIcon className="w-5 h-5 text-red-600" />}/>// ✅ Good - Specific and actionable<Alertvariant="error"title="Upload Failed"description="The file 'document.pdf' could not be uploaded. Please check the file size and try again."prefix={<XCircleIcon className="w-5 h-5 text-red-600" />}/>
Consistent Icon Usage Maintain consistent icon usage throughout your application.
// ✅ Good - Consistent icon patterns<Alertvariant="success"prefix={<CheckCircleIcon className="w-5 h-5 text-green-600" />}title="Success"description="Operation completed."/><Alertvariant="warning"prefix={<ExclamationTriangleIcon className="w-5 h-5 text-yellow-600" />}title="Warning"description="Please review your input."/>
<Alertvariant="error"title="Validation Error"description="Please fill in all required fields before submitting the form."prefix={<XCircleIcon className="w-5 h-5 text-red-600" />}/>
<Alertvariant="success"title="Account Created"description="Your account has been successfully created. You can now log in."prefix={<CheckCircleIcon className="w-5 h-5 text-green-600" />}/>
<Alertvariant="warning"title="System Maintenance"description="Scheduled maintenance will occur tonight from 2:00 AM to 4:00 AM EST."prefix={<ExclamationTriangleIcon className="w-5 h-5 text-yellow-600" />}/>
<Alertvariant="info"title="New Features Available"description="Check out our latest updates including dark mode and improved search."prefix={<InformationCircleIcon className="w-5 h-5 text-blue-600" />}dismissible={true}/>
You can override the default colors using CSS classes:
import { InformationCircleIcon } from '@heroicons/react/24/outline'<Alertvariant="basic"title="Custom Colors"description="This alert uses custom colors."prefix={<InformationCircleIcon className="w-5 h-5 text-purple-600" />}className="border-purple-300 bg-purple-50 text-purple-800"titleClassName="text-purple-900"descriptionClassName="text-purple-700"/>
Customize your icons with additional styling:
<Alertvariant="success"title="Custom Icon Styling"description="This icon has custom styling applied."prefix={<CheckCircleIcon className="w-6 h-6 text-green-600 bg-green-100 p-1 rounded-full" />}/>
The Alert component works well across all screen sizes:
import { InformationCircleIcon } from '@heroicons/react/24/outline'<Alertvariant="info"size="sm"className="md:size-md lg:size-lg"title="Responsive Alert"description="This alert adapts to different screen sizes."prefix={<InformationCircleIcon className="w-4 h-4 text-blue-600" />}/>
- Toast: For temporary notifications
- Modal: For important confirmations
- Banner: For persistent site-wide messages
- Callout: For highlighted information blocks
- Notification: For system notifications
For the complete API reference and advanced usage patterns, see the Alert API documentation.
