Class: Shadcn::AlertDialog::Action::Component

Inherits:
Shadcn::ApplicationViewComponent show all
Defined in:
app/components/shadcn/alert_dialog/action/component.rb

Overview

AlertDialogAction — shadcn wraps it in <Button asChild>, so it carries the button's classes while staying the dialog's action element.

Direct Known Subclasses

Cancel::Component

Constant Summary

Constants inherited from Shadcn::ApplicationViewComponent

Shadcn::ApplicationViewComponent::CONTENTS_STYLE, Shadcn::ApplicationViewComponent::VOID_TAGS

Instance Attribute Summary collapse

Attributes inherited from Shadcn::ApplicationViewComponent

#attributes

Instance Method Summary collapse

Methods inherited from Shadcn::ApplicationViewComponent

#call, default_tag, #merged_style, #render_element, #shadcn_t, slot_name, #style_variants, #tag_name

Constructor Details

#initialize(variant: :default, size: :default, **attributes) ⇒ Component

Returns a new instance of Component.



14
15
16
17
18
# File 'app/components/shadcn/alert_dialog/action/component.rb', line 14

def initialize(variant: :default, size: :default, **attributes)
  @variant = variant&.to_sym || :default
  @size = size&.to_sym || :default
  super(**attributes)
end

Instance Attribute Details

#sizeObject (readonly)

Returns the value of attribute size.



12
13
14
# File 'app/components/shadcn/alert_dialog/action/component.rb', line 12

def size
  @size
end

#variantObject (readonly)

Returns the value of attribute variant.



12
13
14
# File 'app/components/shadcn/alert_dialog/action/component.rb', line 12

def variant
  @variant
end

Instance Method Details

#css_classes(extra = nil) ⇒ Object



29
30
31
# File 'app/components/shadcn/alert_dialog/action/component.rb', line 29

def css_classes(extra = nil)
  Button::Component.variant_classes(variant:, size:, class: extra)
end

#element_attributes(**defaults) ⇒ Object



20
21
22
23
24
25
26
27
# File 'app/components/shadcn/alert_dialog/action/component.rb', line 20

def element_attributes(**defaults)
  super(**{
    type: "button",
    "data-variant" => variant,
    "data-size" => size,
    "data-action" => "shadcn--dialog#close"
  }.merge(defaults))
end