Class: Primer::Beta::Avatar
- Defined in:
- app/components/primer/beta/avatar.rb
Overview
‘Avatar` can be used to represent users and organizations on GitHub.
-
Use the default circle avatar for users, and the square shape
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::Beta::AvatarStack) %>.
Constant Summary collapse
- DEFAULT_SIZE =
20
- SMALL_THRESHOLD =
24
- DEFAULT_SHAPE =
:circle
- SHAPE_OPTIONS =
[DEFAULT_SHAPE, :square].freeze
- SIZE_OPTIONS =
[16, DEFAULT_SIZE, SMALL_THRESHOLD, 32, 40, 48, 64, 80].freeze
Constants inherited from Component
Component::INVALID_ARIA_LABEL_TAGS
Constants included from Status::Dsl
Constants included from ViewHelper
Constants included from TestSelectorHelper
TestSelectorHelper::TEST_SELECTOR_TAG
Constants included from FetchOrFallbackHelper
FetchOrFallbackHelper::InvalidValueError
Constants included from AttributesHelper
AttributesHelper::PLURAL_ARIA_ATTRIBUTES, AttributesHelper::PLURAL_DATA_ATTRIBUTES
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(src:, alt: nil, size: DEFAULT_SIZE, shape: DEFAULT_SHAPE, href: nil, **system_arguments) ⇒ Avatar
constructor
A new instance of Avatar.
Methods inherited from Component
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
Methods included from AttributesHelper
#aria, #data, #extract_data, #merge_aria, #merge_data, #merge_prefixed_attribute_hashes
Methods included from ExperimentalSlotHelpers
Methods included from ExperimentalRenderHelpers
Constructor Details
#initialize(src:, alt: nil, size: DEFAULT_SIZE, shape: DEFAULT_SHAPE, href: nil, **system_arguments) ⇒ Avatar
Returns a new instance of Avatar.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/components/primer/beta/avatar.rb', line 36 def initialize(src:, alt: nil, size: DEFAULT_SIZE, shape: DEFAULT_SHAPE, href: nil, **system_arguments) @href = href @system_arguments = deny_tag_argument(**system_arguments) @system_arguments[:tag] = :img @system_arguments[:src] = src @system_arguments[:alt] = alt @system_arguments[:size] = fetch_or_fallback(SIZE_OPTIONS, size, DEFAULT_SIZE) @system_arguments[:height] = @system_arguments[:size] @system_arguments[:width] = @system_arguments[:size] @system_arguments[:classes] = class_names( system_arguments[:classes], "avatar", "avatar-small" => size < SMALL_THRESHOLD, "circle" => shape == DEFAULT_SHAPE, "lh-0" => href # Addresses an overflow issue with linked avatars ) end |
Instance Method Details
#call ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'app/components/primer/beta/avatar.rb', line 55 def call if @href render(Primer::Beta::Link.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 |