Avatar

A visual representation of a user or entity with image and fallback support

Installation#

npmpnpmyarnbun
npx sugarcoat add avatar

Examples#

Default#

Default

Sizes#

Available in five sizes to fit different UI contexts.

Sizes

Colors#

Avatars can use different color palettes for the fallback background.

Colors

Shapes#

Avatars support different shapes.

Shapes

Fallback#

The fallback is shown when the image fails to load or isn't provided.

Fallback

Shadow#

Add elevation with the shadow prop.

Shadow

Inactive State#

Show inactive or offline users with reduced opacity.

Inactive

Avatar Group#

Group multiple avatars together with optional overflow indicator.

Avatar Group

Avatar Group with Max#

Limit the number of visible avatars with overflow count.

Group with Max

User Card Example#

User Card

Anatomy#

<Avatar>
  <Avatar.Image src="..." alt="..." />
  <Avatar.Fallback>JD</Avatar.Fallback>
</Avatar>
 
// Group
<Avatar.Group max={3}>
  <Avatar>...</Avatar>
  <Avatar>...</Avatar>
</Avatar.Group>

Usage#

Import
import { Avatar } from "@sugarcoat/ui-nxt";
Usage
<Avatar size="md" color="primary" shape="circle">
<Avatar.Image src="/path/to/image.jpg" alt="User Name" />
<Avatar.Fallback>UN</Avatar.Fallback>
</Avatar>

Props#

Avatar (Root)#

PropTypeDefaultDescription
size"xs" | "sm" | "md" | "lg" | "xl""md"Size of the avatar
color"default" | "neutral" | "primary" | "accent""default"Color palette for the fallback background
shape"square" | "rounded" | "circle""circle"Shape of the avatar
shadowbooleantrueWhether to show box shadow
inactivebooleanfalseShow avatar in inactive/offline state
cssSystemStyleObject-Additional CSS styles using Panda CSS syntax

Avatar.Image#

PropTypeDefaultDescription
srcrequiredstring-URL of the avatar image
altrequiredstring-Alternative text for the image

Avatar.Fallback#

PropTypeDefaultDescription
childrenReactNode-Content to display when image is unavailable (usually initials)

Avatar.Group#

PropTypeDefaultDescription
maxnumber-Maximum number of avatars to display before showing overflow count
size"xs" | "sm" | "md" | "lg" | "xl"-Size for all avatars in the group
color"default" | "neutral" | "primary" | "accent"-Color for all avatars in the group
shape"square" | "rounded" | "circle"-Shape for all avatars in the group

Accessibility#

  • Built on Base UI Avatar for robust accessibility
  • Always provide meaningful alt text for Avatar.Image
  • Fallback content is announced by screen readers when image fails
  • Use aria-label on Avatar.Group to describe the group context
Customize Theme
Build your own sugarcoat/ui theme
PresetLime / Violet / Slate
Brand ColorLime
Accent ColorViolet
Gray ScaleSlate
Border RadiusLg