Sha256: f5f6987ebd80871af28772152df89cda737b12dca62d7f9ba22ed524ad301cb5

Contents?: true

Size: 1.8 KB

Versions: 2

Compression:

Stored size: 1.8 KB

Contents

# frozen_string_literal: true

class FoxTail::Dropdown::MenuItemComponent < FoxTail::ClickableComponent
  renders_one :left_visual, types: {
    icon: {
      renders: lambda { |icon, options = {}| render_icon icon, options, :start },
      as: :left_icon
    },
    svg: {
      renders: lambda { |path, options = {}| render_svg path, options, :start },
      as: :left_svg
    },
    image: {
      renders: lambda { |url, attributes = {}| render_image url, attributes, :start },
      as: :left_image
    }
  }

  renders_one :right_visual, types: {
    icon: {
      renders: lambda { |icon, options = {}| render_icon icon, options, :end },
      as: :right_icon
    },
    svg: {
      renders: lambda { |path, options = {}| render_svg path, options, :end },
      as: :right_svg
    },
    image: {
      renders: lambda { |url, attributes = {}| render_image url, attributes, :end },
      as: :right_image
    }
  }

  has_option :color, default: :default

  def visuals?
    left_visual? || right_visual?
  end

  def call
    super do
      concat left_visual if left_visual?
      concat content
      concat right_visual if right_visual?
    end
  end

  private

  def render_icon(icon, options, side)
    options[:variant] ||= :mini
    options[:"aria-hidden"] = true
    options[:class] = classnames theme.apply(:visual, self, side: side), options[:class]
    FoxTail::IconBaseComponent.new icon, options
  end

  def render_svg(path, options, side)
    options[:"aria-hidden"] = true
    options[:class] = classnames theme.apply(:visual, self, side: side), options[:class]
    FoxTail::InlineSvgComponent.new path, options
  end

  def render_image(uri, options, side)
    options[:"aria-hidden"] = true
    options[:class] = classnames theme.apply(:visual, self, side: side), options[:class]
    image_tag uri, options
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fox_tail-0.1.1 app/components/fox_tail/dropdown/menu_item_component.rb
fox_tail-0.1.0 app/components/fox_tail/dropdown/menu_item_component.rb