Class: GovukComponent::AccordionComponent::SectionComponent
- Inherits:
-
Base
- Object
- ViewComponent::Base
- Base
- GovukComponent::AccordionComponent::SectionComponent
- Defined in:
- app/components/govuk_component/accordion_component/section_component.rb
Instance Attribute Summary collapse
-
#accordion_id ⇒ Object
readonly
Returns the value of attribute accordion_id.
-
#expanded ⇒ Object
(also: #expanded?)
readonly
Returns the value of attribute expanded.
-
#heading_level ⇒ Object
readonly
Returns the value of attribute heading_level.
-
#heading_text ⇒ Object
readonly
Returns the value of attribute heading_text.
-
#summary_text ⇒ Object
readonly
Returns the value of attribute summary_text.
Attributes inherited from Base
Instance Method Summary collapse
- #heading_content ⇒ Object
- #id(suffix: nil) ⇒ Object
-
#initialize(heading_text:, summary_text:, expanded:, heading_level:, accordion_id: nil, classes: [], html_attributes: {}) ⇒ SectionComponent
constructor
A new instance of SectionComponent.
- #summary_content ⇒ Object
Methods inherited from Base
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 = @heading_level = heading_level @accordion_id = accordion_id super(classes:, html_attributes:) end |
Instance Attribute Details
#accordion_id ⇒ Object (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 |
#expanded ⇒ Object (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 end |
#heading_level ⇒ Object (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_text ⇒ Object (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_text ⇒ Object (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_content ⇒ Object
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_content ⇒ Object
33 34 35 |
# File 'app/components/govuk_component/accordion_component/section_component.rb', line 33 def summary_content summary_html || summary_text end |