Class: ShadcnPhlexcomponents::Accordion

Inherits:
Base
  • Object
show all
Defined in:
lib/shadcn_phlexcomponents/components/accordion.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(value: nil, multiple: false, **attributes) ⇒ Accordion

Returns a new instance of Accordion.



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

def initialize(value: nil, multiple: false, **attributes)
  @multiple = multiple
  @value = value.is_a?(Array) ? value : [value]
  @aria_id = "accordion-#{SecureRandom.hex(5)}"
  super(**attributes)
end

Instance Method Details

#content(**attributes) ⇒ Object



20
21
22
# File 'lib/shadcn_phlexcomponents/components/accordion.rb', line 20

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

#default_attributesObject



24
25
26
27
28
29
30
31
32
# File 'lib/shadcn_phlexcomponents/components/accordion.rb', line 24

def default_attributes
  {
    data: {
      multiple: @multiple.to_s,
      controller: "accordion",
      accordion_open_items_value: @value.compact.to_json,
    },
  }
end

#item(**attributes) ⇒ Object



12
13
14
# File 'lib/shadcn_phlexcomponents/components/accordion.rb', line 12

def item(**attributes, &)
  AccordionItem(**attributes, &)
end

#trigger(**attributes) ⇒ Object



16
17
18
# File 'lib/shadcn_phlexcomponents/components/accordion.rb', line 16

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

#view_templateObject



34
35
36
# File 'lib/shadcn_phlexcomponents/components/accordion.rb', line 34

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