Method: Primer::Beta::NavList#build_avatar_item

Defined in:
app/components/primer/beta/nav_list.rb

#build_avatar_item(src:, username:, full_name: nil, full_name_scheme: Primer::Alpha::ActionList::Item::DEFAULT_DESCRIPTION_SCHEME, component_klass: Primer::Beta::NavList::Item, avatar_arguments: {}, **system_arguments) ⇒ Object

Builds a new avatar item but does not add it to the list. Avatar items are a convenient way to accessibly add an item with a leading avatar image. Use this method instead of the ‘#with_avatar_item` slot if you need to render an avatar item outside the context of a list, eg. if rendering additional items to append to an existing list, perhaps via a separate HTTP request.

Parameters:

  • src (String)

    The source url of the avatar image.

  • username (String)

    The username associated with the avatar.

  • full_name (String) (defaults to: nil)

    Optional. The user’s full name.

  • full_name_scheme (Symbol) (defaults to: Primer::Alpha::ActionList::Item::DEFAULT_DESCRIPTION_SCHEME)

    Optional. How to display the user’s full name. <%= one_of(Primer::Alpha::ActionList::Item::DESCRIPTION_SCHEME_OPTIONS) %>

  • component_klass (Class) (defaults to: Primer::Beta::NavList::Item)

    The class to use instead of the default <%= link_to_component(Primer::Beta::NavList::Item) %>

  • avatar_arguments (Hash) (defaults to: {})

    Optional. The arguments accepted by <%= link_to_component(Primer::Beta::Avatar) %>

  • system_arguments (Hash)

    These arguments are forwarded to <%= link_to_component(Primer::Beta::NavList::Item) %>, or whatever class is passed as the ‘component_klass` argument.

[View source]

139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'app/components/primer/beta/nav_list.rb', line 139

def build_avatar_item(src:, username:, full_name: nil, full_name_scheme: Primer::Alpha::ActionList::Item::DEFAULT_DESCRIPTION_SCHEME, component_klass: Primer::Beta::NavList::Item, avatar_arguments: {}, **system_arguments)
  component_klass.new(
    list: top_level_group,
    selected_item_id: @selected_item_id,
    label: username,
    description_scheme: full_name_scheme,
    **system_arguments
  ).tap do |item|
    item.with_leading_visual_raw_content do
      # no alt text necessary
      item.render(Primer::Beta::Avatar.new(src: src, **avatar_arguments, role: :presentation, size: 16))
    end

    item.with_description_content(full_name) if full_name
  end
end