Class: SolidusAdmin::UI::Icon::Component
- Inherits:
-
BaseComponent
- Object
- BaseComponent
- SolidusAdmin::UI::Icon::Component
- Defined in:
- app/components/solidus_admin/ui/icon/component.rb
Constant Summary collapse
- NAMES =
Set.new(File.read("#{__dir__}/names.txt").split("\n").map(&:freeze)).freeze
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(name:, **attrs) ⇒ Component
constructor
Renders a remixincon svg.
Constructor Details
#initialize(name:, **attrs) ⇒ Component
Renders a remixincon svg.
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/components/solidus_admin/ui/icon/component.rb', line 11 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 |
Instance Method Details
#call ⇒ Object
25 26 27 28 29 30 |
# File 'app/components/solidus_admin/ui/icon/component.rb', line 25 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 |