Class: Primer::TabNavComponent::TabComponent

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

Overview

Tabs to be rendered.

Constant Summary

Constants included from Status::Dsl

Status::Dsl::STATUSES

Constants included from ViewHelper

ViewHelper::HELPERS

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::InvalidValueError

Instance Attribute Summary collapse

Instance Method Summary collapse

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(title:, selected: false, **system_arguments) ⇒ TabComponent

Returns a new instance of TabComponent.



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(title:, selected: false, **system_arguments)
  @title = title
  @selected = selected
  @system_arguments = system_arguments
  @system_arguments[:tag] ||= :a
  @system_arguments[:role] = :tab

  if selected
    if @system_arguments[:tag] == :a
      @system_arguments[:"aria-current"] = :page
    else
      @system_arguments[:"aria-selected"] = true
    end
  end

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

Instance Attribute Details

#selectedObject (readonly)

Returns the value of attribute selected.



72
73
74
# File 'app/components/primer/tab_nav_component.rb', line 72

def selected
  @selected
end

Instance Method Details

#callObject



95
96
97
# File 'app/components/primer/tab_nav_component.rb', line 95

def call
  render(Primer::BaseComponent.new(**@system_arguments)) { @title }
end

#hidden?Boolean

Returns:

  • (Boolean)


103
104
105
# File 'app/components/primer/tab_nav_component.rb', line 103

def hidden?
  !@selected
end

#panelObject



99
100
101
# File 'app/components/primer/tab_nav_component.rb', line 99

def panel
  content
end