Class: Primer::AvatarComponent

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

Overview

Avatars are images used to represent users and organizations on GitHub. Use the default round avatar for users, and the ‘square` argument for organizations or any other non-human avatars.

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.

Examples:

34|Default

<%= render(Primer::AvatarComponent.new(src: "http://placekitten.com/200/200", alt: "@kittenuser")) %>

Parameters:

  • src (String)

    The source url of the avatar image

  • alt (String)

    Passed through to alt on img tag

  • size (Integer) (defaults to: 20)

    Adds the avatar-small class if less than 24

  • square (Boolean) (defaults to: false)

    Used to create a square avatar.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/components/primer/avatar_component.rb', line 18

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



35
36
37
# File 'app/components/primer/avatar_component.rb', line 35

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