# 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.

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

Category: simple. Source: `src/lib/components/simple/media/AvatarGroup.svelte`.

## Examples

### 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.

```svelte
<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.

```svelte
<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

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `avatars` (required) | `AvatarGroupItem[]` |  | The avatars, in order: the first one is at the start. |
| `maxVisible` | `number` |  | Shows 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` | `boolean` | `true` | Shows the name of every avatar in a Tooltip. |
| `locale` | `string` |  | BCP 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` | `string` |  | Accessible name of the counter. Defaults to "{count} more", in the language of `locale`; `{count}` is replaced with the number of hidden avatars. |
| `avatarGroupElement` (bindable) | `HTMLDivElement` |  | The 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

| Name | Parameters | Description |
| --- | --- | --- |
| `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 = { … }`

| Name | Type | Description |
| --- | --- | --- |
| `name` | `string` | Full name: initials, color, accessible name and Tooltip. |
| `src` | `string \| Blob` | Image: a URL, or a `Blob`/`File`. |
| `text` | `string` | Text shown instead of the initials of `name`. |
| `alt` | `string` | Accessible name and Tooltip text instead of `name`. |
| `colorKey` | `string \| number` | Value that picks the color instead of `name`, for example the id of the person. |
| `color` | `'auto' \| 'primary' \| 'neutral' \| 1 \| 2 \| 3 \| 4 \| 5 \| 6` | Fixed 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 variable | Default |
| --- | --- |
| `--avatar-group-gap-width` | `--avatar-group-default-gap-width`: `2px` |
| `--avatar-group-overlap` | `--avatar-group-default-overlap`: `6px`<br>`--avatar-group-default-xs-overlap`: `4px`<br>`--avatar-group-default-sm-overlap`: `5px`<br>`--avatar-group-default-lg-overlap`: `9px`<br>`--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` |  |
