Class: DsfrComponent::AccordionComponent::SectionComponent

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

Constant Summary

Constants included from Traits::HeaderSizeable

Traits::HeaderSizeable::DEFAULT_HEADER_LEVEL

Constants inherited from Base

Base::HEADING_LEVELS, Base::SIZES

Instance Attribute Summary collapse

Attributes inherited from Base

#html_attributes

Instance Method Summary collapse

Methods included from Traits::HeaderSizeable

#default_header_level, #header_level, #header_level=, #header_tag

Constructor Details

#initialize(title:, header_level:, expanded: false, id: nil, 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



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/components/dsfr_component/accordion_component/section_component.rb', line 11

def initialize(
  title:,
  header_level:,
  expanded: false,
  id: nil,
  html_attributes: {}
)
  @title = title
  @expanded = expanded
  @id = id
  self.header_level = header_level

  super(html_attributes: html_attributes)
end

Instance Attribute Details

#expandedObject (readonly) Also known as: expanded?

Returns the value of attribute expanded.



4
5
6
# File 'app/components/dsfr_component/accordion_component/section_component.rb', line 4

def expanded
  @expanded
end

#titleObject (readonly)

Returns the value of attribute title.



4
5
6
# File 'app/components/dsfr_component/accordion_component/section_component.rb', line 4

def title
  @title
end

Instance Method Details

#idObject



26
27
28
# File 'app/components/dsfr_component/accordion_component/section_component.rb', line 26

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