Class: Primer::MenuComponent

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

Overview

Use ‘Menu` to create vertical lists of navigational links.

Constant Summary collapse

HEADING_TAG_OPTIONS =
[:h1, :h2, :h3, :h4, :h5, :h6].freeze
HEADING_TAG_FALLBACK =
:h2

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

Instance Method Summary collapse

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

Constructor Details

#initialize(**system_arguments) ⇒ MenuComponent

Returns a new instance of MenuComponent.

Examples:

Default

<%= render(Primer::MenuComponent.new) do |c| %>
  <% c.heading(tag: :h2) do %>
    Heading
  <% end %>
  <% c.item(selected: true, href: "#url") do %>
    Item 1
  <% end %>
  <% c.item(href: "#url") do %>
    <%= render(Primer::OcticonComponent.new("check")) %>
    With Icon
  <% end %>
  <% c.item(href: "#url") do %>
    <%= render(Primer::OcticonComponent.new("check")) %>
    With Icon and Counter
    <%= render(Primer::CounterComponent.new(count: 25)) %>
  <% end %>
<% end %>

Parameters:

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>



61
62
63
64
65
66
67
68
# File 'app/components/primer/menu_component.rb', line 61

def initialize(**system_arguments)
  @system_arguments = deny_tag_argument(**system_arguments)
  @system_arguments[:tag] = :nav
  @system_arguments[:classes] = class_names(
    "menu",
    @system_arguments[:classes]
  )
end

Instance Method Details

#render?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'app/components/primer/menu_component.rb', line 70

def render?
  items.any?
end