Class: Primer::Alpha::Dropdown::Menu::Item
- Inherits:
-
Component
- Object
- ViewComponent::Base
- Component
- Primer::Alpha::Dropdown::Menu::Item
- Defined in:
- app/components/primer/alpha/dropdown/menu.rb
Overview
Items to be rendered in the ‘Dropdown` menu.
Constant Summary collapse
- TAG_DEFAULT =
:a
- BUTTON_TAGS =
[:button, :summary].freeze
- TAG_OPTIONS =
[TAG_DEFAULT, *BUTTON_TAGS].freeze
Constants inherited from Component
Component::INVALID_ARIA_LABEL_TAGS
Constants included from Status::Dsl
Constants included from ViewHelper
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
- #call ⇒ Object
- #divider? ⇒ Boolean
-
#initialize(as:, tag: TAG_DEFAULT, divider: false, **system_arguments) ⇒ Item
constructor
A new instance of Item.
- #list? ⇒ Boolean
Methods inherited from Component
Methods included from JoinStyleArgumentsHelper
Methods included from TestSelectorHelper
Methods included from FetchOrFallbackHelper
#fetch_or_fallback, #fetch_or_fallback_boolean, #silence_deprecations?
Methods included from ClassNameHelper
Methods included from Primer::AttributesHelper
#aria, #data, #extract_data, #merge_aria, #merge_data, #merge_prefixed_attribute_hashes
Methods included from ExperimentalSlotHelpers
Methods included from ExperimentalRenderHelpers
Constructor Details
#initialize(as:, tag: TAG_DEFAULT, divider: false, **system_arguments) ⇒ Item
Returns a new instance of Item.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'app/components/primer/alpha/dropdown/menu.rb', line 65 def initialize(as:, tag: TAG_DEFAULT, divider: false, **system_arguments) @divider = divider @as = as @system_arguments = system_arguments @system_arguments[:tag] = fetch_or_fallback(TAG_OPTIONS, tag, TAG_DEFAULT) @system_arguments[:tag] = :li if list? && divider? @system_arguments[:role] ||= :menuitem @system_arguments[:role] = :presentation if divider @system_arguments[:classes] = class_names( @system_arguments[:classes], "dropdown-item" => !divider, "dropdown-divider" => divider ) end |
Instance Method Details
#call ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'app/components/primer/alpha/dropdown/menu.rb', line 81 def call component = if BUTTON_TAGS.include?(@system_arguments[:tag]) # rubocop:disable Primer/ComponentNameMigration Primer::ButtonComponent.new(scheme: :link, **@system_arguments) # rubocop:enable Primer/ComponentNameMigration else Primer::BaseComponent.new(**@system_arguments) end # divider has no content render(component) if divider? render(component) { content } end |
#divider? ⇒ Boolean
96 97 98 |
# File 'app/components/primer/alpha/dropdown/menu.rb', line 96 def divider? @divider end |
#list? ⇒ Boolean
100 101 102 |
# File 'app/components/primer/alpha/dropdown/menu.rb', line 100 def list? @as == :list end |