Fragiola

API: components

Avatar

An image that represents a person, shown only once it has loaded, with a fallback while it loads or when it fails, in each framework.

An image that represents a person, with a fallback (initials, an icon) while the image loads or when it fails. The image is rendered only once it has loaded, so a broken image never shows, and the layout does not shift between the fallback and the image (you size the Root). It needs no ARIA of its own: the Image is a plain img named by its alt (the APG has no pattern). A group of avatars and a status badge are markup and CSS, not primitives.

Team avatars
Gallery

Behaviour

  • The loading status is the Root's: idle (no Image, or not loading yet), loading, loaded, or error (the image failed, or the Image has no src). The Image loads its src outside the document (the toolkit's watchImageStatus) and renders its img once it has loaded; a new src loads again. When the Image unmounts, the status returns to idle.
  • A cached image is loaded at once, never loading, within the mount (before the browser paints), so its fallback is never painted.
  • Fallback: rendered while the image is not loaded. With delay, only once that many milliseconds have passed since it mounted, so a fast image never flashes it.
  • On a server the status is idle: the Image renders nothing and the Fallback is rendered (none with a delay, which has not passed). The load starts once mounted in the browser.
  • No status attribute: the parts carry none (Base UI). Read the status through onLoadingStatusChange, or the Root's state (render, the Vue slot, Angular's state()).

Anatomy

partelementdata-primitives-partrole
Rootspanavatar-rootholds the image's loading status
Imageimgavatar-imagerendered only once its image has loaded
Fallbackspanavatar-fallbackrendered while the image is not loaded (after its delay)

Usage

import { Avatar } from "@fragiola/primitives-react/avatar";

<Avatar.Root>
    <Avatar.Image src="/ada.jpg" alt="Ada Lovelace" />
    <Avatar.Fallback delay={300}>AL</Avatar.Fallback>
</Avatar.Root>;

Props

Every part also takes what the primitive contract gives: render (Vue: as and the render slot), a class and a style, a ref, and any attribute, which it forwards: the Image forwards alt and every other img attribute.

Root

No props of its own.

Image

proptypedefaultdescription
srcstringthe image; none is an error (Angular: *avatarImage="src")
srcSetstringthe img's srcset, also used for the load
sizesstringthe img's sizes, also used for the load
crossOrigin"anonymous" | "use-credentials" | ""the img's crossorigin, also used for the load
referrerPolicystringthe img's referrerpolicy, also used for the load
onLoadingStatusChange(status: ImageLoadingStatus) => voideach new status but idle (Vue: @loading-status-change, Angular: (loadingStatusChange))

Fallback

proptypedefaultdescription
delaynumberrendered only once this many milliseconds have passed since it mounted (Angular: *avatarFallback="300")

State and part attributes

partattributes
Rootnone of its own
Imagethe img attributes you give, and the load's (src, srcset, sizes, crossorigin, referrerpolicy)
Fallbacknone of its own

The Fallback's content is yours: text, an aria-label, or aria-hidden for a decorative one.

Keyboard

None: an avatar is not focusable.

Exports

entryexports
@fragiola/primitives-react/avatarAvatar, AvatarFallbackProps, AvatarImageProps, AvatarRootProps, AvatarState, ImageLoadingStatus, RenderProp
@fragiola/primitives-vue/avatarAvatar, AvatarFallbackProps, AvatarImageEmits, AvatarImageProps, AvatarState, ImageLoadingStatus, RenderSlotProps
@fragiola/primitives-angular/avatarAvatarFallback, AvatarImage, AvatarImageCrossOrigin, AvatarRoot, AvatarState, ImageLoadingStatus