# Avatar Stack

`AvatarStack` shows the people in a document or room as overlapping avatars. It works like the stacks of [Liveblocks](https://liveblocks.io/docs/api-reference/liveblocks-react-ui#AvatarStack), [Kibo UI](https://www.kibo-ui.com/components/avatar-stack), and [Supabase UI](https://supabase.com/ui/docs/nextjs/realtime-avatar-stack): same name, a `max` that counts the "+N" item, and one avatar per person. Pass Realtime's `people` as they are.

_Interactive preview available on the rendered documentation page._


## Installation

Install `@vite-hub/ui` as [Installation](https://vitehub.dev/docs/ui/installation) shows. `vite-hub/nuxt` auto-imports the component. In Vue with Vite, import it from `@vite-hub/ui` or `@vite-hub/ui/avatar-stack`:

```ts
import { AvatarStack } from "@vite-hub/ui";
```

## Usage

```ts
import { AvatarStack } from "@vite-hub/ui";
import { useRealtimeTiptap } from "vite-hub/realtime/vue";

const { people } = useRealtimeTiptap("docs", "guides/welcome.md");
```

```vue
<template>
  <AvatarStack :people="people" variant="outline" />
</template>
```

## Composition

```text
AvatarStack
├── avatar-stack-item (one per person)
│   └── avatar-stack-image or avatar-stack-fallback
└── avatar-stack-count (+N)
```

## Features

- One avatar per person: entries with the same `id`, such as one person in two tabs, show once.
- An image, or the person's initials without one.
- `outline` rings each avatar in the person's presence color, to match their caret.
- Hover an avatar to see the name. Hover the count to list hidden names.
- Default styles sit in the `components` layer of `@vite-hub/ui/styles.css`.

## Outline

Use `variant="outline"` in an editor, where each person also has a caret in their color.

_Interactive preview available on the rendered documentation page._


## Sizes

_Interactive preview available on the rendered documentation page._


| Size      | Avatar |
| --------- | ------ |
| `sm`      | 24 px  |
| `default` | 32 px  |
| `lg`      | 40 px  |

## Max

`max` is the most items in the stack, counting the "+N" item, so `max` items always fit. It is at least 2, so one face always shows. `null` shows everyone.

_Interactive preview available on the rendered documentation page._


## Accessibility

The stack has `role="group"` and an `aria-label` that names everyone, such as "3 people: Ana, Ben, Cleo". Assistive technology reads it once and skips the decorative avatars.

## API Reference

### AvatarStack

Renders a `div` with `data-slot="avatar-stack"`. Each avatar is a `span` with `data-slot="avatar-stack-item"`, and the count is a `span` with `data-slot="avatar-stack-count"`.

#### Props

| Prop      | Type                             | Default     | Description                                                                 |
| --------- | -------------------------------- | ----------- | --------------------------------------------------------------------------- |
| `people`  | `AvatarStackPerson[]`            | Required    | `{ id, name, image?, color? }`. Entries with the same `id` show once. |
| `max`     | `number \| null`                 | `3`         | Most items, counting "+N". `null` shows everyone. |
| `size`    | `"sm" \| "default" \| "lg"`      | `"default"` | The avatar size.                                                            |
| `variant` | `"default" \| "outline"`         | `"default"` | `outline` rings each avatar in the person's `color`.                        |

## Related

- [Connection Status](https://vitehub.dev/docs/ui/connection-status) and [Sync Status](https://vitehub.dev/docs/ui/sync-status) show the state of the same room.
- [Carets](https://vitehub.dev/docs/ui/carets) styles the editor carets in the same colors.
- [Realtime](https://vitehub.dev/docs/realtime) provides `people`.
- [Collaborative Editor](https://vitehub.dev/docs/ui/blocks/collaborative-editor) combines all collaboration parts with Realtime.

<!-- vitehub-docs:section-links -->
## In this section

- [Start](https://vitehub.dev/raw/docs/ui.md)
- [Blocks](https://vitehub.dev/raw/docs/ui/blocks/chat-app.md)
- [Parts](https://vitehub.dev/raw/docs/ui/message.md)
- [Chat](https://vitehub.dev/raw/docs/ui/chat.md)
- Collaboration
  - [Avatar Stack](https://vitehub.dev/raw/docs/ui/avatar-stack.md) (this page)
  - [Connection Status](https://vitehub.dev/raw/docs/ui/connection-status.md)
  - [Sync Status](https://vitehub.dev/raw/docs/ui/sync-status.md)
  - [Carets](https://vitehub.dev/raw/docs/ui/carets.md)
  - [Comments](https://vitehub.dev/raw/docs/ui/comments.md)
  - [Markdown Editor](https://vitehub.dev/raw/docs/ui/markdown-editor.md)
- [Agent work](https://vitehub.dev/raw/docs/ui/tool-list.md)
- [Utilities](https://vitehub.dev/raw/docs/ui/attachments.md)

Next: [Connection Status](https://vitehub.dev/raw/docs/ui/connection-status.md)

All pages: [llms.txt](https://vitehub.dev/llms.txt)
