Class: Yattho::Alpha::Dropdown::Menu::Item
- Inherits:
-
Component
- Object
- ViewComponent::Base
- Component
- Yattho::Alpha::Dropdown::Menu::Item
- Defined in:
- app/components/yattho/alpha/dropdown/menu.rb
Overview
Items to be rendered in the ‘Dropdown` menu.
Direct Known Subclasses
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 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
Constructor Details
#initialize(as:, tag: TAG_DEFAULT, divider: false, **system_arguments) ⇒ Item
Returns a new instance of Item.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/components/yattho/alpha/dropdown/menu.rb', line 66 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
82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'app/components/yattho/alpha/dropdown/menu.rb', line 82 def call component = if BUTTON_TAGS.include?(@system_arguments[:tag]) # rubocop:disable Yattho/ComponentNameMigration Yattho::ButtonComponent.new(scheme: :link, **@system_arguments) # rubocop:enable Yattho/ComponentNameMigration else Yattho::BaseComponent.new(**@system_arguments) end # divider has no content render(component) if divider? render(component) { content } end |
#divider? ⇒ Boolean
97 98 99 |
# File 'app/components/yattho/alpha/dropdown/menu.rb', line 97 def divider? @divider end |
#list? ⇒ Boolean
101 102 103 |
# File 'app/components/yattho/alpha/dropdown/menu.rb', line 101 def list? @as == :list end |