Class: Ariadne::ShowMoreButtonComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/ariadne/show_more_button_component.rb

Overview

Add a general description of component here Add additional usage considerations or best practices that may aid the user to use the component correctly.

Constant Summary collapse

DEFAULT_TAG =
:div
TAG_OPTIONS =
[DEFAULT_TAG].freeze
DEFAULT_CLASSES =
{ wrapper: "ariadne-group", button: "ariadne-px-2 ariadne-py-0" }
DEFAULT_ATTRIBUTES =
{
  wrapper: {
    "data-controller": "toggleable",
  },
  button: {
    "data-action": "click->toggleable#toggle",
  },
}

Constants inherited from Component

Component::BASE_HIDDEN_CLASS, Component::BASE_MAIN_CLASSES, Component::BASE_WRAPPER_CLASSES, Component::INVALID_ARIA_LABEL_TAGS

Constants included from ActionViewExtensions::FormHelper

ActionViewExtensions::FormHelper::DEFAULT_FORM_CLASSES

Constants included from Ariadne::Status::Dsl

Ariadne::Status::Dsl::STATUSES

Constants included from ViewHelper

ViewHelper::HELPERS

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::INTEGER_TYPES, FetchOrFallbackHelper::InvalidValueError, FetchOrFallbackHelper::TRUE_OR_FALSE

Instance Method Summary collapse

Methods included from ActionViewExtensions::FormHelper

#ariadne_form_with

Methods included from ClassNameHelper

#merge_class_names

Methods included from LoggerHelper

#logger, #silence_deprecations?, #silence_warnings?

Methods included from FetchOrFallbackHelper

#check_incoming_attribute, #check_incoming_tag, #check_incoming_value, #fetch_or_raise, #fetch_or_raise_boolean, #fetch_or_raise_integer

Constructor Details

#initialize(tag: DEFAULT_TAG, classes: "", button_text: "...", outlet: nil, attributes: {}) ⇒ ShowMoreButtonComponent

Returns a new instance of ShowMoreButtonComponent.

Examples:

Default


<%= render(Ariadne::ShowMoreButtonComponent.new) { "Example" } %>

Raises:

  • (ArgumentError)


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/components/ariadne/show_more_button_component.rb', line 31

def initialize(tag: DEFAULT_TAG, classes: "", button_text: "...", outlet: nil, attributes: {})
  raise ArgumentError, "An 'aria-label' attribute is required to use the Show More Button. Include as much detail as you can about the content to be shown to assist screen readers." if attributes.blank? || attributes["aria-label"].blank?
  raise ArgumentError, "An 'outlet' attribute is required to use the Show More Button. This will ensure controllers can correctly identify states to update." if outlet.blank?

  @outlet = outlet
  @tag = check_incoming_tag(DEFAULT_TAG, tag)
  @classes = merge_class_names(DEFAULT_CLASSES[:wrapper], classes)
  @attributes = DEFAULT_ATTRIBUTES[:wrapper]
    .merge({ "data-toggleable-toggleable-outlet": "[data-toggleable-outlet=#{@outlet}]" })
    .merge(attributes)

  @button_classes = merge_class_names(DEFAULT_CLASSES[:button], classes)
  @button_attributes = DEFAULT_ATTRIBUTES[:button].merge(attributes)
  @button_text = button_text
end