Sha256: 54162d6fef756efdb0c73e2807ab19420fd91a48f6b5cf8c4659173b3ebc8f03
Contents?: true
Size: 1.83 KB
Versions: 61
Compression:
Stored size: 1.83 KB
Contents
<% shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new(local_assigns) id ||= "default-id-#{SecureRandom.hex(4)}" items ||= [] condensed ||= false accordion_classes = %w(gem-c-accordion govuk-accordion) accordion_classes << 'govuk-accordion--condensed' if condensed data_attributes ||= {} data_attributes[:module] = 'accordion' %> <% if items.any? %> <%= tag.div(class: accordion_classes, id: id, data: data_attributes) do %> <% items.each_with_index do |item, i| %> <% # Nunjucks starts a loop on 1 and the client side JavaScript also # adopts this behaviour. To prevent things from breaking, the index # here also need to be increase by one. (Nunjucks is used by GOV.UK # Frontend, which this component is based on.) index = i + 1 item[:data_attributes] ||= nil section_classes = %w(govuk-accordion__section) section_classes << 'govuk-accordion__section--expanded' if item[:expanded] summary_classes = %w(govuk-accordion__section-summary govuk-body) %> <%= tag.div(class: section_classes) do %> <div class="govuk-accordion__section-header"> <%= content_tag( shared_helper.get_heading_level, content_tag('span', item[:heading][:text], class: "govuk-accordion__section-button", id: "#{id}-heading-#{index}", data: item[:data_attributes]), class: 'govuk-accordion__section-heading' ) %> <%= tag.div(item[:summary][:text], id: "#{id}-summary-#{index}", class: summary_classes) if item[:summary].present? %> </div> <%= tag.div(item[:content][:html], id: "#{id}-content-#{index}", class: "govuk-accordion__section-content", 'aria-labelledby': "#{id}-heading-#{index}") %> <% end %> <% end %> <% end %> <% end %>
Version data entries
61 entries across 61 versions & 1 rubygems