Sha256: 129b63a796daaa92e6cadd0892766f685d4357dcbd487eb3421a3b50ef6ee7ce

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

class SolidusAdmin::UI::Icon::Component < SolidusAdmin::BaseComponent
  NAMES = Set.new(File.read("#{__dir__}/names.txt").split("\n").map(&:freeze)).freeze

  # Renders a remixincon svg.
  #
  # @param name [String] the name of the icon
  # @option attrs [String] :class the class to add to the svg
  # @see https://remixicon.com/
  def initialize(name:, **attrs)
    raise ArgumentError, "unkown icon #{name.inspect}" unless NAMES.include?(name.to_s)

    @name = name
    @attrs = attrs

    # Hide the icon from screen readers by default.
    @attrs['aria-hidden'] = true unless @attrs.key?('aria-hidden')

    # Default icons without style to 16x16, mostly useful in test snapshots.
    @attrs['width'] = '16'
    @attrs['height'] = '16'
  end

  def call
    # bypass the asset_host configuration to avoid CORS issues with CDNs:
    # https://github.com/solidusio/solidus/issues/5657
    href = asset_path("solidus_admin/remixicon.symbol.svg#ri-#{@name}", host: "")
    tag.svg(tag.use("xlink:href": href), **@attrs)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
solidus_admin-0.3.2 app/components/solidus_admin/ui/icon/component.rb