Alert
Alerts communicate important information, warnings, errors, and success messages. They help users understand the outcome of actions, identify issues, and discover information that requires attention.
Quick Start
Import and compose the Alert components to create structured alert messages.
Validation Error
Please review the highlighted fields before continuing.
1import { 2Alert, 3AlertIcon, 4AlertContent, 5AlertTitle, 6AlertDescription, 7} from "@ecos/ui"; 8import { AlertCircle } from "lucide-react"; 9 10<Alert variant="error"> 11 <AlertIcon variant="error"> 12 <AlertCircle size={16} /> 13 </AlertIcon> 14 15 <AlertContent> 16 <AlertTitle> 17 Validation Error 18 </AlertTitle> 19 20 <AlertDescription> 21 Please review the highlighted 22 fields before continuing. 23 </AlertDescription> 24 </AlertContent> 25</Alert>
Variants
Variants communicate different message types and levels of importance.
Error | Warning | Success |
|---|---|---|
Error Something went wrong. | Warning Review before continuing. | Success Changes saved successfully. |
1<Alert variant="error"> ... </Alert> 2 3<Alert variant="warning"> ... </Alert> 4 5<Alert variant="success"> ... </Alert>
Actions
Use AlertAction to provide contextual actions such as retrying an operation, navigating to related settings, or dismissing the alert.
Outdated Information
This record may require review.
1<Alert variant="warning"> 2 <AlertIcon variant="warning"> 3 <AlertTriangle size={16} /> 4 </AlertIcon> 5 6 <AlertContent> 7 <AlertTitle> 8 Outdated Information 9 </AlertTitle> 10 11 <AlertDescription> 12 This record may require review. 13 </AlertDescription> 14 </AlertContent> 15 16 <AlertAction> 17 <X size={16} /> 18 </AlertAction> 19</Alert>
Payment Failed
We couldn't process your payment method.
1<Alert variant="error"> 2 <AlertIcon variant="error"> 3 <AlertCircle size={16} /> 4 </AlertIcon> 5 6 <AlertContent> 7 <AlertTitle>Payment Failed</AlertTitle> 8 9 <AlertDescription> 10 We couldn't process your payment method. 11 </AlertDescription> 12 </AlertContent> 13 14 <AlertAction className="text-sm font-medium underline"> 15 Update Payment 16 </AlertAction> 17</Alert>
Icon Usage
Icons provide fast visual recognition and should match the meaning conveyed by the alert.
1<AlertIcon variant="error"> 2 <AlertCircle size={16} /> 3</AlertIcon> 4 5<AlertIcon variant="warning"> 6 <AlertTriangle size={16} /> 7</AlertIcon> 8 9<AlertIcon variant="success"> 10 <CheckCircle2 size={16} /> 11</AlertIcon>
Long Content
Alert descriptions can contain longer messages and automatically expand to accommodate content.
Profile Updated
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Eius
nostrum earum hic quibusdam nisi quaerat fugit sit repellendus,
dolor accusamus magni veniam veritatis pariatur maiores nihil atque
enim ex quo minus, nesciunt cum excepturi. Odio porro repellat,
quia possimus ipsum architecto similique!
1<Alert variant="success"> 2 <AlertIcon variant="success"> 3 <CheckCircle2 size={16} /> 4 </AlertIcon> 5 6 <AlertContent> 7 <AlertTitle> 8 Profile Updated 9 </AlertTitle> 10 11 <AlertDescription> 12 Lorem ipsum dolor sit amet consectetur, adipisicing elit. Eius 13 nostrum earum hic quibusdam nisi quaerat fugit sit repellendus, 14 dolor accusamus magni veniam veritatis pariatur maiores nihil atque 15 enim ex quo minus, nesciunt cum excepturi. Odio porro repellat, 16 quia possimus ipsum architecto similique! 17 </AlertDescription> 18 </AlertContent> 19</Alert>
API Reference
Alert
Property | Type | Default | Description |
|---|---|---|---|
| variant | "error" | "warning" | "success" | "error" | Determines the visual style and semantic meaning of the alert. |
| className | string | - | Additional classes applied to the alert container. |
AlertIcon
Property | Type | Default | Description |
|---|---|---|---|
| variant | "error" | "warning" | "success" | - | Applies the corresponding icon container styling. |
| children | ReactNode | - | The icon rendered within the coloured icon container. |
AlertContent
Property | Type | Default | Description |
|---|---|---|---|
| children | ReactNode | - | Container used to group the alert title and description. |
AlertTitle
Property | Type | Default | Description |
|---|---|---|---|
| children | ReactNode | - | Primary message displayed within the alert. |
AlertDescription
Property | Type | Default | Description |
|---|---|---|---|
| children | ReactNode | - | Supporting content providing additional context. |
AlertAction
Property | Type | Default | Description |
|---|---|---|---|
| children | ReactNode | - | Optional action element, typically used for dismiss controls. |
| onClick | () => void | - | Called when the action button is clicked. |
Visual Reference
Visual reference covering all supported alert variants.
Variant | Example |
|---|---|
| Error | Error Alert content |
| Warning | Warning Alert content |
| Success | Success Alert content |