Avatar stack
Slant / People & chat
Overlapping avatars; the count for the rest opens the full list.
Demo
Usage
import { AvatarStack, type AvatarPerson } from '@tuttn/slant'
const people: AvatarPerson[] = [
{ id: 'ak', initials: 'AK', name: 'Ada K.', status: 'online' },
{ id: 'jr', initials: 'JR', name: 'Juno R.', status: 'away' },
{ id: 'ts', initials: 'TS', name: 'Tal S.' },
]
// Past max, the rest collapse into one "+N" bubble, a button that opens a
// list of everyone under the stack. It keeps its own open state.
<AvatarStack people={people} label="People on this project" max={4} />
// Control it with open and onOpenChange, or keep a static bubble.
<AvatarStack people={reviewers} label="Reviewers" max={3} open={open} onOpenChange={setOpen} />
<AvatarStack people={watchers} label="Watchers" max={3} expandable={false} />
// overflow draws the bubble's text; screen readers still hear "17 more".
<AvatarStack people={watchers} label="Watchers" max={3}
overflow={hidden => hidden > 9 ? '9+' : `+${hidden}`} />Props
| Prop | Type | Default | Description |
|---|---|---|---|
people | AvatarPerson[] | — | The people, in order: `{ id, name, initials?, src?, status? }`. Every third one takes the accent tone. |
label | string | — | The list's accessible name. |
max | number | — | How many avatars to show before the rest collapse into a "+N" bubble. All of them when omitted. |
overflow | (hidden: number) => ReactNode | hidden => `+${hidden}` | Replaces the bubble's visible "+N". Screen readers hear `messages.more(hidden)` either way. |
expandable | boolean | true | Makes the "+N" bubble a button that opens a list of everyone (avatar, name and status) right after the stack. False keeps a static bubble. |
open | boolean | — | Whether the full list is open. Pass it to control the stack; leave it out and it keeps its own state. |
defaultOpen | boolean | false | Whether the full list starts open when uncontrolled. |
onOpenChange | (open: boolean) => void | — | Called with the requested state when the bubble is pressed. |
…rest | HTMLAttributes | — | className, style, the ref and other attributes reach the root <ul>. |
Keyboard
| Tab | reaches the "+N" bubble, the only stop in a stack |
| Enter / Space | opens or closes the list of everyone |
Accessibility
- The stack is a list (
<ul>) named bylabel, with one item per avatar and one for the bubble. - Each avatar reads as Avatar does: the name with the status, from
messages.presence(“Ada K., online”). - The bubble reads
messages.more(“2 more”) whateveroverflowdraws, so a short visible label such as “9+” loses nothing. - When people are hidden, the bubble is a button (
expandable, on by default) witharia-expandedandaria-controls. Enter or Space opens an inline list of everyone right after the stack, each row read once throughmessages.presence; focus stays on the bubble. The list is the stack’s next sibling, so put the stack in a column for it to open underneath. - Presence is colour only. Where it matters, say it in text too, such as a count of who is online.