Class: StimulusPlumbers::Components::Icon

Inherits:
Plumber::Base show all
Defined in:
lib/stimulus_plumbers/components/icon.rb

Instance Attribute Summary

Attributes inherited from Plumber::Base

#template

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Plumber::Base

#initialize, #theme

Methods included from Plumber::Renderer

#set_slots, #slot_block_for, #slot_kwargs_for, #slot_renderable?

Methods included from Plumber::Options::Aria

#labelled_aria

Methods included from Plumber::Options::Html

#merge_html_options

Constructor Details

This class inherits a constructor from StimulusPlumbers::Plumber::Base

Class Method Details

.icon_name?(value) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/stimulus_plumbers/components/icon.rb', line 6

def self.icon_name?(value)
  value.is_a?(Symbol) || (value.is_a?(String) && !value.html_safe?)
end

Instance Method Details

#render(name:, **kwargs) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/stimulus_plumbers/components/icon.rb', line 10

def render(name:, **kwargs)
  html_options = merge_html_options(
    theme.resolve(:icon),
    kwargs
  )

  icon_data = Themes::Schema::Icon.resolve(theme.icons[name.to_s])
  if icon_data
    svg_icon(icon_data, html_options)
  else
    template.tag.span(**html_options)
  end
end