%
add_gem_component_stylesheet("tabs")
tabs ||= []
panel_border ||= true unless panel_border == false
panel_css_classes = %w(govuk-tabs__panel)
panel_css_classes << "gem-c-tabs__panel--no-border" if panel_border == false
panel_css_classes = panel_css_classes.join(" ")
as_links ||= false
disable_ga4 ||= false
component_helper = GovukPublishingComponents::Presenters::ComponentWrapperHelper.new(local_assigns)
component_helper.add_class("govuk-tabs gem-c-tabs")
component_helper.add_data_attribute({ module: "govuk-tabs" }) unless as_links
unless disable_ga4
component_helper.add_data_attribute({ module: "ga4-event-tracker" }) unless as_links
component_helper.add_data_attribute({ module: "ga4-link-tracker" }) if as_links
end
%>
<% if tabs.count > 1 %>
<%= tag.div(**component_helper.all_attributes) do %>
<%= t("components.tabs.contents") %>
<% tabs.each_with_index do |tab, index| %>
- ">
<%
tab[:tab_data_attributes] ||= {}
unless disable_ga4
ga4_attributes = {
event_name: "select_content",
type: "tabs",
text: tab[:label],
index_section: index + 1,
index_section_count: tabs.length,
}
ga4_attributes[:event_name] = "navigation" if as_links
tab[:tab_data_attributes][:ga4_link] = ga4_attributes if as_links
tab[:tab_data_attributes][:ga4_event] = ga4_attributes unless as_links
end
tab_link = "##{tab[:id]}"
tab_link = tab[:href] if as_links
%>
<%= link_to(tab[:label],
tab_link,
class: "govuk-tabs__tab",
data: tab[:tab_data_attributes]) %>
<% end %>
<% unless as_links %>
<% tabs.each do |tab| %>
<% if tab[:title] %>
<%= tab[:title] %>
<% end %>
<%= tab[:content] %>
<% end %>
<% end %>
<% end %>
<% end %>
<% if tabs.count == 1 %>
<% if tabs[0][:title] %>
<%= tabs[0][:title] %>
<% end %>
<%= tabs[0][:content] %>
<% end %>