Class: FluentIcons::Component
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- FluentIcons::Component
- Defined in:
- lib/fluent-icons/component.rb
Overview
ViewComponent for rendering Fluent Icons
Usage:
<%= render FluentIcons::Component.new(name: "add") %>
<%= render FluentIcons::Component.new(name: "delete", style: "filled", weight: 24) %>
<%= render FluentIcons::Component.new(name: "search", class: "w-4 h-4 text-blue-500") %>
With Hotwire/Turbo:
<%= render FluentIcons::Component.new(name: "refresh", data: { action: "click->controller#refresh" }) %>
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(name:, style: 'regular', weight: 20, **options) ⇒ Component
constructor
A new instance of Component.
Constructor Details
#initialize(name:, style: 'regular', weight: 20, **options) ⇒ Component
Returns a new instance of Component.
18 19 20 21 22 23 |
# File 'lib/fluent-icons/component.rb', line 18 def initialize(name:, style: 'regular', weight: 20, **) @name = name.to_s @style = style.to_s @weight = weight.to_i @options = end |
Instance Method Details
#call ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/fluent-icons/component.rb', line 25 def call # Use the existing caching system from the helper svg_html = Cache.fetch(@name, ) do icon = FluentIcons::Fluent.new(@name, style: @style, weight: @weight, **@options) icon.to_svg end svg_html.html_safe end |