Avatar group
FreeWho is here, as overlapping glass coins each cut out of the one behind it by a ring of the surface, ending in a grey +N.
npx shadcn@latest add https://pixilui.com/r/avatar-group.jsonPreview
Overlapping coins, each cut out of the one behind it.
Size
import { Avatar } from "@/components/pixilui/avatar";
import { Tooltip, TooltipGroup } from "@/components/pixilui/tooltip";
import { AvatarGroup } from "@/components/pixilui/avatar-group";
// The first option of each knob is the demo's default; the docs preview starts there.
export const knobs = {
size: ["32", "24", "40"],
} as const;
const people: [string, string][] = [
["Maya Rao", "Admin"],
["Ben Ito", "Watching"],
["Hana Ito", "Editor"],
["Dev Patel", "Asked for this run"],
];
/** Who is on a run, with name tips that travel along the stack, and three more. */
export default function AvatarGroupDemo({ size = "32" }: KnobValues<typeof knobs>) {
const px = Number(size);
return (
<div className="flex items-center gap-3 type-label text-secondary">
<TooltipGroup>
<AvatarGroup more={3} moreLabel="3 more people" size={px}>
{people.map(([name, role]) => (
<Tooltip key={name} label={name} secondary={role} name>
<Avatar name={name} size={px} tabIndex={0} />
</Tooltip>
))}
</AvatarGroup>
</TooltipGroup>
<span>7 people on this run</span>
</div>
);
}When to use
Use it when
- Who is watching a run, who is on a workspace, who approved.
Use something else when
- One person: use Avatar beside their name.
- A list people need to read: write the names.
Installation
Terminal
npx shadcn@latest add https://pixilui.com/r/avatar-group.jsonAdds avatar-group.tsx with avatar.tsx, and installs clsx and tailwind-merge. The URL works in any app with a components.json, with no registry to add first.
components/pixilui/avatar-group.tsx
/*
A stack of glass coins, locked 1 Dec 2026 with the user avatar (design/explorations/components/locked/user-avatar):
each coin overlaps the one before by a fifth of a face and is cut out by a ring of the surface; the last can
be +N, a grey coin. Its look is foundation.css section 8 (.pixilui-user-avatars). No motion of its own: a
person arriving or leaving uses the foundation's arrive and leave (lib/motion/surface).
*/
import { forwardRef, type ComponentPropsWithoutRef, type ReactNode } from "react";
import { cn } from "./lib/utils";
export type AvatarGroupProps = ComponentPropsWithoutRef<"span"> & {
/** The coins, as Avatar elements, first in front of the reading order. */
children: ReactNode;
/** How many more people there are: shown as a grey +N coin at the end. Zero or less shows nothing. */
more?: number;
/** The +N coin's accessible name, such as "3 more people". Without it the coin reads its number. */
moreLabel?: string;
/** The coins' size in px, for the +N coin; give the Avatars the same size. */
size?: number;
};
/** Overlapping coins for who is here, each cut out of the one behind it, with an optional +N. */
export const AvatarGroup = forwardRef<HTMLSpanElement, AvatarGroupProps>(function AvatarGroup({ children, more, moreLabel, size, className, ...props }, ref) {
return (
<span ref={ref} className={cn("pixilui-user-avatars font-body", className)} {...props}>
{children}
{more && more > 0 ? <MoreCoin count={more} label={moreLabel} size={size} /> : null}
</span>
);
});
/** The +N coin: grey, for no one in particular. */
function MoreCoin({ count, label, size }: { count: number; label?: string; size?: number }) {
const sized = size !== undefined && [16, 20, 24, 40, 48].includes(size) ? size : undefined;
return (
<span className="pixilui-user-avatar font-body" data-tone="grey" data-size={sized} {...(label ? { role: "img", "aria-label": label } : {})}>
{`+${count}`}
</span>
);
}
It uses Avatar: add it the same way. Then npm i clsx tailwind-merge, and add the foundation once per app, as in Installation.
Usage
example.tsx
import { AvatarGroup } from "@/components/pixilui/avatar-group";
<AvatarGroup>Save changes</AvatarGroup>Each coin overlaps the one before by a fifth of a face; the stack keeps its size and never wraps.
API reference
PropTypeDefault
childrenRequiredReactNode–The coins, as Avatar elements, first in front of the reading order.morenumber–How many more people there are: shown as a grey +N coin at the end. Zero or less shows nothing.moreLabelstring–The +N coin's accessible name, such as "3 more people". Without it the coin reads its number.sizenumber–The coins' size in px, for the +N coin; give the Avatars the same size.Also takes every native <span> attribute, and a ref.
Keyboard
TabNever takes focus on its own; wrap it in a TooltipGroup with name tips to make each coin a stop.
Accessibility
- Each coin keeps its own name; the +N coin is named by moreLabel ("3 more people").
- For name tips that travel along the stack, give each coin a Tooltip with name inside a TooltipGroup.
Motion
- None of its own: it holds still. A person arriving or leaving uses the foundation's arrive and leave.