Avatar
Data displayA person's picture or initials: <Avatar.Root> (size sm, default, lg) holds an Avatar.Image (src, alt) and an Avatar.Fallback shown while it loads or when it fails. Avatar.Badge marks a status; Avatar.Group overlaps several, with an Avatar.GroupCount for the rest.
import { Avatar } from '@limerdev/zest'; alt. Decorative pictures: use a plain <img>.Examples
Basic
Initials show until the picture loads, or when it can't.
<script lang="ts">
import { Avatar } from '@limerdev/zest';
</script>
<Avatar.Root size="sm">
<Avatar.Fallback>AB</Avatar.Fallback>
</Avatar.Root>
<Avatar.Root>
<Avatar.Image src="/missing.png" alt="Anna Berg" />
<Avatar.Fallback>AB</Avatar.Fallback>
</Avatar.Root>
<Avatar.Root size="lg">
<Avatar.Fallback>EL</Avatar.Fallback>
<Avatar.Badge />
</Avatar.Root> Group
A group overlaps avatars; GroupCount stands in for the rest.
<script lang="ts">
import { Avatar } from '@limerdev/zest';
const people: string[] = ['AB', 'EL', 'MK', 'SJ'];
</script>
<Avatar.Group>
{#each people as initials (initials)}
<Avatar.Root>
<Avatar.Fallback>{initials}</Avatar.Fallback>
</Avatar.Root>
{/each}
<Avatar.GroupCount>+8</Avatar.GroupCount>
</Avatar.Group> Props
Every part also takes class (merged over its defaults), ref (bindable: the element), children, and child (a snippet that
renders your own element, with props to spread on it).
Avatar.Root
| Prop | Type | Default | Description |
|---|---|---|---|
| delayMs | number | 0 | The delay in milliseconds to wait before showing the avatar once the image has loaded. This can be used to prevent sudden flickering of the image if it loads quickly. |
| loadingStatus bindable | "error" | "loading" | "loaded" | 'loading' | The loading status of the image. If you are confident that the image exists and will load successfully, you can set this to "loaded" to skip the loading process (which shows the fallback) and immediately show the image. |
| onLoadingStatusChange | OnChangeFn<AvatarImageLoadingStatus> | – | A callback invoked when the loading status of the image changes. |
| size | "default" | "sm" | "lg" | 'default' | The avatar's size: sm (24px), default (32px) or lg (40px). |
Avatar.Image
No props of its own beyond the common ones.
Avatar.Fallback
No props of its own beyond the common ones.
Avatar.Badge
No props of its own beyond the common ones.
Avatar.Group
No props of its own beyond the common ones.
Avatar.GroupCount
No props of its own beyond the common ones.