Class: Primer::AvatarComponent
- Defined in:
- app/components/primer/avatar_component.rb
Overview
‘Avatar` can be 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.
-
By default, ‘Avatar` will render a static `<img>`. To have `Avatar` function as a link, set the `href` which will wrap the `<img>` in a `<a>`.
-
Set ‘size` to update the height and width of the `Avatar` in pixels.
-
To stack multiple avatars together, use <%= link_to_component(Primer::AvatarStackComponent) %>.
Constant Summary collapse
- SMALL_THRESHOLD =
24
Constants included from Status::Dsl
Constants included from ViewHelper
Constants included from TestSelectorHelper
TestSelectorHelper::TEST_SELECTOR_TAG
Constants included from FetchOrFallbackHelper
FetchOrFallbackHelper::InvalidValueError
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(src:, alt:, size: 20, square: false, href: nil, **system_arguments) ⇒ AvatarComponent
constructor
A new instance of AvatarComponent.
Methods included from JoinStyleArgumentsHelper
Methods included from TestSelectorHelper
Methods included from FetchOrFallbackHelper
#fetch_or_fallback, #fetch_or_fallback_boolean, #silence_deprecations?
Methods included from ClassNameHelper
Constructor Details
#initialize(src:, alt:, size: 20, square: false, href: nil, **system_arguments) ⇒ AvatarComponent
Returns a new instance of AvatarComponent.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/components/primer/avatar_component.rb', line 46 def initialize(src:, alt:, size: 20, square: false, href: nil, **system_arguments) @href = href @system_arguments = system_arguments @system_arguments[:tag] = :img @system_arguments[:src] = src @system_arguments[:alt] = alt @system_arguments[:size] = size @system_arguments[:height] = size @system_arguments[:width] = size @system_arguments[:classes] = class_names( system_arguments[:classes], "avatar", "avatar-small" => size < SMALL_THRESHOLD, "circle" => !square, "lh-0" => href # Addresses an overflow issue with linked avatars ) end |
Instance Method Details
#call ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'app/components/primer/avatar_component.rb', line 65 def call if @href render(Primer::LinkComponent.new(href: @href, classes: @system_arguments[:classes])) do render(Primer::BaseComponent.new(**@system_arguments.except(:classes))) { content } end else render(Primer::BaseComponent.new(**@system_arguments)) { content } end end |