Class: Maglev::Uikit::IconComponent

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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_namesObject (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

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'app/components/maglev/uikit/icon_component.rb', line 6

def name
  @name
end

#sizeObject (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

#callObject



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