Class: ShadcnPhlexcomponents::AlertDialogAction

Inherits:
Base
  • Object
show all
Defined in:
lib/shadcn_phlexcomponents/components/alert_dialog.rb

Direct Known Subclasses

AlertDialogActionTo

Constant Summary

Constants inherited from Base

Base::SANITIZER_ALLOWED_ATTRIBUTES, Base::SANITIZER_ALLOWED_TAGS, Base::TAILWIND_MERGER

Instance Method Summary collapse

Methods inherited from Base

#before_template, #convert_collection_hash_to_struct, #find_as_child, #icon, #item_disabled?, #merge_default_attributes, #merged_as_child_attributes, #nokogiri_attributes_to_hash, #overlay, #sanitize_as_child

Constructor Details

#initialize(variant: :default, size: :default, as_child: false, **attributes) ⇒ AlertDialogAction

Returns a new instance of AlertDialogAction.



258
259
260
261
262
263
# File 'lib/shadcn_phlexcomponents/components/alert_dialog.rb', line 258

def initialize(variant: :default, size: :default, as_child: false, **attributes)
  @variant = variant
  @size = size
  @as_child = as_child
  super(**attributes)
end

Instance Method Details

#class_variants(**args) ⇒ Object



273
274
275
# File 'lib/shadcn_phlexcomponents/components/alert_dialog.rb', line 273

def class_variants(**args)
  Button.new.class_variants(variant: @variant, size: @size, class: args[:class])
end

#default_attributes ⇒ Object



265
266
267
268
269
270
271
# File 'lib/shadcn_phlexcomponents/components/alert_dialog.rb', line 265

def default_attributes
  {
    data: {
      action: "click->alert-dialog#close",
    },
  }
end

#view_template ⇒ Object



277
278
279
280
281
282
283
284
285
286
287
288
289
290
# File 'lib/shadcn_phlexcomponents/components/alert_dialog.rb', line 277

def view_template(&)
  if @as_child
    content = capture(&)
    element = find_as_child(content.to_s)
    vanish(&)
    merged_attributes = merged_as_child_attributes(element, @attributes)

    send(element.name, **merged_attributes) do
      sanitize_as_child(element.children.to_s)
    end
  else
    button(**@attributes, &)
  end
end