Class: Primer::UnderlineNavComponent

Inherits:
Component
  • Object
show all
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 inherited from Component

Component::STATUSES

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::InvalidValueError

Instance Method Summary collapse

Methods inherited from Component

status

Methods included from ViewHelper

#primer

Methods included from JoinStyleArgumentsHelper

#join_style_arguments

Methods included from FetchOrFallbackHelper

#fetch_or_fallback, #fetch_or_fallback_boolean

Methods included from ClassNameHelper

#class_names

Constructor Details

#initialize(align: ALIGN_DEFAULT, **system_arguments) ⇒ UnderlineNavComponent

Returns a new instance of UnderlineNavComponent.

Examples:

Default

<%= render(Primer::UnderlineNavComponent.new) do |component| %>
  <% component.with(:body) do %>
    <%= render(Primer::LinkComponent.new(href: "#url")) { "Item 1" } %>
  <% end %>
  <% component.with(:actions) do %>
    <%= render(Primer::ButtonComponent.new) { "Button!" } %>
  <% end %>
<% end %>

Align right

<%= render(Primer::UnderlineNavComponent.new(align: :right)) do |component| %>
  <% component.with(:body) do %>
    <%= render(Primer::LinkComponent.new(href: "#url")) { "Item 1" } %>
  <% end %>
  <% component.with(:actions) do %>
    <%= render(Primer::ButtonComponent.new) { "Button!" } %>
  <% end %>
<% end %>


35
36
37
38
39
40
41
42
43
44
45
# File 'app/components/primer/underline_nav_component.rb', line 35

def initialize(align: ALIGN_DEFAULT, **system_arguments)
  @align = fetch_or_fallback(ALIGN_OPTIONS, align, ALIGN_DEFAULT)

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