Class: CCS::Components::GovUK::Accordion
- Defined in:
- lib/ccs/components/govuk/accordion.rb,
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
This is used for generating the accordion component from the GDS - Components - Accordion
Defined Under Namespace
Classes: Section
Constant Summary collapse
- DEFAULT_ATTRIBUTES =
The default attributes for the accordion
{ class: 'govuk-accordion', data: { module: 'govuk-accordion' } }.freeze
Instance Method Summary collapse
-
#initialize(accordion_id:, accordion_sections:, **options) ⇒ Accordion
constructor
A new instance of Accordion.
-
#render ⇒ ActiveSupport::SafeBuffer
Generates the HTML for the GOV.UK Accordion component.
Constructor Details
#initialize(accordion_id:, accordion_sections:, **options) ⇒ Accordion
Returns a new instance of Accordion.
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/ccs/components/govuk/accordion.rb', line 39 def initialize(accordion_id:, accordion_sections:, **) super(**) @options[:attributes][:id] = accordion_id @options[:heading_level] ||= 2 %i[hide_all_sections hide_section hide_section_aria_label show_all_sections show_section show_section_aria_label].each do |data_attribute| data_attribute_name = :"#{data_attribute}_text" @options[:attributes][:data][:"i18n.#{data_attribute.to_s.gsub('_', '-')}"] = [data_attribute_name] if [data_attribute_name] end @accordion_sections = accordion_sections.map.with_index(1) { |accordion_section, index| Section.new(section: accordion_section, accordion_id: accordion_id, index: index, heading_level: @options[:heading_level]) } end |
Instance Method Details
#render ⇒ ActiveSupport::SafeBuffer
Generates the HTML for the GOV.UK Accordion component
57 58 59 60 61 |
# File 'lib/ccs/components/govuk/accordion.rb', line 57 def render tag.div(**[:attributes]) do accordion_sections.each { |accordion_section| concat(accordion_section.render) } end end |