class Primer::Beta::NavList

‘selected_item_id` argument to select the appropriate item.
or more ID values that determine which item will appear selected. Use the
Nav list items appear visually active when selected. Each nav item must have one
when the group expands and collapses.
group will automatically render with a trailing chevron icon that changes direction
with sub items expand and collapse on click. To indicate this functionality, the
Nav list groups can contain sub items. Rather than navigating to a URL, groups
nav list is a list of links.
that appears to the left or right side of some main content. Each group in a
`NavList` provides a simple way to render side navigation, i.e. navigation

def self.custom_element_name

Other tags:
    Private: -
def self.custom_element_name
  "nav-list"
end

def before_render

def before_render
  if heading?
    raise ArgumentError, "Please don't set an aria-label if a heading is provided" if aria(:label, @system_arguments)
    @system_arguments[:aria] = merge_aria(
      @system_arguments,
      { aria: { labelledby: heading.id } }
    )
  else
    raise ArgumentError, "When no heading is provided, an aria-label must be given" unless aria(:label, @system_arguments)
  end
end

def both_are_groups?(item1, item2)

def both_are_groups?(item1, item2)
  group?(item1) && group?(item2)
end

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)

Parameters:
  • 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.
  • avatar_arguments (Hash) -- Optional. The arguments accepted by <%= link_to_component(Primer::Beta::Avatar) %>
  • component_klass (Class) -- The class to use instead of the default <%= link_to_component(Primer::Beta::NavList::Item) %>
  • full_name_scheme (Symbol) -- Optional. How to display the user's full name. <%= one_of(Primer::Alpha::ActionList::Item::DESCRIPTION_SCHEME_OPTIONS) %>
  • full_name (String) -- Optional. The user's full name.
  • username (String) -- The username associated with the avatar.
  • src (String) -- The source url of the avatar image.
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

def build_item(component_klass: Primer::Beta::NavList::Item, **system_arguments, &block)

Parameters:
  • 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.
  • component_klass (Class) -- The class to use instead of the default <%= link_to_component(Primer::Beta::NavList::Item) %>
def build_item(component_klass: Primer::Beta::NavList::Item, **system_arguments, &block)
  component_klass.new(
    list: top_level_group,
    selected_item_id: @selected_item_id,
    **system_arguments,
    &block
  )
end

def divider?(item)

def divider?(item)
  kind(item) == :divider
end

def either_is_divider?(item1, item2)

def either_is_divider?(item1, item2)
  divider?(item1) || divider?(item2)
end

def group?(item)

def group?(item)
  kind(item) == :group
end

def heterogeneous?(item1, item2)

def heterogeneous?(item1, item2)
  kind(item1) != kind(item2)
end

def initialize(selected_item_id: nil, **system_arguments)

Parameters:
  • system_arguments (Hash) -- <%= link_to_system_arguments_docs %>
  • selected_item_id (Symbol) -- The ID of the currently selected item. The default is `nil`, meaning no item is selected.
def initialize(selected_item_id: nil, **system_arguments)
  @system_arguments = system_arguments
  @selected_item_id = selected_item_id
end

def kind(item)

def kind(item)
  item.respond_to?(:kind) ? item.kind : :item
end

def render_divider_between?(item1, item2)

def render_divider_between?(item1, item2)
  return false if either_is_divider?(item1, item2)
  both_are_groups?(item1, item2) || heterogeneous?(item1, item2)
end

def render_outer_list?

Lists that contain top-level items (i.e. items outside of a group) should be wrapped in a `
    `
def render_outer_list?
  items.any? { |item| !group?(item) }
end

def top_level_group

def top_level_group
  # dummy group for the list: argument in the item slot above
  @top_level_group ||= Primer::Beta::NavList::Group.new(selected_item_id: @selected_item_id)
end