Avatar Stack¶
A row of overlapping Avatars, such as who watched an item. Past max, the rest fold into a +N bubble whose tooltip names them.
Decision¶
| When | Use |
|---|---|
| Several people in the space of one, in a row or a card | Avatar Stack |
| One person with a name beside them | User Chip |
Usage¶
import { createAvatarStack } from './configurationpage?name=myplugin_stolon.js';
var stack = createAvatarStack({ users: [{ name: 'Ada', src: adaUrl }, { name: 'Bob' }], max: 4, label: 'Watched by' });
view.querySelector('#watchers').appendChild(stack.element);
Classes: stolon-avatar-stack with a stolon-small, stolon-medium, or stolon-large modifier, and stolon-avatar-more on the bubble. The handle is { element, getValue, setValue, destroy }, where getValue() returns the users and setValue(users) draws new ones.
States and Modifiers¶
- Each user takes the avatar options, such as
src,image,name, andcolor. Astatusis not drawn in a stack. - The stack hides itself when it has no users.
maxis 4 by default. With more users, the stack showsmaxminus one avatars and a bubble, such as "+3", so it never grows pastmaxplaces.moreTextreplaces "+{value}".sizeissmall(default),medium, orlarge.- The stack is one image to a screen reader, named by
labeland every name in it. The names also sit in its title. The bubble's tooltip names the users it stands for, through Tooltip when the page binds it.
Reference¶
Generated from the code by scripts/build-docs.mjs. Edit the code, not this section.
createAvatarStack¶
function createAvatarStack(options?: AvatarStackOptions): AvatarStackHandle
A row of overlapping avatars, such as who watched an item, built from createAvatar. Past max, the rest fold into a +N bubble whose tooltip names them. The stack is one image to a screen reader, named by every name in it.
| Option | Type | What it does |
|---|---|---|
users |
AvatarOptions[] |
[{ src, image, name, color }] as createAvatar takes [optional] |
max |
number |
how many avatars show before the +N bubble (default 4) |
size |
'small' | 'medium' | 'large' |
'small', 'medium', or 'large' (default 'small') |
moreText |
string |
the bubble's text, where {value} is how many more (default '+{value}') |
label |
string |
the start of the accessible name, before the names, such as 'Watched by' [optional] |
| Handle member | Type |
|---|---|
getValue |
(): AvatarOptions[] |
setValue |
(users: AvatarOptions[] | null): void |
destroy |
(): void |
| Class | What it looks like |
|---|---|
stolon-avatar-stack |
A row of overlapping avatars, each ringed in the surface color, ending in a +N bubble when there are more |
stolon-avatar-more |
The +N bubble that stands for the avatars past max, with their names in its tooltip |
Example¶
Example Code¶
<!-- title: Avatar Stack -->
<div id="mount" style="display: grid; gap: 16px;"></div>
<script type="module">
const base = await window.__baseReady;
const G = window.__gallery;
const mount = document.getElementById('mount');
base.bindTooltips(document.body);
const people = [
{ name: 'Ada', src: G.svg(64, 64, '#3498db', 'A') },
{ name: 'Bob', color: 'green' },
{ name: 'Cy', src: G.svg(64, 64, '#9b59b6', 'C') },
{ name: 'Dee', color: 'orange' },
{ name: 'Eve', src: G.svg(64, 64, '#e91e63', 'E') },
{ name: 'Finn', color: 'teal' }
];
mount.appendChild(base.createAvatarStack({ users: people.slice(0, 3), label: 'Watched by' }).element);
mount.appendChild(base.createAvatarStack({ users: people, max: 4, label: 'Watched by' }).element);
mount.appendChild(base.createAvatarStack({ users: people, max: 3, size: 'medium', label: 'Synced to' }).element);
</script>