structyl

Avatar

stable

An image element with a fallback for representing the user.

Basic usage

JDAB

Examples

Avatar group

Stack avatars with negative margin to form a compact group.

ALGHMHAT

Team stack with fallback

Show loaded images, initials fallbacks and delayed fallback states together.

Features

  • Automatic and manual control over when the image renders.
  • Fallback accepts an arbitrary node.
  • Delays fallback to avoid flicker.

Installation

bash
pnpm dlx structyl add avatar

API Reference

Avatar.Root

Contains the image and fallback.

PropTypeDefault
asChildboolean

Merge props onto the immediate child instead of rendering a default element.

false
classNamestring

Additional Tailwind classes, merged with the component defaults.

Avatar.Image

The avatar image. Renders only once loaded successfully.

PropTypeDefault
srcstring

Image source URL.

onLoadingStatusChange(status: 'idle' | 'loading' | 'loaded' | 'error') => void

Called when the loading status changes.

classNamestring

Additional Tailwind classes, merged with the component defaults.

Avatar.Fallback

Renders while the image is loading or has failed.

PropTypeDefault
delayMsnumber

Delay in ms before showing, to avoid flicker on fast loads.

classNamestring

Additional Tailwind classes, merged with the component defaults.

Avatar | structyl