Avatar
Show a user as initials, an icon or an image, with an optional presence dot.
Avatar is a client component ("use client") that renders a circular Box containing initials, an icon or a next/image image. Use it to represent people or accounts in lists, headers and comments. It depends on Next.js (next/image) and the Icon block for string icon names.
Import#
import { Avatar } from "@reactberry/system/blocks";
Usage#
import { Avatar } from "@reactberry/system/blocks";
import { Box, Text } from "@reactberry/system/elements";
export default function MemberRow() {
return (
<Box display="flex" alignItems="center" gap="s">
<Avatar
type="image"
name="Ada Lovelace"
src="https://example.com/avatars/ada.jpg"
size="2rem"
withPresence
/>
<Text fontWeight="600">Ada Lovelace</Text>
</Box>
);
}
Examples#
Fixed colour#
By default the colour is derived from name. Set autocolor={false} and pass color to use one colour for everyone.
Image fallback#
When type="image" has no src, or the image fails to load, fallbackType decides what renders instead: initials ("text") or the silhouette ("icon", the default).
Presence status#
Set withPresence to show a dot. status sets its colour and border. The dot has no text, so show the status next to the avatar.
API#
Avatar#
| Prop | Type | Default | Description |
|---|---|---|---|
type | "text" | "icon" | "image" | "text" | What to render inside the circle. |
name | string | "Aa" | Source for the initials and the auto colour; also used as the image |
autocolor | boolean | true | Derives the colour from |
color | string | — | Colour used when |
size | string | "2.5rem" | Width and height of the circle. |
fontSize | string | "75%" | Initials font size. |
src | string | — | Image URL for |
alt | string | — | Image alt text. Falls back to |
fallbackType | "text" | "icon" | "icon" | Rendered when |
icon | string | ComponentType | ReactElement | — | Icon for |
iconProps | object | {} | Forwarded to the icon when |
withPresence | boolean | false | Shows the status dot. |
status | { label: string; color: string; border: string; size?: string } | null | { label: "online", color… | Dot colour ( |
statusProps | object | {} | Spread onto the status dot |
All other props are spread onto the inner circle Box, after the defaults (display="inline-flex", shape="circle", overflow="hidden", flex="none"). The prop type includes [key: string]: any, so unknown props are not type-checked.
Accessibility#
- The avatar renders
divelements with no role or label. Initials are plain text and are read by screen readers. - The silhouette and icons have no accessible name.
- Images use
alt, thenname, then"avatar"as alt text. status.labelis declared but not rendered or used for accessibility. Add an accessible label yourself if presence matters.
Notes#
- Initials are the first letters of the first two space-separated words, or the first two characters of a single word, upper-cased.
- The circle background uses
currentColor, socolor(or the auto colour) sets the fill; initials and icons are white. - Failed image URLs are remembered for the session by URL without its query string, so presigned URLs that only change their signature are not retried.
- Remote
srchosts must be allowed in your Next.jsimagesconfiguration. - The status dot size is
calc(status.size or size / 2.5)whensizeis passed, otherwise"0.625rem"regardless ofstatus.size. nameis also forwarded to the innerdivas anameattribute.