Class: Primer::UnderlineNavComponent

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

Overview

Use the UnderlineNav component to style navigation with a minimal underlined selected state, typically used for navigation placed at the top of the page.

Constant Summary collapse

ALIGN_DEFAULT =
:left
ALIGN_OPTIONS =
[ALIGN_DEFAULT, :right].freeze

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(with_panel: false, align: ALIGN_DEFAULT, body_classes: "", **system_arguments) ⇒ UnderlineNavComponent

Returns a new instance of UnderlineNavComponent.

Examples:

Default

<%= render(Primer::UnderlineNavComponent.new) do |component| %>
  <% component.tab(href: "#", selected: true) { "Item 1" } %>
  <% component.tab(href: "#") { "Item 2" } %>
  <% component.actions do %>
    <%= render(Primer::ButtonComponent.new) { "Button!" } %>
  <% end %>
<% end %>

With icons and counters

<%= render(Primer::UnderlineNavComponent.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 %>
  <% component.actions do %>
    <%= render(Primer::ButtonComponent.new) { "Button!" } %>
  <% end %>
<% end %>

Align right

<%= render(Primer::UnderlineNavComponent.new(align: :right)) do |component| %>
  <% component.tab(href: "#", selected: true) do |t| %>
    <% t.text { "Item 1" } %>
  <% end %>
  <% component.tab(href: "#") do |t| %>
    <% t.text { "Item 2" } %>
  <% end %>
  <% component.actions do %>
    <%= render(Primer::ButtonComponent.new) { "Button!" } %>
  <% end %>
<% end %>

With panels

<%= render(Primer::UnderlineNavComponent.new(with_panel: true)) do |component| %>
  <% component.tab(selected: true) do |t| %>
    <% t.text { "Item 1" } %>
    <% t.panel do %>
      Panel 1
    <% end %>
  <% end %>
  <% component.tab do |t| %>
    <% t.text { "Item 2" } %>
    <% t.panel do %>
      Panel 2
    <% end %>
  <% end %>
  <% component.actions do %>
    <%= render(Primer::ButtonComponent.new) { "Button!" } %>
  <% end %>
<% end %>

Parameters:

  • with_panel (Boolean) (defaults to: false)

    Whether the TabNav should navigate through pages or panels.

  • align (Symbol) (defaults to: ALIGN_DEFAULT)

    <%= one_of(Primer::UnderlineNavComponent::ALIGN_OPTIONS) %> - Defaults to <%= Primer::UnderlineNavComponent::ALIGN_DEFAULT %>

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'app/components/primer/underline_nav_component.rb', line 104

def initialize(with_panel: false, align: ALIGN_DEFAULT, body_classes: "", **system_arguments)
  @with_panel = with_panel
  @align = fetch_or_fallback(ALIGN_OPTIONS, align, ALIGN_DEFAULT)

  @system_arguments = system_arguments
  @system_arguments[:tag] = :nav
  @system_arguments[:role] = :tablist
  @system_arguments[:classes] = class_names(
    @system_arguments[:classes],
    "UnderlineNav",
    "UnderlineNav--right" => @align == :right
  )

  @body_arguments = {
    tag: :div,
    classes: class_names(
      "UnderlineNav-body",
      body_classes
    )
  }
end