Class: Yattho::Alpha::ActionList

Inherits:
Component
  • Object
show all
Defined in:
app/components/yattho/alpha/action_list.rb,
app/components/yattho/alpha/action_list/item.rb,
app/components/yattho/alpha/action_list/divider.rb,
app/components/yattho/alpha/action_list/heading.rb

Overview

An ActionList is a styled list of links. It acts as the base component for many other menu-type components, including ‘ActionMenu` and `SelectPanel`, as well as the navigational component `NavList`.

Each item in an action list can be augmented by specifying corresponding leading and/or trailing visuals.

Direct Known Subclasses

NavList::Section

Defined Under Namespace

Classes: Divider, Heading, Item

Constant Summary collapse

DEFAULT_ROLE =
:list
DEFAULT_SCHEME =
:full
SCHEME_MAPPINGS =
{
  DEFAULT_SCHEME => nil,
  :inset => "ActionListWrap--inset"
}.freeze
SCHEME_OPTIONS =
SCHEME_MAPPINGS.keys.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

Class Method Summary collapse

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(role: DEFAULT_ROLE, item_classes: nil, scheme: DEFAULT_SCHEME, show_dividers: false, **system_arguments) ⇒ ActionList

Returns a new instance of ActionList.

Parameters:

  • role (Boolean) (defaults to: DEFAULT_ROLE)

    ARIA role describing the function of the list. listbox and menu are a common values.

  • item_classes (String) (defaults to: nil)

    Additional CSS classes to attach to items.

  • scheme (Symbol) (defaults to: DEFAULT_SCHEME)

    <%= one_of(Yattho::Alpha::ActionList::SCHEME_OPTIONS) %>. ‘inset` children are offset (vertically and horizontally) from list edges. `full` (default) children are flush (vertically and horizontally) with list edges.

  • show_dividers (Boolean) (defaults to: false)

    Display a divider above each item in the list when it does not follow a header or divider.

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/components/yattho/alpha/action_list.rb', line 56

def initialize(
  role: DEFAULT_ROLE,
  item_classes: nil,
  scheme: DEFAULT_SCHEME,
  show_dividers: false,
  **system_arguments
)
  @id = self.class.generate_id
  @role = role

  @system_arguments = system_arguments
  @system_arguments[:tag] = :ul
  @item_classes = item_classes
  @scheme = fetch_or_fallback(SCHEME_OPTIONS, scheme, DEFAULT_SCHEME)
  @show_dividers = show_dividers
  @system_arguments[:classes] = class_names(
    SCHEME_MAPPINGS[@scheme],
    system_arguments[:classes],
    "ActionListWrap",
    "ActionListWrap--subGroup",
    "ActionListWrap--divided" => @show_dividers
  )

  @list_wrapper_arguments = {}
end

Class Method Details

.custom_element_nameObject

:nocov:



25
26
27
# File 'app/components/yattho/alpha/action_list.rb', line 25

def self.custom_element_name
  @custom_element_name ||= name.split("::").last.underscore.dasherize
end

Instance Method Details

#before_renderObject



83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'app/components/yattho/alpha/action_list.rb', line 83

def before_render
  if heading.present?
    @system_arguments[:'aria-labelledby'] = @id
  elsif aria(:label, @system_arguments).blank?
    raise ArgumentError, "An aria-label or heading must be provided"
  end

  return if items.blank?

  @list_wrapper_arguments[:classes] = class_names(
    @list_wrapper_arguments[:classes],
    "ActionListItem--hasSubItem"
  )
end

#build_item(**system_arguments) ⇒ Object



99
100
101
102
103
104
105
106
# File 'app/components/yattho/alpha/action_list.rb', line 99

def build_item(**system_arguments)
  system_arguments[:classes] = class_names(
    @item_classes,
    system_arguments[:classes]
  )

  ActionList::Item.new(list: self, **system_arguments)
end

#custom_element_nameObject



30
31
32
# File 'app/components/yattho/alpha/action_list.rb', line 30

def custom_element_name
  self.class.custom_element_name
end

#will_add_item(_item) ⇒ Object



109
# File 'app/components/yattho/alpha/action_list.rb', line 109

def will_add_item(_item); end