Class: GovukComponent::Accordion::Section

Inherits:
Slot
  • Object
show all
Defined in:
app/components/govuk_component/accordion.rb

Instance Attribute Summary collapse

Attributes included from Traits::CustomHtmlAttributes

#html_attributes

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Section.



26
27
28
29
30
31
32
# File 'app/components/govuk_component/accordion.rb', line 26

def initialize(title:, summary: nil, expanded: false, classes: [], html_attributes: {})
  super(classes: classes, html_attributes: html_attributes)

  self.title   = title
  self.summary = summary
  self.expanded = expanded
end

Instance Attribute Details

#expandedObject Also known as: expanded?

Returns the value of attribute expanded.



22
23
24
# File 'app/components/govuk_component/accordion.rb', line 22

def expanded
  @expanded
end

#summaryObject

Returns the value of attribute summary.



22
23
24
# File 'app/components/govuk_component/accordion.rb', line 22

def summary
  @summary
end

#titleObject

Returns the value of attribute title.



22
23
24
# File 'app/components/govuk_component/accordion.rb', line 22

def title
  @title
end

Instance Method Details

#classesObject



38
39
40
# File 'app/components/govuk_component/accordion.rb', line 38

def classes
  super + (expanded? ? %w(govuk-accordion__section--expanded) : [])
end

#id(suffix: nil) ⇒ Object



34
35
36
# File 'app/components/govuk_component/accordion.rb', line 34

def id(suffix: nil)
  [title.parameterize, suffix].compact.join('-')
end