Alert

Displays a callout for user attention.

No JavaScript Required

Installation

Add the component to your project:

rails generate shadcn:component alert

Usage

<%= render Shadcn::AlertComponent.new do |alert| %>
  <% alert.with_title { "Heads up!" } %>
  <% alert.with_description { "You can add components to your app using the cli." } %>
<% end %>

Examples

Default

Destructive

<%= render Shadcn::AlertComponent.new(variant: :destructive) do |alert| %>
  <% alert.with_title { "Error" } %>
  <% alert.with_description { "Your session has expired. Please log in again." } %>
<% end %>

With Icon

Destructive with Icon

Multiple Alerts

API Reference

API Reference

Prop Type Default Description
variant Symbol :default Alert style variant (:default, :destructive)
class_name String nil Additional CSS classes to apply

Slots

Slot Description
with_icon Optional icon displayed on the left
with_title Alert title (bold heading)
with_description Alert description text

Accessibility

  • Uses role="alert" for proper screen reader announcement
  • Icons are decorative and should not require alt text
  • Color is not the only indicator - icons and text provide context