Class: Kanso::IconComponent

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, **options) ⇒ IconComponent

Returns a new instance of IconComponent.



7
8
9
10
# File 'app/components/kanso/icon_component.rb', line 7

def initialize(name:, **options)
  @name = name
  @options = options
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'app/components/kanso/icon_component.rb', line 5

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'app/components/kanso/icon_component.rb', line 5

def options
  @options
end

Instance Method Details

#callObject



12
13
14
15
16
17
18
19
# File 'app/components/kanso/icon_component.rb', line 12

def call
  attributes = tag.attributes(
    options.deep_merge(data: { icon_name: name })
  )

  raw_svg = cached_svg_content
  raw_svg.sub("<svg", "<svg #{attributes}").html_safe
end