Module: WildayUi::Components::Button::Features::Animation

Included in:
WildayUi::Components::Button::FeatureEngine
Defined in:
app/helpers/wilday_ui/components/button/features/animation.rb

Constant Summary collapse

FEATURE_CONFIG =
{
  wrapper_required: false,
  stimulus_controller: "animation",
  default_stimulus_action: "animation#animate animation#disableAfterAnimation"
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.feature_configObject



12
13
14
# File 'app/helpers/wilday_ui/components/button/features/animation.rb', line 12

def self.feature_config
  { animation: FEATURE_CONFIG }
end

Instance Method Details

#setup_animation_options(options, additional_classes, animation, wrapper_data) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/helpers/wilday_ui/components/button/features/animation.rb', line 16

def setup_animation_options(options, additional_classes, animation, wrapper_data)
  return unless animation.present?

  animation_config = normalize_animation_options(animation)

  # Add animation data attributes
  options[:data] ||= {}
  options[:data][:animation] = animation_config.to_json
  options[:data][:controller] = "animation"
  options[:data][:animation_target] = "button"
  options[:data][:action] = FEATURE_CONFIG[:default_stimulus_action]

  additional_classes = [
    additional_classes,
    "w-button-animated",
    "w-button-animation-#{animation_config[:name]}",
    "w-button-animation-trigger-#{animation_config[:trigger]}"
  ].compact.join(" ")
end