Avatar
Avatars show a person as a photo, initials or a person glyph, alone or in a group.
import { Avatar, AvatarGroup, AvatarGroupCount } from '@aksornproject/aksara-ui'Content
The Avatar shows the photo once src loads. Until then, or if it fails, it shows the fallback text. Without fallback it draws a person glyph.
fallback renders verbatim, so pass the initials you want to show. children replace the photo and the fallback.
<Avatar size="medium" src={photo} alt="Somchai Prasert" fallback="SP" />
<Avatar size="medium" fallback="NK" />
<Avatar size="medium" />Sizes
Five sizes, from tiny (20px) to large (128px). xsmall (24px) is the default. The initials keep the 16px font-size mode, so they never outgrow the circle when an app scales its base font size.
<Avatar size="tiny" fallback="SP" />
<Avatar size="xsmall" fallback="SP" />
<Avatar size="small" fallback="SP" />
<Avatar size="medium" fallback="SP" />
<Avatar size="large" fallback="SP" />Variants
variant sets the border. default has none, border draws a 2px subtle border and dashed a 2px dashed one.
<Avatar size="medium" fallback="NK" />
<Avatar size="medium" variant="border" fallback="NK" />
<Avatar size="medium" variant="dashed" />Status
status adds a success, neutral or error dot on the edge of the circle. The dot is hidden from assistive technology, so put the status in alt as well.
<Avatar
size="medium"
src={portrait('#9ec5e8', '#f1c27d', '#3d5a80')}
alt="Somchai Prasert, online"
status="success"
/>
<Avatar
size="medium"
src={portrait('#f4b6c2', '#c68642', '#6d597a')}
alt="Nicha Kanchana, away"
status="neutral"
/>
<Avatar
size="medium"
src={portrait('#b5e48c', '#8d5524', '#1d3557')}
alt="Arthit Wong, sync failed"
status="error"
/>Disabled and loading
disabled dims the Avatar and sets aria-disabled. loading shows the skeleton fill, hides the content and sets aria-busy. The Avatar also shows the skeleton while its image loads.
<Avatar size="medium" fallback="SP" disabled />
<Avatar size="medium" fallback="SP" loading />Group
AvatarGroup draws a white ring around each child and places the rings edge to edge. Its size reaches every child that does not set its own.
The group does not count or slice. Render the visible Avatars yourself and an AvatarGroupCount with the overflow.
<AvatarGroup size="small">
{members.map((member) => (
<Avatar key={member.id} src={member.photo} alt={member.name} />
))}
<AvatarGroupCount>+4</AvatarGroupCount>
</AvatarGroup>Interactive
render swaps the root element. Rendered as a button or a link, the Avatar shows a hover overlay and the focus ring. A plain Avatar shows neither.
<Avatar
size="medium"
fallback="SP"
aria-label="Open Somchai Prasert's profile"
render={<button type="button" />}
/>Accessibility
altnames the photo. It falls back tofallback, then to an empty string.- The status dot is
aria-hidden. Put the status inaltor in nearby text. - An interactive Avatar needs an accessible name. With a photo,
altgives it one. With initials, passaria-label. disabledsetsaria-disabled.loadingand a loading image setaria-busy.
API
Avatar
Prop
Type
AvatarGroup
Prop
Type
AvatarGroupCount
Prop
Type