Class: Yattho::Alpha::NavList::Item
- Inherits:
-
ActionList::Item
- Object
- ViewComponent::Base
- Component
- ActionList::Item
- Yattho::Alpha::NavList::Item
- Defined in:
- app/components/yattho/alpha/nav_list/item.rb
Overview
Items are rendered as styled links. They can optionally include leading and/or trailing visuals, such as icons, avatars, and counters. Items are selected by ID. IDs can be specified via the ‘selected_item_ids` argument, which accepts a list of valid IDs for the item. Items can also themselves contain sub items. Sub items are rendered collapsed by default.
Constant Summary
Constants inherited from ActionList::Item
ActionList::Item::DEFAULT_DESCRIPTION_SCHEME, ActionList::Item::DEFAULT_SCHEME, ActionList::Item::DEFAULT_SIZE, ActionList::Item::DESCRIPTION_SCHEME_MAPPINGS, ActionList::Item::DESCRIPTION_SCHEME_OPTIONS, ActionList::Item::SCHEME_MAPPINGS, ActionList::Item::SCHEME_OPTIONS, ActionList::Item::SIZE_MAPPINGS, ActionList::Item::SIZE_OPTIONS
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 Attribute Summary collapse
-
#selected_by_ids ⇒ Object
readonly
Returns the value of attribute selected_by_ids.
-
#sub_item ⇒ Object
(also: #sub_item?)
readonly
Returns the value of attribute sub_item.
Attributes inherited from ActionList::Item
#active, #disabled, #href, #list, #parent
Instance Method Summary collapse
- #active? ⇒ Boolean
- #before_render ⇒ Object
-
#expand! ⇒ Object
Cause this item to show its list of sub items when rendered.
-
#initialize(selected_item_id: nil, selected_by_ids: [], sub_item: false, expanded: false, **system_arguments) ⇒ Item
constructor
A new instance of Item.
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(selected_item_id: nil, selected_by_ids: [], sub_item: false, expanded: false, **system_arguments) ⇒ Item
Returns a new instance of Item.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/components/yattho/alpha/nav_list/item.rb', line 32 def initialize(selected_item_id: nil, selected_by_ids: [], sub_item: false, expanded: false, **system_arguments) @selected_item_id = selected_item_id @selected_by_ids = Array(selected_by_ids) @expanded = @sub_item = sub_item system_arguments[:classes] = class_names( system_arguments[:classes], "ActionListItem--subItem" => @sub_item ) @sub_list_arguments = { classes: class_names( "ActionList", "ActionList--subGroup" ) } overrides = { 'data-item-id': @selected_by_ids.join(" ") } super(**system_arguments, **overrides) end |
Instance Attribute Details
#selected_by_ids ⇒ Object (readonly)
Returns the value of attribute selected_by_ids.
11 12 13 |
# File 'app/components/yattho/alpha/nav_list/item.rb', line 11 def selected_by_ids @selected_by_ids end |
#sub_item ⇒ Object (readonly) Also known as: sub_item?
Returns the value of attribute sub_item.
11 12 13 |
# File 'app/components/yattho/alpha/nav_list/item.rb', line 11 def sub_item @sub_item end |
Instance Method Details
#active? ⇒ Boolean
55 56 57 |
# File 'app/components/yattho/alpha/nav_list/item.rb', line 55 def active? item_active?(self) end |
#before_render ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'app/components/yattho/alpha/nav_list/item.rb', line 64 def before_render if active_sub_item? @content_arguments[:classes] = class_names( @content_arguments[:classes], "ActionListContent--hasActiveSubItem" ) end super raise "Cannot render a trailing action for an item with subitems" if items.present? && trailing_action.present? return if items.blank? @content_arguments[:tag] = :button @content_arguments[:'aria-expanded'] = @expanded.to_s @content_arguments[:'data-action'] = "click:#{@list.custom_element_name}#handleItemWithSubItemClick" with_private_trailing_action_icon(:'chevron-down', classes: "ActionListItem-collapseIcon") @system_arguments[:classes] = class_names( @system_arguments[:classes], "ActionListItem--hasSubItem" ) end |
#expand! ⇒ Object
Cause this item to show its list of sub items when rendered.
60 61 62 |
# File 'app/components/yattho/alpha/nav_list/item.rb', line 60 def @expanded = true end |