Class: ShadcnPhlexcomponents::Collapsible

Inherits:
Base
  • Object
show all
Defined in:
lib/shadcn_phlexcomponents/components/collapsible.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(open: false, **attributes) ⇒ Collapsible

Returns a new instance of Collapsible.



5
6
7
8
9
# File 'lib/shadcn_phlexcomponents/components/collapsible.rb', line 5

def initialize(open: false, **attributes)
  @open = open
  @aria_id = "collapsible-#{SecureRandom.hex(5)}"
  super(**attributes)
end

Instance Method Details

#content(**attributes) ⇒ Object



15
16
17
# File 'lib/shadcn_phlexcomponents/components/collapsible.rb', line 15

def content(**attributes, &)
  CollapsibleContent(aria_id: @aria_id, **attributes, &)
end

#default_attributesObject



19
20
21
22
23
24
25
26
# File 'lib/shadcn_phlexcomponents/components/collapsible.rb', line 19

def default_attributes
  {
    data: {
      controller: "collapsible",
      collapsible_is_open_value: @open.to_s,
    },
  }
end

#trigger(**attributes) ⇒ Object



11
12
13
# File 'lib/shadcn_phlexcomponents/components/collapsible.rb', line 11

def trigger(**attributes, &)
  CollapsibleTrigger(aria_id: @aria_id, **attributes, &)
end

#view_templateObject



28
29
30
# File 'lib/shadcn_phlexcomponents/components/collapsible.rb', line 28

def view_template(&)
  div(**@attributes, &)
end