Class: Primer::AvatarComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/primer/avatar_component.rb

Constant Summary collapse

SMALL_THRESHOLD =
24

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::InvalidValueError

Instance Method Summary collapse

Methods included from FetchOrFallbackHelper

#fetch_or_fallback

Methods included from ClassNameHelper

#class_names

Constructor Details

#initialize(src:, alt:, size: 20, square: false, **kwargs) ⇒ AvatarComponent

Returns a new instance of AvatarComponent.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/components/primer/avatar_component.rb', line 7

def initialize(src:, alt:, size: 20, square: false, **kwargs)
  @kwargs = kwargs
  @kwargs[:tag] = :img
  @kwargs[:src] = src
  @kwargs[:alt] = alt
  @kwargs[:size] = size
  @kwargs[:height] = size
  @kwargs[:width] = size

  @kwargs[:classes] = class_names(
    "avatar",
    kwargs[:classes],
    "avatar--small" => size < SMALL_THRESHOLD,
    "CircleBadge" => !square
  )
end

Instance Method Details

#callObject



24
25
26
# File 'app/components/primer/avatar_component.rb', line 24

def call
  render(Primer::BaseComponent.new(**@kwargs)) { content }
end