Sha256: 2b0663f37c4323cc2deb5b343844232c46a689a7358685cd6b1234eb7a60a5a9

Contents?: true

Size: 1.83 KB

Versions: 10

Compression:

Stored size: 1.83 KB

Contents

<%
  heading_helper = GovukPublishingComponents::Presenters::AccordionHelper.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(
              heading_helper.heading_tag,
              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

10 entries across 10 versions & 1 rubygems

Version Path
govuk_publishing_components-16.1.0 app/views/govuk_publishing_components/components/_accordion.html.erb
govuk_publishing_components-16.0.0 app/views/govuk_publishing_components/components/_accordion.html.erb
govuk_publishing_components-15.3.0 app/views/govuk_publishing_components/components/_accordion.html.erb
govuk_publishing_components-15.2.0 app/views/govuk_publishing_components/components/_accordion.html.erb
govuk_publishing_components-15.1.0 app/views/govuk_publishing_components/components/_accordion.html.erb
govuk_publishing_components-15.0.0 app/views/govuk_publishing_components/components/_accordion.html.erb
govuk_publishing_components-14.0.0 app/views/govuk_publishing_components/components/_accordion.html.erb
govuk_publishing_components-13.8.1 app/views/govuk_publishing_components/components/_accordion.html.erb
govuk_publishing_components-13.8.0 app/views/govuk_publishing_components/components/_accordion.html.erb
govuk_publishing_components-13.7.0 app/views/govuk_publishing_components/components/_accordion.html.erb