Sha256: cce28b40b8a8dd29c624985ff9181db1b61bacde126c3549079d0ba931579f4f

Contents?: true

Size: 1.66 KB

Versions: 2

Compression:

Stored size: 1.66 KB

Contents

<%
  id_prefix = local_assigns[:idPrefix]
  attributes = {
    class: class_names("govuk-tabs", local_assigns[:classes]),
    data: { module: "govuk-tabs" }
  }.merge!(local_assigns[:attributes] || {})
%>
<%= tag.div(**attributes) do %>
  <h2 class="govuk-tabs__title">
    <%= local_assigns[:title] || "Contents" %>
  </h2>
  <% if (items = local_assigns[:items] || []).any? %>
    <ul class="govuk-tabs__list">
      <% items.each_with_index do |item, i| %>
        <% if item %>
          <%
            item_id = item[:id].presence || [id_prefix, i].join("-")
            item_classes = class_names("govuk-tabs__list-item", { "govuk-tabs__list-item--selected" => i.zero? })
            link_attributes = item[:attributes] || {}
            link_attributes[:class] = class_names("govuk-tabs__tab", link_attributes[:class])
          %>
          <li class="<%= item_classes %>">
            <%= tag.a item[:label], href: "##{item_id}", **link_attributes %>
          </li>
        <% end %>
      <% end %>
    </ul>
    <% items.each_with_index do |item, i| %>
      <% if item %>
        <%
          item_id = item[:id].presence || [id_prefix, i].join("-")
          panel_attributes = {
            class: class_names("govuk-tabs__panel", { "govuk-tabs__panel--hidden" => i.positive? })
          }.merge!(item.dig(:panel, :attributes) || {})
        %>
        <%= tag.div(id: item_id, **panel_attributes) do %>
          <% if (html_content = item.dig(:panel, :html).presence) %>
            <%= html_content %>
          <% else %>
            <p class="govuk-body"><%= item.dig(:panel, :text) %></p>
          <% end %>
        <% end %>
      <% end %>
    <% end %>
  <% end %>
<% end %>

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
govuk-design-system-rails-0.10.3 app/views/components/_govuk_tabs.html.erb
govuk-design-system-rails-0.10.2 app/views/components/_govuk_tabs.html.erb