Class: Yattho::Alpha::UnderlinePanels

Inherits:
Component
  • Object
show all
Includes:
TabbedComponentHelper, UnderlineNavHelper
Defined in:
app/components/yattho/alpha/underline_panels.rb

Overview

Use ‘UnderlinePanels` to style tabs with an associated panel and an underlined selected state.

Constant Summary

Constants included from UnderlineNavHelper

UnderlineNavHelper::ACTIONS_TAG_DEFAULT, UnderlineNavHelper::ACTIONS_TAG_OPTIONS, UnderlineNavHelper::ALIGN_DEFAULT, UnderlineNavHelper::ALIGN_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

Instance Method Summary collapse

Methods included from UnderlineNavHelper

#underline_nav_action_classes, #underline_nav_body_classes, #underline_nav_classes, #underline_nav_tab_classes

Methods included from TabbedComponentHelper

#before_render

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(label:, align: ALIGN_DEFAULT, body_arguments: {}, wrapper_arguments: {}, **system_arguments) ⇒ UnderlinePanels

Returns a new instance of UnderlinePanels.

Examples:

Default

<%= render(Yattho::Alpha::UnderlinePanels.new(label: "With panels")) do |component| %>
  <% component.with_tab(id: "tab-1", selected: true) do |tab| %>
    <% tab.with_text { "Tab 1" } %>
    <% tab.with_panel do %>
      Panel 1
    <% end %>
  <% end %>
  <% component.with_tab(id: "tab-2") do |tab| %>
    <% tab.with_text { "Tab 2" } %>
    <% tab.with_panel do %>
      Panel 2
    <% end %>
  <% end %>
  <% component.with_actions do %>
    <%= render(Yattho::ButtonComponent.new) { "Button!" } %>
  <% end %>
<% end %>

Parameters:

  • label (String)

    Sets an ‘aria-label` that helps assistive technology users understand the purpose of the tabs.

  • align (Symbol) (defaults to: ALIGN_DEFAULT)

    <%= one_of(Yattho::UnderlineNavHelper::ALIGN_OPTIONS) %> - Defaults to <%= Yattho::UnderlineNavHelper::ALIGN_DEFAULT %>

  • body_arguments (Hash) (defaults to: {})

    <%= link_to_system_arguments_docs %> for the body wrapper.

  • wrapper_arguments (Hash) (defaults to: {})

    <%= link_to_system_arguments_docs %> for the ‘TabContainer` wrapper.

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'app/components/yattho/alpha/underline_panels.rb', line 63

def initialize(label:, align: ALIGN_DEFAULT, body_arguments: {}, wrapper_arguments: {}, **system_arguments)
  @align = fetch_or_fallback(ALIGN_OPTIONS, align, ALIGN_DEFAULT)
  @wrapper_arguments = wrapper_arguments

  @system_arguments = deny_tag_argument(**system_arguments)
  @system_arguments[:tag] = :div
  @system_arguments[:classes] = underline_nav_classes(@system_arguments[:classes], @align)

  @body_arguments = deny_tag_argument(**body_arguments)
  @body_arguments[:tag] = :ul
  @body_arguments[:classes] = underline_nav_body_classes(@body_arguments[:classes])

  @body_arguments[:role] = :tablist
  @body_arguments[:'aria-label'] = label
end