Class: Pajamas::AccordionItemComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/pajamas/accordion_item_component.rb

Constant Summary collapse

STATE_OPTIONS =
[:opened, :closed].freeze

Instance Method Summary collapse

Constructor Details

#initialize(title: nil, state: :closed, button_options: {}) ⇒ AccordionItemComponent

Returns a new instance of AccordionItemComponent.

Parameters:

  • title (String) (defaults to: nil)
  • state (Symbol) (defaults to: :closed)
  • button_options (Hash) (defaults to: {})


13
14
15
16
17
# File 'app/components/pajamas/accordion_item_component.rb', line 13

def initialize(title: nil, state: :closed, button_options: {})
  @title = title
  @state = filter_attribute(state.to_sym, STATE_OPTIONS)
  @button_options = button_options
end

Instance Method Details

#body_classObject



23
24
25
# File 'app/components/pajamas/accordion_item_component.rb', line 23

def body_class
  @state == :opened ? { class: 'show' } : {}
end

#expanded?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'app/components/pajamas/accordion_item_component.rb', line 27

def expanded?
  @state == :opened
end

#iconObject



19
20
21
# File 'app/components/pajamas/accordion_item_component.rb', line 19

def icon
  @state == :opened ? "chevron-down" : "chevron-right"
end