Class: Shadcn::AlertDialogComponent

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

Overview

Alert Dialog component for important confirmation dialogs Matches shadcn/ui AlertDialog component Uses Stimulus for interactivity (reuses dialog controller)

Examples:

Basic alert dialog

<%= render Shadcn::AlertDialogComponent.new do |dialog| %>
  <% dialog.with_trigger do %>
    <%= render Shadcn::ButtonComponent.new(variant: :outline) { "Delete Account" } %>
  <% end %>
  <% dialog.with_body do |body| %>
    <% body.with_header do |header| %>
      <% header.with_title { "Are you absolutely sure?" } %>
      <% header.with_description { "This action cannot be undone." } %>
    <% end %>
    <% body.with_footer do |footer| %>
      <% footer.with_cancel { "Cancel" } %>
      <% footer.with_action { "Continue" } %>
    <% end %>
  <% end %>
<% end %>

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(open: false, **options) ⇒ AlertDialogComponent

Returns a new instance of AlertDialogComponent.

Parameters:

  • open (Boolean) (defaults to: false)

    Whether dialog starts open



32
33
34
35
# File 'app/components/shadcn/alert_dialog_component.rb', line 32

def initialize(open: false, **options)
  super(**options)
  @open = open
end