Class: Primer::Dropdown::Menu::Item
- Defined in:
- app/components/primer/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
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 included from JoinStyleArgumentsHelper
Methods included from TestSelectorHelper
Methods included from FetchOrFallbackHelper
#fetch_or_fallback, #fetch_or_fallback_boolean, #silence_deprecations?
Methods included from ClassNameHelper
Constructor Details
#initialize(as:, tag: TAG_DEFAULT, divider: false, **system_arguments) ⇒ Item
Returns a new instance of Item.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/components/primer/dropdown/menu.rb', line 60 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] = :separator if divider @system_arguments[:classes] = class_names( @system_arguments[:classes], "dropdown-item" => !divider, "dropdown-divider" => divider ) end |
Instance Method Details
#call ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'app/components/primer/dropdown/menu.rb', line 76 def call component = if BUTTON_TAGS.include?(@system_arguments[:tag]) Primer::ButtonComponent.new(scheme: :link, **@system_arguments) else Primer::BaseComponent.new(**@system_arguments) end # divider has no content render(component) if divider? render(component) { content } end |
#divider? ⇒ Boolean
89 90 91 |
# File 'app/components/primer/dropdown/menu.rb', line 89 def divider? @divider end |
#list? ⇒ Boolean
93 94 95 |
# File 'app/components/primer/dropdown/menu.rb', line 93 def list? @as == :list end |