Class: CCS::Components::GovUK::Accordion::Section

Inherits:
Object
  • Object
show all
Includes:
ActionView::Context, ActionView::Helpers
Defined in:
lib/ccs/components/govuk/accordion/section.rb,
lib/ccs/components/govuk/accordion/section/header.rb,
lib/ccs/components/govuk/accordion/section/content.rb

Overview

GOV.UK Accordion Section

The individual accordion section

Defined Under Namespace

Classes: Content, Header

Instance Method Summary collapse

Constructor Details

#initialize(section:, accordion_id:, index:, heading_level:) ⇒ Section

Returns a new instance of Section.

Parameters:

  • section (Hash)

    attributes for the accordion section

  • accordion_id (String)

    ID of the accordion

  • index (Integer)

    the index of the accordion section

  • heading_level (Integer)

    heading level, from 1 to 6

Options Hash (section:):

  • :expanded (Boolean)

    sets whether the section should be expanded when the page loads for the first time.

  • :heading (String)

    the heading text for the accordion

  • :summary (String) — default: nil

    optional summary text for the accordion header

  • :content (ActiveSupport::SafeBuffer)

    the content within the accordion section

  • : (String)

    text if :content is nil then the text will be rendered



41
42
43
44
45
# File 'lib/ccs/components/govuk/accordion/section.rb', line 41

def initialize(section:, accordion_id:, index:, heading_level:)
  @section_is_expanded = section[:expanded]
  @header = Header.new(section: section, accordion_id: accordion_id, index: index, heading_level: heading_level)
  @content = Content.new(section: section, accordion_id: accordion_id, index: index)
end

Instance Method Details

#renderActiveSupport::SafeBuffer

Generates the HTML for the GOV.UK Accordion Section

Returns:

  • (ActiveSupport::SafeBuffer)


51
52
53
54
55
56
# File 'lib/ccs/components/govuk/accordion/section.rb', line 51

def render
  tag.div(class: "govuk-accordion__section #{'govuk-accordion__section--expanded' if section_is_expanded}".rstrip) do
    concat(header.render)
    concat(content.render)
  end
end