Class: Yattho::Alpha::HiddenTextExpander

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

Overview

Use ‘HiddenTextExpander` to indicate and toggle hidden text.

Constant Summary

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(inline: false, button_arguments: {}, **system_arguments) ⇒ HiddenTextExpander

Returns a new instance of HiddenTextExpander.

Examples:

Default

<%= render(Yattho::Alpha::HiddenTextExpander.new("aria-label": "No effect")) %>

Inline

<%= render(Yattho::Alpha::HiddenTextExpander.new(inline: true, "aria-label": "No effect")) %>

Styling the button

<%= render(Yattho::Alpha::HiddenTextExpander.new("aria-label": "No effect", button_arguments: { p: 1, classes: "custom-class" })) %>

Parameters:

  • inline (Boolean) (defaults to: false)

    Whether or not the expander is inline.

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

    <%= link_to_system_arguments_docs %> for the button element.

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/components/yattho/alpha/hidden_text_expander.rb', line 27

def initialize(inline: false, button_arguments: {}, **system_arguments)
  @system_arguments = deny_tag_argument(**system_arguments)
  @button_arguments = button_arguments

  @system_arguments[:tag] = :span
  @system_arguments[:classes] = class_names(
    "hidden-text-expander",
    @system_arguments[:classes],
    "inline" => inline
  )

  aria_label = system_arguments[:'aria-label'] || system_arguments.dig(:aria, :label) || @aria_label
  if aria_label.present?
    @button_arguments[:'aria-label'] = aria_label
    @system_arguments[:aria]&.delete(:label)
  end

  @button_arguments[:classes] = class_names(
    "ellipsis-expander",
    button_arguments[:classes]
  )
end

Instance Method Details

#callObject



50
51
52
53
54
# File 'app/components/yattho/alpha/hidden_text_expander.rb', line 50

def call
  render(Yattho::BaseComponent.new(**@system_arguments)) do
    render(Yattho::Alpha::HellipButton.new(**@button_arguments))
  end
end