Class: Yattho::Alpha::Dropdown::Menu::Item

Inherits:
Component
  • Object
show all
Defined in:
app/components/yattho/alpha/dropdown/menu.rb

Overview

Items to be rendered in the ‘Dropdown` menu.

Direct Known Subclasses

Dropdown::Menu::Item

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

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 inherited from Component

deprecated?, generate_id

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(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

#callObject



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

Returns:

  • (Boolean)


97
98
99
# File 'app/components/yattho/alpha/dropdown/menu.rb', line 97

def divider?
  @divider
end

#list?Boolean

Returns:

  • (Boolean)


101
102
103
# File 'app/components/yattho/alpha/dropdown/menu.rb', line 101

def list?
  @as == :list
end