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

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

Overview

This component is part of ‘Dropdown` and should not be used as a standalone component.

Direct Known Subclasses

Dropdown::Menu

Defined Under Namespace

Classes: Item

Constant Summary collapse

AS_DEFAULT =
:default
AS_OPTIONS =
[AS_DEFAULT, :list].freeze
SCHEME_DEFAULT =
:default
SCHEME_MAPPINGS =
{
  SCHEME_DEFAULT => "",
  :dark => "dropdown-menu-dark"
}.freeze
DIRECTION_DEFAULT =
:se
DIRECTION_OPTIONS =
[DIRECTION_DEFAULT, :sw, :w, :e, :ne, :s].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: AS_DEFAULT, direction: DIRECTION_DEFAULT, scheme: SCHEME_DEFAULT, header: nil, **system_arguments) ⇒ Menu

Returns a new instance of Menu.

Parameters:

  • as (Symbol) (defaults to: AS_DEFAULT)

    When ‘as` is `:list`, wraps the menu in a `<ul>` with a `<li>` for each item.

  • direction (Symbol) (defaults to: DIRECTION_DEFAULT)

    <%= one_of(Yattho::Alpha::Dropdown::Menu::DIRECTION_OPTIONS) %>.

  • header (String) (defaults to: nil)

    Header to be displayed above the menu.

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/components/yattho/alpha/dropdown/menu.rb', line 34

def initialize(as: AS_DEFAULT, direction: DIRECTION_DEFAULT, scheme: SCHEME_DEFAULT, header: nil,
               **system_arguments)
  @header = header
  @direction = direction
  @as = fetch_or_fallback(AS_OPTIONS, as, AS_DEFAULT)

  @system_arguments = deny_tag_argument(**system_arguments)
  @system_arguments[:tag] = "details-menu"
  @system_arguments[:role] = "menu"

  @system_arguments[:classes] = class_names(
    @system_arguments[:classes],
    "dropdown-menu",
    "dropdown-menu-#{fetch_or_fallback(DIRECTION_OPTIONS, direction, DIRECTION_DEFAULT)}",
    SCHEME_MAPPINGS[fetch_or_fallback(SCHEME_MAPPINGS.keys, scheme, SCHEME_DEFAULT)]
  )
end