Class: StimulusPlumbers::Components::Avatar::Renderer

Inherits:
Plumber::Base
  • Object
show all
Defined in:
lib/stimulus_plumbers/components/avatar/renderer.rb

Instance Attribute Summary

Attributes inherited from Plumber::Base

#template

Instance Method Summary collapse

Methods inherited from Plumber::Base

#initialize, #theme

Methods included from Plumber::HtmlOptions

#merge_html_options, #merge_string_option, #normalize_part

Constructor Details

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

Instance Method Details

#avatar(name: nil, initials: nil, url: nil, color: nil, size: :md, **kwargs, &block) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/stimulus_plumbers/components/avatar/renderer.rb', line 7

def avatar(name: nil, initials: nil, url: nil, color: nil, size: :md, **kwargs, &block)
  color_css = resolve_color(color, name, initials) unless url || block_given?

  html_options = merge_html_options(
    {
      classes:      [theme.resolve(:avatar, size: size).fetch(:classes, ""), color_css],
      "aria-label": name,
      role:         "img"
    },
    kwargs
  )

  template.(:span, inner(name, initials, url, &block), **html_options)
end