Class: UI::AccordionItem

Inherits:
Phlex::HTML
  • Object
show all
Includes:
AccordionItemBehavior
Defined in:
app/components/ui/accordion_item.rb

Overview

Accordion Item component (Phlex) Individual collapsible item within an accordion

Examples:

Basic usage

render UI::Item.new(value: "item-1") do
  render UI::Trigger.new { "Trigger text" }
  render UI::Content.new { "Content text" }
end

Start open

render UI::Item.new(value: "item-1", initial_open: true) do
  # Item will be open by default
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AccordionItemBehavior

#item_base_classes, #item_classes, #item_data_attributes, #item_html_attributes, #item_state, #merged_item_data_attributes

Constructor Details

#initialize(value: "", initial_open: false, classes: "", attributes: {}) ⇒ AccordionItem

Returns a new instance of AccordionItem.

Parameters:

  • value (String) (defaults to: "")

    unique identifier for this item

  • initial_open (Boolean) (defaults to: false)

    whether this item starts open

  • classes (String) (defaults to: "")

    additional CSS classes

  • attributes (Hash) (defaults to: {})

    additional HTML attributes



25
26
27
28
29
30
# File 'app/components/ui/accordion_item.rb', line 25

def initialize(value: "", initial_open: false, classes: "", attributes: {}, **)
  @value = value
  @initial_open = initial_open
  @classes = classes
  @attributes = attributes
end

Instance Attribute Details

#initial_openObject (readonly)

Returns the value of attribute initial_open.



19
20
21
# File 'app/components/ui/accordion_item.rb', line 19

def initial_open
  @initial_open
end

#valueObject (readonly)

Returns the value of attribute value.



19
20
21
# File 'app/components/ui/accordion_item.rb', line 19

def value
  @value
end

Instance Method Details

#initial_open_contextObject



45
46
47
# File 'app/components/ui/accordion_item.rb', line 45

def initial_open_context
  @initial_open
end

#item_value_contextObject

Helper methods that child components can call to get parent context



41
42
43
# File 'app/components/ui/accordion_item.rb', line 41

def item_value_context
  @value
end

#view_template(&block) ⇒ Object



32
33
34
35
36
37
38
# File 'app/components/ui/accordion_item.rb', line 32

def view_template(&block)
  div(**item_html_attributes) do
    # Pass context to child components by rendering the block
    # Child components will receive item_value and initial_open through helpers
    instance_exec(&block) if block
  end
end