Class: FoxTail::ColorThemeTriggerComponent::StimulusController

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

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



21
22
23
24
25
26
27
28
29
30
31
# File 'app/components/fox_tail/color_theme_trigger_component.rb', line 21

def attributes(options = {})
  controller_options = options.extract! :key, :storage, :default_theme, :domain
  controller_options.reverse_merge! FoxTail::Base.fox_tail_config.color_theme
  attributes = super
  attributes[:data][value_key(:key)] = controller_options[:key]
  attributes[:data][value_key(:storage)] = controller_options[:storage]
  attributes[:data][value_key(:default_theme)] = controller_options[:default_theme]
  attributes[:data][value_key(:domain)] = controller_options[:domain]
  attributes[:data][:action] = action(options[:action], event: options[:trigger_type]) if options[:action].present?
  attributes
end

#set_dark_mode_action(event: nil) ⇒ Object



37
38
39
# File 'app/components/fox_tail/color_theme_trigger_component.rb', line 37

def set_dark_mode_action(event: nil)
  action "setDarkMode", event: event
end

#set_light_mode_action(event: nil) ⇒ Object



41
42
43
# File 'app/components/fox_tail/color_theme_trigger_component.rb', line 41

def set_light_mode_action(event: nil)
  action "setLightMode", event: event
end

#set_preferred_action(event: nil) ⇒ Object



45
46
47
# File 'app/components/fox_tail/color_theme_trigger_component.rb', line 45

def set_preferred_action(event: nil)
  action "setPreferred", event: event
end

#toggle_action(event: nil) ⇒ Object



33
34
35
# File 'app/components/fox_tail/color_theme_trigger_component.rb', line 33

def toggle_action(event: nil)
  action :toggle, event: event
end