Class: Maglev::Uikit::IconComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Maglev::Uikit::IconComponent
- Defined in:
- app/components/maglev/uikit/icon_component.rb
Instance Attribute Summary collapse
-
#class_names ⇒ Object
readonly
Returns the value of attribute class_names.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(name:, size: '1.25rem', class_names: nil) ⇒ IconComponent
constructor
A new instance of IconComponent.
Constructor Details
#initialize(name:, size: '1.25rem', class_names: nil) ⇒ IconComponent
Returns a new instance of IconComponent.
8 9 10 11 12 |
# File 'app/components/maglev/uikit/icon_component.rb', line 8 def initialize(name:, size: '1.25rem', class_names: nil) @name = name @size = size @class_names = class_names end |
Instance Attribute Details
#class_names ⇒ Object (readonly)
Returns the value of attribute class_names.
6 7 8 |
# File 'app/components/maglev/uikit/icon_component.rb', line 6 def class_names @class_names end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'app/components/maglev/uikit/icon_component.rb', line 6 def name @name end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
6 7 8 |
# File 'app/components/maglev/uikit/icon_component.rb', line 6 def size @size end |
Instance Method Details
#call ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/components/maglev/uikit/icon_component.rb', line 14 def call icon_svg = ICONS[name] || raise("Icon '#{name}' not found") # Apply styling and classes to the SVG styled_svg = icon_svg.gsub( '<svg xmlns="http://www.w3.org/2000/svg" ', "<svg xmlns=\"http://www.w3.org/2000/svg\" style=\"#{style}\" class=\"#{final_class_names}\"" ) # rubocop:disable Rails/OutputSafety styled_svg.html_safe # rubocop:enable Rails/OutputSafety end |