Class: Yattho::Alpha::NavList::Section

Inherits:
ActionList show all
Defined in:
app/components/yattho/alpha/nav_list/section.rb

Overview

A logical grouping of navigation links with an optional heading.

See <%= link_to_component(Yattho::Alpha::NavList) %> for usage examples.

Constant Summary

Constants inherited from ActionList

ActionList::DEFAULT_ROLE, ActionList::DEFAULT_SCHEME, ActionList::SCHEME_MAPPINGS, ActionList::SCHEME_OPTIONS

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 ActionList

#before_render, #custom_element_name, #will_add_item

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(selected_item_id: nil, **system_arguments) ⇒ Section

Returns a new instance of Section.

Parameters:

  • selected_item_id (Symbol) (defaults to: nil)

    The ID of the currently selected item. Used internally.

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>



46
47
48
49
50
51
52
# File 'app/components/yattho/alpha/nav_list/section.rb', line 46

def initialize(selected_item_id: nil, **system_arguments)
  @system_arguments = system_arguments
  @selected_item_id = selected_item_id
  @system_arguments[:'data-target'] = "nav-list.list"

  super(**@system_arguments)
end

Class Method Details

.custom_element_nameObject



40
41
42
# File 'app/components/yattho/alpha/nav_list/section.rb', line 40

def self.custom_element_name
  "nav-list"
end

Instance Method Details

#build_item(component_klass: NavList::Item, **system_arguments) ⇒ Object



75
76
77
78
79
80
81
# File 'app/components/yattho/alpha/nav_list/section.rb', line 75

def build_item(component_klass: NavList::Item, **system_arguments)
  component_klass.new(
    **system_arguments,
    selected_item_id: @selected_item_id,
    list: self
  )
end

#expand!Object

Cause this section to show its list of sub items when rendered. :nocov:



56
57
58
# File 'app/components/yattho/alpha/nav_list/section.rb', line 56

def expand!
  @expanded = true
end

#itemsArray<Yattho::Alpha::ActionList::Item>

The items contained within this section.



64
65
66
# File 'app/components/yattho/alpha/nav_list/section.rb', line 64

def items
  [*super, show_more_item].tap(&:compact!)
end