Class: Primer::TabNavComponent

Inherits:
Component
  • Object
show all
Includes:
TabbedComponentHelper
Defined in:
app/components/primer/tab_nav_component.rb

Overview

Use TabNav to style navigation with a tab-based selected state, typically used for navigation placed at the top of the page.

Constant Summary

Constants included from Status::Dsl

Status::Dsl::STATUSES

Constants included from ViewHelper

ViewHelper::HELPERS

Constants included from TestSelectorHelper

Primer::TestSelectorHelper::TEST_SELECTOR_TAG

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::InvalidValueError

Instance Method Summary collapse

Methods included from TabbedComponentHelper

#before_render

Methods included from JoinStyleArgumentsHelper

#join_style_arguments

Methods included from TestSelectorHelper

#add_test_selector

Methods included from FetchOrFallbackHelper

#fetch_or_fallback, #fetch_or_fallback_boolean, #silence_deprecations?

Methods included from ClassNameHelper

#class_names

Constructor Details

#initialize(label:, with_panel: false, **system_arguments) ⇒ TabNavComponent

Returns a new instance of TabNavComponent.

Examples:

Default

<%= render(Primer::TabNavComponent.new(label: "Default")) do |c| %>
  <% c.tab(selected: true, href: "#") { "Tab 1" }%>
  <% c.tab(href: "#") { "Tab 2" } %>
  <% c.tab(href: "#") { "Tab 3" } %>
<% end %>

With icons and counters

<%= render(Primer::TabNavComponent.new(label: "With icons and counters")) do |component| %>
  <% component.tab(href: "#", selected: true) do |t| %>
    <% t.icon(icon: :star) %>
    <% t.text { "Item 1" } %>
  <% end %>
  <% component.tab(href: "#") do |t| %>
    <% t.icon(icon: :star) %>
    <% t.text { "Item 2" } %>
    <% t.counter(count: 10) %>
  <% end %>
  <% component.tab(href: "#") do |t| %>
    <% t.text { "Item 3" } %>
    <% t.counter(count: 10) %>
  <% end %>
<% end %>

With panels

<%= render(Primer::TabNavComponent.new(label: "With panels", with_panel: true)) do |c| %>
  <% c.tab(selected: true) do |t| %>
    <% t.text { "Tab 1" } %>
    <% t.panel do %>
      Panel 1
    <% end %>
  <% end %>
  <% c.tab do |t| %>
    <% t.text { "Tab 2" } %>
    <% t.panel do %>
      Panel 2
    <% end %>
  <% end %>
  <% c.tab do |t| %>
    <% t.text { "Tab 3" } %>
    <% t.panel do %>
      Panel 3
    <% end %>
  <% end %>
<% end %>

Parameters:

  • label (String)

    Used to set the ‘aria-label` on the top level `<nav>` element.

  • with_panel (Boolean) (defaults to: false)

    Whether the TabNav should navigate through pages or panels.

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'app/components/primer/tab_nav_component.rb', line 74

def initialize(label:, with_panel: false, **system_arguments)
  @with_panel = with_panel
  @system_arguments = system_arguments

  @system_arguments[:tag] ||= :div
  @system_arguments[:classes] = class_names(
    "tabnav",
    system_arguments[:classes]
  )

  @body_arguments = {
    tag: navigation_tag(with_panel),
    classes: "tabnav-tabs",
    aria: {
      label: label
    }
  }

  @body_arguments[:role] = :tablist if @with_panel
end