Class: Blacklight::Icons::LegacyIconComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/blacklight/icons/legacy_icon_component.rb

Instance Method Summary collapse

Constructor Details

#initialize(name:, classes: '', aria_hidden: false, label: true, role: 'img', additional_options: {}) ⇒ LegacyIconComponent

Returns a new instance of LegacyIconComponent.



6
7
8
9
10
11
# File 'app/components/blacklight/icons/legacy_icon_component.rb', line 6

def initialize(name:, classes: '', aria_hidden: false, label: true, role: 'img', additional_options: {})
  @name = name
  @classes = classes
  @aria_hidden = aria_hidden
  @icon = Blacklight::Icon.new(name, classes: classes, label: label, role: role, additional_options: additional_options)
end

Instance Method Details

#callObject



13
14
15
16
17
# File 'app/components/blacklight/icons/legacy_icon_component.rb', line 13

def call
  tag.span(svg&.html_safe || default_icon, # rubocop:disable Rails/OutputSafety
           class: "blacklight-icons blacklight-icon-#{@name} #{@classes}".strip,
           'aria-hidden': (true if @aria_hidden))
end

#default_iconObject



25
26
27
# File 'app/components/blacklight/icons/legacy_icon_component.rb', line 25

def default_icon
  @icon.icon_label
end

#svgObject



19
20
21
22
23
# File 'app/components/blacklight/icons/legacy_icon_component.rb', line 19

def svg
  Rails.cache.fetch([:blacklight_icon_svg, @name]) do
    @icon.svg if @icon.present?
  end
end