Class: Blacklight::Icons::IconComponent

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

Overview

This is the list icon for the search button. You can override the default svg by setting:

Blacklight::Icons::ListComponent.svg = '<svg>your SVG here</svg>'

Direct Known Subclasses

ListComponent, SearchComponent

Instance Method Summary collapse

Constructor Details

#initialize(svg: nil, tag: :span, name: nil, label: nil, aria_hidden: nil, classes: nil, **options) ⇒ IconComponent

rubocop:disable Metrics/ParameterLists



10
11
12
13
14
15
16
# File 'app/components/blacklight/icons/icon_component.rb', line 10

def initialize(svg: nil, tag: :span, name: nil, label: nil, aria_hidden: nil, classes: nil, **options)
  self.svg = svg if svg
  @classes = Array(classes) + ['blacklight-icons', "blacklight-icons-#{name}"]
  @name = name
  @tag = tag
  @options = options.merge(aria: options.fetch(:aria, {}).reverse_merge(label: label, hidden: aria_hidden))
end

Instance Method Details

#callObject

rubocop:enable Metrics/ParameterLists



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

def call
  tag.public_send(@tag, svg&.html_safe, # rubocop:disable Rails/OutputSafety
                  class: @classes,
                  **@options)
end

#nameObject



27
28
29
# File 'app/components/blacklight/icons/icon_component.rb', line 27

def name
  @name ||= self.class.name.demodulize.underscore.sub('_component', '')
end