Class: GovukComponent::AccordionComponent::SectionComponent

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

Instance Attribute Summary collapse

Attributes inherited from Base

#html_attributes

Instance Method Summary collapse

Methods inherited from Base

#brand

Constructor Details

#initialize(heading_text:, summary_text:, expanded:, heading_level:, accordion_id: nil, classes: [], html_attributes: {}) ⇒ SectionComponent

Returns a new instance of SectionComponent.



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

def initialize(heading_text:, summary_text:, expanded:, heading_level:, accordion_id: nil, classes: [], html_attributes: {})
  @heading_text  = heading_text
  @summary_text  = summary_text
  @expanded      = expanded
  @heading_level = heading_level
  @accordion_id  = accordion_id

  super(classes:, html_attributes:)
end

Instance Attribute Details

#accordion_idObject (readonly)

Returns the value of attribute accordion_id.



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

def accordion_id
  @accordion_id
end

#expandedObject (readonly) Also known as: expanded?

Returns the value of attribute expanded.



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

def expanded
  @expanded
end

#heading_levelObject (readonly)

Returns the value of attribute heading_level.



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

def heading_level
  @heading_level
end

#heading_textObject (readonly)

Returns the value of attribute heading_text.



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

def heading_text
  @heading_text
end

#summary_textObject (readonly)

Returns the value of attribute summary_text.



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

def summary_text
  @summary_text
end

Instance Method Details

#heading_contentObject



29
30
31
# File 'app/components/govuk_component/accordion_component/section_component.rb', line 29

def heading_content
  heading_html || heading_text || fail(ArgumentError, "no heading_text or heading_html")
end

#id(suffix: nil) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'app/components/govuk_component/accordion_component/section_component.rb', line 19

def id(suffix: nil)
  prefix = @accordion_id

  # generate a random number if we don't have heading_text to avoid attempting
  # to parameterize a potentially-huge chunk of HTML
  @unique_identifier ||= heading_text&.parameterize || SecureRandom.hex(4)

  [prefix, @unique_identifier, suffix].compact.join('-')
end

#summary_contentObject



33
34
35
# File 'app/components/govuk_component/accordion_component/section_component.rb', line 33

def summary_content
  summary_html || summary_text
end