PeakUI

AvatarGroup

Stacks or tiles avatars with an overflow count

Usage

import {Avatar, AvatarGroup} from "@peakui/react";

Anatomy

import {Avatar, AvatarGroup} from "@peakui/react";

export default () => (
  <AvatarGroup>
    <Avatar>
      <Avatar.Image />
      <Avatar.Fallback />
    </Avatar>
    <AvatarGroup.Count /> {/* Optional */}
  </AvatarGroup>
);

Examples

Max

max renders that many avatars and a +N count of the rest.

With Count

An explicit AvatarGroup.Count suits a total the server knows. It is not truncated by max and replaces the automatic count.

Sizes

Colors

color is given to every child that omits it.

Variants

Grid

Overlap

Customization

Tailwind CSS

Global CSS

@layer components {
  .avatar-group {
    --avatar-group-overlap: 0.75rem;
    --avatar-group-seam: 2px;
  }

  .avatar-group__count {
    @apply font-semibold;
  }
}

Styling Reference

PeakUI follows the BEM methodology, so variants and states are plain class names you can target.

CSS Classes

The AvatarGroup component uses these CSS classes (view source styles):

Base & Element Classes

  • .avatar-group - Base container
  • .avatar-group__count - Overflow count avatar

Layout Classes

  • .avatar-group--grid - Wrapping grid, no overlap

Overlap Classes

  • .avatar-group--clip - Crescent mask with a transparent seam, the default
  • .avatar-group--ring - Solid outline in the background color

Slots

  • [data-slot="avatar-group"]
  • [data-slot="avatar-group-count"]

CSS Variables

VariablePurpose
--avatar-group-overlapHow far each avatar sits over its neighbour (0.5rem)
--avatar-group-seamWidth of the seam or ring between avatars (2px)

API Reference

AvatarGroup

Only direct Avatar children receive size, color, variant and the max cut: an Avatar inside a wrapper component is left alone. The group has no default role; pass role="group" with aria-label when the stack is meaningful.

PropTypeDefaultDescription
size'sm' | 'md' | 'lg''md'Size given to children that omit size
color'default' | 'accent' | 'success' | 'warning' | 'danger'-Color given to children that omit color
variant'default' | 'soft'-Variant given to children that omit variant
maxnumber-Most avatars to render; omit to render all
overlap'clip' | 'ring''clip'Stacked overlap style; ignored when isGrid
isGridbooleanfalseWraps the avatars in a grid without overlap
childrenReactNode-Avatar elements and an optional AvatarGroup.Count
classNamestring-Additional classes
renderDOMRenderFunction<E, undefined>-Replaces the rendered element; E defaults to 'div'
...restEvery <div> attribute is accepted

AvatarGroup.Count

PropTypeDefaultDescription
childrenReactNode-Count content, such as +3
size'sm' | 'md' | 'lg'group'sOverrides the group's size
color'default' | 'accent' | 'success' | 'warning' | 'danger'group'sOverrides the group's color
variant'default' | 'soft'group'sOverrides the group's variant
classNamestring-Additional classes
...restEvery <span> attribute is accepted

On this page