Class: FoxTail::CollapsibleComponent

Inherits:
BaseComponent show all
Includes:
FoxTail::Concerns::HasStimulusController
Defined in:
app/components/fox_tail/collapsible_component.rb

Direct Known Subclasses

Tabs::PanelComponent

Defined Under Namespace

Classes: StimulusController

Instance Attribute Summary collapse

Attributes inherited from BaseComponent

#html_attributes

Instance Method Summary collapse

Methods inherited from BaseComponent

classname_merger, stimulus_merger, use_stimulus?, #with_html_attributes, #with_html_class

Methods inherited from Base

fox_tail_config

Constructor Details

#initialize(id, html_attributes = {}) ⇒ CollapsibleComponent

Returns a new instance of CollapsibleComponent.



15
16
17
18
# File 'app/components/fox_tail/collapsible_component.rb', line 15

def initialize(id, html_attributes = {})
  super(html_attributes)
  @id = id
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'app/components/fox_tail/collapsible_component.rb', line 6

def id
  @id
end

Instance Method Details

#before_renderObject



24
25
26
27
28
29
30
31
# File 'app/components/fox_tail/collapsible_component.rb', line 24

def before_render
  super

  html_attributes[:id] = id
  html_attributes[:class] = classnames theme.apply(:root, self),
                                       !open? && theme.apply("root/collapsed", self),
                                       html_class
end

#callObject



33
34
35
36
37
38
# File 'app/components/fox_tail/collapsible_component.rb', line 33

def call
  capture do
    concat trigger if trigger?
    concat (:div, content, html_attributes)
  end
end

#stimulus_controller_optionsObject



40
41
42
43
44
45
# File 'app/components/fox_tail/collapsible_component.rb', line 40

def stimulus_controller_options
  {
    open: open?,
    hidden_classes: theme.apply("root/collapsed", self)
  }
end

#trigger_idObject



20
21
22
# File 'app/components/fox_tail/collapsible_component.rb', line 20

def trigger_id
  options[:trigger_id] ||= :"#{id}_trigger"
end