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 FetchOrFallbackHelper

FetchOrFallbackHelper::InvalidValueError

Instance Method Summary collapse

Methods included from TabbedComponentHelper

#before_render

Methods included from JoinStyleArgumentsHelper

#join_style_arguments

Methods included from FetchOrFallbackHelper

#fetch_or_fallback, #fetch_or_fallback_boolean, #silence_deprecations?

Methods included from ClassNameHelper

#class_names

Constructor Details

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

Returns a new instance of TabNavComponent.

Examples:

Default

<%= render(Primer::TabNavComponent.new) 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) 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(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 %>


69
70
71
72
73
74
75
76
77
78
79
# File 'app/components/primer/tab_nav_component.rb', line 69

def initialize(aria_label: nil, with_panel: false, **system_arguments)
  @aria_label = aria_label
  @with_panel = with_panel
  @system_arguments = system_arguments
  @system_arguments[:tag] ||= :div

  @system_arguments[:classes] = class_names(
    "tabnav",
    system_arguments[:classes]
  )
end