Sha256: 43c9cca6c05168f82776201f7c76ba0d0b8fd363f6341acf57dbd2e6a2c35666

Contents?: true

Size: 1.14 KB

Versions: 2

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

class FoxTail::DrawerTriggerComponent < FoxTail::TriggerBaseComponent
  has_option :open, default: false, type: :boolean

  def before_render
    super

    html_attributes[:class] = classnames theme.apply(:root, self),
                                         theme.apply("root/#{open? ? :open : :close}", self),
                                         html_class
  end

  def stimulus_controller_options
    super.merge open_classes: theme.apply("root/open", self),
                closed_classes: theme.apply("root/closed", self)
  end

  class StimulusController < FoxTail::StimulusController
    def drawer_identifier
      FoxTail::DrawerComponent.stimulus_controller_identifier
    end

    def attributes(options = {})
      attributes = super options
      attributes[:data][outlet_key(drawer_identifier)] = options[:selector]
      attributes[:data][classes_key(:open)] = options[:open_classes]
      attributes[:data][classes_key(:closed)] = options[:closed_classes]
      attributes[:data][:action] = action options.fetch(:action, :toggle), event: options.fetch(:trigger_type, :click)
      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/drawer_trigger_component.rb
fox_tail-0.1.0 app/components/fox_tail/drawer_trigger_component.rb