Class: FoxTail::CollapsibleTriggerComponent::StimulusController

Inherits:
StimulusController show all
Defined in:
app/components/fox_tail/collapsible_trigger_component.rb

Constant Summary collapse

TRIGGER_TYPES =
{
  click: {
    toggle: :click
  }
}.freeze

Instance Attribute Summary

Attributes inherited from StimulusController

#identifier

Instance Method Summary collapse

Methods inherited from StimulusController

#action, #action_param_key, #build_actions, #classes_key, #config, #event, #initialize, #merge, #merge!, #outlet_key, #target_key, #to_s, #to_sym, #value_key

Constructor Details

This class inherits a constructor from FoxTail::StimulusController

Instance Method Details

#attributes(options = {}) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'app/components/fox_tail/collapsible_trigger_component.rb', line 36

def attributes(options = {})
  trigger_type = TRIGGER_TYPES[options[:trigger_type]&.to_sym]
  attributes = super
  attributes[:data][classes_key(:collapsed)] = options[:collapsed_classes]
  attributes[:data][classes_key(:expanded)] = options[:expanded_classes]
  attributes[:data][outlet_key(collapsible_identifier)] = options[:selector]
  attributes[:data][:action] = build_actions(trigger_type)
  attributes[:aria] = {expanded: options[:opened], controls: extract_controls(options[:collapsible_selector])}
  attributes
end

#collapsible_identifierObject



32
33
34
# File 'app/components/fox_tail/collapsible_trigger_component.rb', line 32

def collapsible_identifier
  FoxTail::CollapsibleComponent.stimulus_controller_identifier
end