Overview
The Alert component displays important messages to users. It supports multiple variants and can include icons, titles, and descriptions.Import
Alert
The main container component for displaying alert messages.Props
The visual style variant of the alert.
default: Standard background with foreground textdestructive: Red/destructive styling for errors or warnings
Additional CSS classes to apply to the alert container.
Ref object to attach to the underlying div element.
HTML Attributes
ExtendsReact.HTMLAttributes<HTMLDivElement>, inheriting all standard div attributes including:
childrenonClickonMouseEnterstyle- etc.
Usage
AlertTitle
Heading component for alert titles.Props
Additional CSS classes to apply to the title.
Ref object to attach to the underlying heading element.
HTML Attributes
ExtendsReact.HTMLAttributes<HTMLHeadingElement>, inheriting all standard heading attributes.
Styling
- Renders as an
h5element - Default styles: medium font weight, tight line height and tracking
- Bottom margin of 1 unit
AlertDescription
Description component for alert content.Props
Additional CSS classes to apply to the description.
Ref object to attach to the underlying div element.
HTML Attributes
ExtendsReact.HTMLAttributes<HTMLParagraphElement>, inheriting all standard paragraph attributes.
Styling
- Renders as a
divelement - Small text size with relaxed leading for paragraph elements
- Automatically formats nested paragraphs
Accessibility
- The Alert component automatically sets
role="alert"for screen readers - Icons should be placed before text content for proper reading order
- Alert icons automatically positioned at left with text content offset
Styling
The Alert component uses class-variance-authority for variant management:- Full width with rounded corners and border
- Padding of 4 units
- SVG icons automatically positioned absolutely at top-left
- Content after icons automatically indented
- Icon receives foreground color for consistency