Sha256: efab38d5e16402414265f0ee8da1c0f1de380e7e165231207efac93dd7d55df6

Contents?: true

Size: 706 Bytes

Versions: 19

Compression:

Stored size: 706 Bytes

Contents

module Lookbook
  class Icon::Component < Lookbook::BaseComponent
    ICON_CACHE = {}

    attr_reader :stroke

    def initialize(name:, size: 4, stroke: 2, **html_attrs)
      @icon_name = name.to_s.tr("_", "-")
      @size = size || 4
      @stroke = stroke
      super(**html_attrs)
    end

    def size_rems
      "#{@size * 0.25}rem"
    end

    def svg
      ICON_CACHE[@icon_name] ||= read_svg
    end

    def read_svg
      File.read(svg_path).html_safe
    rescue
      if Rails.env.development? || Rails.env.test?
        raise "`#{@icon_name}` is not a valid icon name"
      end
    end

    def svg_path
      Lookbook::Engine.root.join("assets/icons/#{@icon_name}.svg")
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
lookbook-2.3.0 app/components/lookbook/icon/component.rb
lookbook-2.2.2 app/components/lookbook/icon/component.rb
lookbook-2.2.1 app/components/lookbook/icon/component.rb
lookbook-2.2.0 app/components/lookbook/icon/component.rb
lookbook-2.1.1 app/components/lookbook/icon/component.rb
lookbook-2.1.0 app/components/lookbook/icon/component.rb
lookbook-2.0.5 app/components/lookbook/icon/component.rb
lookbook-2.0.4 app/components/lookbook/icon/component.rb
lookbook-2.0.3 app/components/lookbook/icon/component.rb
lookbook-2.0.2 app/components/lookbook/icon/component.rb
lookbook-2.0.1 app/components/lookbook/icon/component.rb
lookbook-2.0.0 app/components/lookbook/icon/component.rb
lookbook-2.0.0.rc.3 app/components/lookbook/icon/component.rb
lookbook-2.0.0.rc.2 app/components/lookbook/icon/component.rb
lookbook-2.0.0.rc.1 app/components/lookbook/icon/component.rb
lookbook-2.0.0.beta.9 app/components/lookbook/icon/component.rb
lookbook-2.0.0.beta.8 app/components/lookbook/icon/component.rb
lookbook-2.0.0.beta.7 app/components/lookbook/icon/component.rb
lookbook-2.0.0.beta.6 app/components/lookbook/icon/component.rb