Sha256: 94c29bcdbe37a41b5af0da5551c7a98223c070b67a6e1e016e56827d4312fb59

Contents?: true

Size: 1.05 KB

Versions: 2

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

class FoxTail::PopoverTriggerComponent < FoxTail::TriggerBaseComponent
  has_option :delay, default: 300

  def initialize(id, selector, html_attributes = {})
    super
    with_trigger_type :hover unless trigger_type?
  end


  def stimulus_controller_options
    super.merge delay: delay
  end

  class StimulusController < FoxTail::StimulusController
    TRIGGER_TYPES = {
      hover: {
        hoverShow: %i[mouseenter focus],
        hoverHide: %i[mouseleave blur]
      },
      click: {
        toggle: :click,
        hide: %i[focusout blur]
      }
    }.freeze

    def popover_identifier
      FoxTail::PopoverComponent.stimulus_controller_identifier
    end

    def attributes(options = nil)
      trigger_type = options[:trigger_type]&.to_sym
      attributes = super options
      attributes[:data][value_key(:delay)] = options[:delay]
      attributes[:data][outlet_key(popover_identifier)] = options[:selector]
      attributes[:data][:action] = build_actions TRIGGER_TYPES[trigger_type]
      attributes
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fox_tail-0.1.1 app/components/fox_tail/popover_trigger_component.rb
fox_tail-0.1.0 app/components/fox_tail/popover_trigger_component.rb