Class: DsfrComponent::AccordionComponent::SectionComponent

Inherits:
Base
  • Object
show all
Defined in:
app/components/dsfr_component/accordion_component/section_component.rb

Constant Summary

Constants inherited from Base

Base::HEADING_LEVELS

Instance Attribute Summary collapse

Attributes inherited from Base

#html_attributes

Instance Method Summary collapse

Constructor Details

#initialize(title:, expanded: false, id: nil, classes: [], html_attributes: {}) ⇒ SectionComponent

Returns a new instance of SectionComponent.

Parameters:

  • title (String)

    section title

  • expanded (Boolean) (defaults to: false)

    toggles section folding

  • id (String) (defaults to: nil)

    the HTML id, optional if you want to reuse the anchor



9
10
11
12
13
14
15
# File 'app/components/dsfr_component/accordion_component/section_component.rb', line 9

def initialize(title:, expanded: false, id: nil, classes: [], html_attributes: {})
  @title = title
  @expanded = expanded
  @id = id

  super(classes: classes, html_attributes: html_attributes)
end

Instance Attribute Details

#expandedObject (readonly) Also known as: expanded?

Returns the value of attribute expanded.



2
3
4
# File 'app/components/dsfr_component/accordion_component/section_component.rb', line 2

def expanded
  @expanded
end

#titleObject (readonly)

Returns the value of attribute title.



2
3
4
# File 'app/components/dsfr_component/accordion_component/section_component.rb', line 2

def title
  @title
end

Instance Method Details

#idObject



17
18
19
# File 'app/components/dsfr_component/accordion_component/section_component.rb', line 17

def id
  @id ||= "accordion-section-#{SecureRandom.hex(4)}"
end