Class: Shadcn::AlertComponent

Inherits:
BaseComponent
  • Object
show all
Defined in:
app/components/shadcn/alert_component.rb

Overview

Alert component for displaying important messages Matches shadcn/ui Alert component

Examples:

Basic alert

<%= 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 %>

Destructive alert

<%= render Shadcn::AlertComponent.new(variant: :destructive) do |alert| %>
  <% alert.with_title { "Error" } %>
  <% alert.with_description { "Something went wrong." } %>
<% end %>

With icon

<%= render Shadcn::AlertComponent.new do |alert| %>
  <% alert.with_icon do %>
    <%= icon "info" %>
  <% end %>
  <% alert.with_title { "Note" } %>
  <% alert.with_description { "This is an informational message." } %>
<% end %>

Constant Summary collapse

VARIANTS =

Available alert variants

{
  default: "bg-background text-foreground",
  destructive: "border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive"
}.freeze
BASE_CLASSES =
"relative w-full rounded-lg border px-4 py-3 text-sm [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground [&>svg~*]:pl-7"

Instance Attribute Summary

Attributes inherited from BaseComponent

#class_name, #data, #html_options

Instance Method Summary collapse

Methods inherited from BaseComponent

#content

Methods included from Rails::Helpers::ClassNameHelper

#cn

Constructor Details

#initialize(variant: :default, **options) ⇒ AlertComponent

Returns a new instance of AlertComponent.

Parameters:

  • variant (Symbol) (defaults to: :default)

    Alert style variant (:default, :destructive)



46
47
48
49
# File 'app/components/shadcn/alert_component.rb', line 46

def initialize(variant: :default, **options)
  super(**options)
  @variant = variant.to_sym
end