Skip to content
Likable Aurora @likable-hair/svelte 5

AvatarGroup

Row of overlapping avatars, for example the people assigned to a task. Every avatar is an Avatar built from an AvatarGroupItem, { name?: string; src?: string | Blob; text?: string; alt?: string; colorKey?: string | number; color?: …; status?: … }, with a Tooltip that shows its name. With maxVisible the extra avatars become a "+N" counter whose Tooltip lists their names. A thin gap in the color of --avatar-gap-color separates the avatars: set it to the background behind the group. The group is an ARIA group: give it an aria-label that says what the people are.

import { AvatarGroup } from '@likable-hair/svelte';

src/lib/components/simple/media/AvatarGroup.svelte · Markdown for LLMs

Group

The avatars overlap, separated by a thin gap; every avatar shows its name in a Tooltip. With maxVisible the others become a "+N" counter whose Tooltip lists them. aria-label tells what the people are.

MR GM SB +4
MR GM SB LF
Code
<script lang="ts">
	import { AvatarGroup, type AvatarGroupItem } from '@likable-hair/svelte';

	const team: AvatarGroupItem[] = [
		{ name: 'Mario Rossi', status: 'online' },
		{ name: 'Giulia Marini' },
		{ name: 'Sara Bianchi' },
		{ name: 'Luca Ferri' },
		{ name: 'Anna Greco' },
		{ name: 'Paolo Russo' },
		{ name: 'Chiara Costa' }
	];
</script>

<div class="demo">
	<AvatarGroup avatars={team} maxVisible={3} aria-label="Assigned people" />
	<AvatarGroup avatars={team.slice(0, 4)} aria-label="Reviewers" />
</div>

<style>
	.demo {
		display: flex;
		flex-direction: column;
		align-items: flex-start;
		gap: 16px;
	}
</style>

Sizes and shape

size and shape apply to every avatar and the overlap follows the size; --avatar-group-overlap and --avatar-group-gap-width change the overlap and the gap.

MR GM SB LF +2
MR GM SB LF +2
MR GM SB LF +2
MR GM SB LF +2
Code
<script lang="ts">
	import { AvatarGroup } from '@likable-hair/svelte';

	const team = ['Mario Rossi', 'Giulia Marini', 'Sara Bianchi', 'Luca Ferri', 'Anna Greco', 'Paolo Russo'].map((name) => ({ name }));
</script>

<div class="demo">
	<AvatarGroup avatars={team} maxVisible={4} size="xs" aria-label="Team" />
	<AvatarGroup avatars={team} maxVisible={4} size="sm" aria-label="Team" />
	<AvatarGroup avatars={team} maxVisible={4} size="lg" aria-label="Team" />
	<AvatarGroup avatars={team} maxVisible={4} shape="square" aria-label="Team" --avatar-group-overlap="6px" />
</div>

<style>
	.demo {
		display: flex;
		flex-direction: column;
		align-items: flex-start;
		gap: 16px;
	}
</style>

Props

NameTypeDefaultDescription
avatars requiredAvatarGroupItem[]The avatars, in order: the first one is at the start.
maxVisible numberShows at most this many avatars, followed by a "+N" counter whose Tooltip lists the hidden names.
size 'xs' | 'sm' | 'md' | 'lg' | 'xl''md'Size of every avatar: xs 24px, sm 32px, md 40px, lg 56px, xl 80px.
shape 'circle' | 'square''circle'Shape of every avatar.
tooltips booleantrueShows the name of every avatar in a Tooltip.
locale stringBCP 47 locale of the texts (it and en are built in, other languages fall back to English). Defaults to the one set with setDefaultLocale, else en.
moreLabel stringAccessible name of the counter. Defaults to "{count} more", in the language of locale; {count} is replaced with the number of hidden avatars.
avatarGroupElement bindable HTMLDivElementThe root <div> element.
class string''Extra classes on the root <div> element.

It also accepts the native attributes and events of <div> (for example id, title, aria-label, onkeydown), which are forwarded to the element.

Snippets

NameParametersDescription
avatarSnippet{ avatar: AvatarGroupItem; index: number }Replaces every avatar, for example to wrap it in a link.
counterSnippet{ count: number; hidden: AvatarGroupItem[] }Replaces the "+N" counter.

Types

Exported by the package: import type { AvatarGroupItem } from '@likable-hair/svelte';

AvatarGroupItem

type AvatarGroupItem = { … }

NameTypeDescription
name stringFull name: initials, color, accessible name and Tooltip.
src string | BlobImage: a URL, or a Blob/File.
text stringText shown instead of the initials of name.
alt stringAccessible name and Tooltip text instead of name.
colorKey string | numberValue that picks the color instead of name, for example the id of the person.
color 'auto' | 'primary' | 'neutral' | 1 | 2 | 3 | 4 | 5 | 6Fixed background instead of the one picked from colorKey or name.
status 'online' | 'away' | 'busy' | 'offline'Status dot in the bottom-right corner.

CSS variables

For a single instance, pass them as style props: <AvatarGroup --avatar-group-counter-color="tomato">. The --avatar-group-default-* defaults apply to the whole app: override them in :root or in a theme.

Per-instance variableDefault
--avatar-group-gap-width
--avatar-group-default-gap-width 2px
--avatar-group-overlap
--avatar-group-default-overlap 6px
--avatar-group-default-xs-overlap 4px
--avatar-group-default-sm-overlap 5px
--avatar-group-default-lg-overlap 9px
--avatar-group-default-xl-overlap 12px
--avatar-group-counter-background
--avatar-group-default-counter-background var(--avatar-default-neutral-background)
--avatar-group-counter-color
--avatar-group-default-counter-color var(--avatar-default-neutral-color)
--avatar-group-counter-font-size