Sha256: 813e71277b7a4aa1e1a44a9265caf08d403b7e58fd59e1189d589049ee4bbae9

Contents?: true

Size: 1.84 KB

Versions: 98

Compression:

Stored size: 1.84 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] = 'govuk-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

98 entries across 98 versions & 1 rubygems

Version Path
govuk_publishing_components-21.41.4 app/views/govuk_publishing_components/components/_accordion.html.erb
govuk_publishing_components-21.41.3 app/views/govuk_publishing_components/components/_accordion.html.erb
govuk_publishing_components-21.41.2 app/views/govuk_publishing_components/components/_accordion.html.erb
govuk_publishing_components-21.41.1 app/views/govuk_publishing_components/components/_accordion.html.erb
govuk_publishing_components-21.41.0 app/views/govuk_publishing_components/components/_accordion.html.erb
govuk_publishing_components-21.40.0 app/views/govuk_publishing_components/components/_accordion.html.erb
govuk_publishing_components-21.39.0 app/views/govuk_publishing_components/components/_accordion.html.erb
govuk_publishing_components-21.38.5 app/views/govuk_publishing_components/components/_accordion.html.erb
govuk_publishing_components-21.38.4 app/views/govuk_publishing_components/components/_accordion.html.erb
govuk_publishing_components-21.38.3 app/views/govuk_publishing_components/components/_accordion.html.erb
govuk_publishing_components-21.38.2 app/views/govuk_publishing_components/components/_accordion.html.erb
govuk_publishing_components-21.38.1 app/views/govuk_publishing_components/components/_accordion.html.erb
govuk_publishing_components-21.38.0 app/views/govuk_publishing_components/components/_accordion.html.erb
govuk_publishing_components-21.37.0 app/views/govuk_publishing_components/components/_accordion.html.erb
govuk_publishing_components-21.36.1 app/views/govuk_publishing_components/components/_accordion.html.erb
govuk_publishing_components-21.36.0 app/views/govuk_publishing_components/components/_accordion.html.erb
govuk_publishing_components-21.35.0 app/views/govuk_publishing_components/components/_accordion.html.erb
govuk_publishing_components-21.34.1 app/views/govuk_publishing_components/components/_accordion.html.erb
govuk_publishing_components-21.34.0 app/views/govuk_publishing_components/components/_accordion.html.erb
govuk_publishing_components-21.33.0 app/views/govuk_publishing_components/components/_accordion.html.erb