Class: Primer::Alpha::UnderlineNav

Inherits:
Component
  • Object
show all
Includes:
TabbedComponentHelper, UnderlineNavHelper
Defined in:
app/components/primer/alpha/underline_nav.rb

Overview

Use ‘UnderlineNav` to style navigation links with a minimal underlined selected state, typically placed at the top of the page.

For panel navigation, use <%= link_to_component(Primer::Alpha::UnderlinePanels) %> instead.

Constant Summary collapse

BODY_TAG_DEFAULT =
:ul
TAG_DEFAULT =
:nav
TAG_OPTIONS =
[TAG_DEFAULT, :div].freeze

Constants included from UnderlineNavHelper

UnderlineNavHelper::ACTIONS_TAG_DEFAULT, UnderlineNavHelper::ACTIONS_TAG_OPTIONS, UnderlineNavHelper::ALIGN_DEFAULT, UnderlineNavHelper::ALIGN_OPTIONS

Constants inherited from Component

Component::INVALID_ARIA_LABEL_TAGS

Constants included from Status::Dsl

Status::Dsl::STATUSES

Constants included from ViewHelper

ViewHelper::HELPERS

Constants included from TestSelectorHelper

TestSelectorHelper::TEST_SELECTOR_TAG

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::InvalidValueError

Constants included from Primer::AttributesHelper

Primer::AttributesHelper::PLURAL_ARIA_ATTRIBUTES, Primer::AttributesHelper::PLURAL_DATA_ATTRIBUTES

Instance Method Summary collapse

Methods included from UnderlineNavHelper

#underline_nav_action_classes, #underline_nav_body_classes, #underline_nav_classes, #underline_nav_tab_classes

Methods included from TabbedComponentHelper

#before_render

Methods inherited from Component

deprecated?, generate_id

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

Methods included from Primer::AttributesHelper

#aria, #data, #merge_aria, #merge_data, #merge_prefixed_attribute_hashes

Constructor Details

#initialize(label:, tag: TAG_DEFAULT, align: ALIGN_DEFAULT, body_arguments: {}, **system_arguments) ⇒ UnderlineNav

Returns a new instance of UnderlineNav.

Parameters:

  • tag (Symbol) (defaults to: TAG_DEFAULT)

    <%= one_of(Primer::Alpha::UnderlineNav::TAG_OPTIONS) %>

  • label (String)

    Sets an ‘aria-label` that helps assistive technology users understand the purpose of the links, and distinguish it from similar elements.

  • align (Symbol) (defaults to: ALIGN_DEFAULT)

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

  • body_arguments (Hash) (defaults to: {})

    <%= link_to_system_arguments_docs %> for the body wrapper.

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>



56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/components/primer/alpha/underline_nav.rb', line 56

def initialize(label:, tag: TAG_DEFAULT, align: ALIGN_DEFAULT, body_arguments: {}, **system_arguments)
  @align = fetch_or_fallback(ALIGN_OPTIONS, align, ALIGN_DEFAULT)

  @system_arguments = system_arguments
  @system_arguments[:tag] = fetch_or_fallback(TAG_OPTIONS, tag, TAG_DEFAULT)
  @system_arguments[:classes] = underline_nav_classes(@system_arguments[:classes], @align)

  @body_arguments = body_arguments
  @body_arguments[:tag] = :ul
  @body_arguments[:classes] = underline_nav_body_classes(@body_arguments[:classes])

  aria_label_for_page_nav(label)
end