Class: ShadcnPhlexcomponents::DialogClose

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

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(as_child: false, **attributes) ⇒ DialogClose

Returns a new instance of DialogClose.



234
235
236
237
# File 'lib/shadcn_phlexcomponents/components/dialog.rb', line 234

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

Instance Method Details

#default_attributesObject



239
240
241
242
243
244
245
246
# File 'lib/shadcn_phlexcomponents/components/dialog.rb', line 239

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

#view_templateObject



248
249
250
251
252
253
254
255
256
257
258
259
260
261
# File 'lib/shadcn_phlexcomponents/components/dialog.rb', line 248

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
    div(**@attributes, &)
  end
end