Class: Blacklight::Icons::IconComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Blacklight::Icons::IconComponent
- Defined in:
- app/components/blacklight/icons/icon_component.rb
Overview
This is the base class for icon components. You should extend this class for each icon.
You can override the default svg by setting:
Blacklight::Icons::MyIconComponent.svg = '<svg>your SVG here</svg>'
Direct Known Subclasses
BookmarkIconComponent, ListComponent, RemoveComponent, SearchComponent
Instance Method Summary collapse
-
#call ⇒ Object
rubocop:enable Metrics/ParameterLists.
- #classes ⇒ Object
-
#initialize(svg: nil, tag: :span, name: nil, label: nil, aria_hidden: nil, classes: nil, **options) ⇒ IconComponent
constructor
rubocop:disable Metrics/ParameterLists.
- #name ⇒ Object
Constructor Details
#initialize(svg: nil, tag: :span, name: nil, label: nil, aria_hidden: nil, classes: nil, **options) ⇒ IconComponent
rubocop:disable Metrics/ParameterLists
11 12 13 14 15 16 17 |
# File 'app/components/blacklight/icons/icon_component.rb', line 11 def initialize(svg: nil, tag: :span, name: nil, label: nil, aria_hidden: nil, classes: nil, **) self.svg = svg if svg @name = name @assigned_classes = Array(classes) @tag = tag @options = .merge(aria: .fetch(:aria, {}).reverse_merge(label: label, hidden: aria_hidden)) end |
Instance Method Details
#call ⇒ Object
rubocop:enable Metrics/ParameterLists
20 21 22 23 24 |
# File 'app/components/blacklight/icons/icon_component.rb', line 20 def call tag.public_send(@tag, svg&.html_safe, # rubocop:disable Rails/OutputSafety class: classes, **@options) end |
#classes ⇒ Object
28 29 30 |
# File 'app/components/blacklight/icons/icon_component.rb', line 28 def classes @classes ||= @assigned_classes + ['blacklight-icons', "blacklight-icons-#{name}"] end |
#name ⇒ Object
32 33 34 |
# File 'app/components/blacklight/icons/icon_component.rb', line 32 def name @name ||= self.class.name.demodulize.underscore.sub('_component', '') end |