Skip to content

Avatar

import { Avatar, AvatarGroup } from '@yarcl/react';
+2
<Avatar name="Ada Lovelace" src="/ada.jpg" />
<Avatar name="Grace Hopper" color="success" />

name supplies the accessible name and turns into initials when no image is available. Use fallback for custom fallback content, and alt="" for a decorative avatar. If an image fails to load, the fallback appears automatically.

AvatarGroup overlaps direct Avatar children. Its token props become defaults for any child that does not set its own value. Set max to limit the visible avatars and total when more people exist than the rendered children.

<AvatarGroup max={3} total={5} aria-label="Project members">
<Avatar name="Ada Lovelace" />
<Avatar name="Grace Hopper" />
<Avatar name="Alan Turing" />
</AvatarGroup>

size sets the diameter from sizes; radius, color and variant style the fallback from their matching config groups. Configure defaults under components.Avatar or components.AvatarGroup.

An avatar with a name or alt renders as an image with that accessible name. Avatar is presentational and has no keyboard interaction. Use an accessible Button or link around it when it triggers an action, and label each group when its membership needs context.

PropTypeDefaultDescription
altstringAlternative text for the avatar. Pass an empty string for a decorative avatar.
colorColorconfigconfig.defaults.colorFallback color from the colors config.
fallbackReactNodeContent shown instead of initials when no image is available.
namestringPerson's name. Used for the fallback initials and accessible name when alt is omitted.
onImageError() => voidCalled after the image fails to load.
radius'size' | Radiusconfig'rounded'Corner radius from the radii config.
size'lg' | 'xs' | 'sm' | 'md' | 'xl'config.defaults.sizeDiameter from the sizes config.
srcstringImage URL. When it cannot load, the fallback is shown.
variantVariantconfigconfig.defaults.softVariantFallback style recipe from this component's variant map or shared variants.
PropTypeDefaultDescription
childrenReactNodeDirect Avatar children to arrange in an overlapping row.
colorColorconfigconfig.defaults.colorFallback color from the colors config.
maxnumberMaximum number of avatars to show before an overflow count.
overflowLabel(count: number) => stringAccessible label for the overflow count. Receives the number of hidden avatars.
radius'size' | Radiusconfigconfig.defaults.radiusAvatar corner radius from the radii config.
size'lg' | 'xs' | 'sm' | 'md' | 'xl'config.defaults.sizeAvatar diameter from the sizes config.
totalnumberTotal number of people when not every avatar is rendered. Used with max.
variantVariantconfigconfig.defaults.softVariantFallback style recipe from this component's variant map or shared variants.