Skip to main content

Alert

StorybookView in Storybook

Explore interactive examples and all component variations in our Storybook.

The Alert component displays important messages to users with different visual styles based on the message type. It supports various variants, optional titles, close buttons, and action buttons for enhanced user interaction.

Basic Usage

Alert Variants

Alerts with Titles

Dismissible Alerts

Alerts with Action Buttons

Properties

Alert

PropertyTypeDescription
variant"info" | "warning" | "error" | "success"The visual style variant of the alert. Default: "info".
titlestringOptional title text displayed above the main content.
childrenReact.ReactNodeThe main content of the alert.
showCloseButtonbooleanWhether to show a close button. Default: false.
onClose() => voidCallback function called when the alert is closed.
actionButtonActionButtonConfigConfiguration for an optional action button.
classNamestringAdditional CSS classes for custom styling.

ActionButtonConfig

PropertyTypeDescription
labelstringThe text displayed on the action button.
onClick() => voidCallback function called when the button is clicked.
variant"default" | "outline" | "secondary"The visual style of the button. Default: "default".

Variant Styles

VariantBackgroundBorderTextIcon
infoBlue 50Blue 200Blue 800Info
warningYellow 50Yellow 200Yellow 800Alert Triangle
errorRed 50Red 200Red 800Alert Circle
successGreen 50Green 200Green 800Check Circle

Accessibility

The Alert component includes several accessibility features:

  • Uses the role="alert" attribute for screen reader compatibility
  • Icons have aria-hidden="true" to prevent redundant announcements
  • Close button includes aria-label="Close alert" for screen readers
  • Proper color contrast ratios for all variants
  • Keyboard navigation support for interactive elements

Common Use Cases

The Alert component is perfect for:

  • System notifications - Updates, maintenance, new features
  • Form validation - Error messages, success confirmations
  • User feedback - Action confirmations, warnings
  • Status updates - Progress indicators, completion messages
  • Security alerts - Login attempts, account changes
  • Marketing messages - Promotions, announcements

Best Practices

  1. Use appropriate variants - Match the alert type to the message importance
  2. Keep messages concise - Users should quickly understand the message
  3. Provide clear actions - Include relevant action buttons when needed
  4. Consider timing - Auto-dismiss non-critical alerts after a reasonable time
  5. Test accessibility - Ensure screen readers can access all content
  6. Avoid alert fatigue - Don't overwhelm users with too many alerts