Avatar
ProA picture with an initials or icon fallback, badges, 35 Expressive shapes and groups. Not an M3 component (@windmorph/react-pro).
import { Avatar, AvatarGroup } from '@windmorph/react-pro';Part of Windmorph Pro, paid components on the free core, not on sale yet. See the Pro guide for what it includes and to register interest.
Purpose
An avatar is a small picture that stands for an account, with initials or an icon when there is no photo. It is not an M3 component: it comes from @windmorph/react-pro and fits the avatar slots of M3 components, such as the 24px avatar of an input chip and the 40px leading avatar of a list item.
Its sizes are in px (24 to 96px), so it keeps its M3 slot size at larger text sizes. For a slot they don't fit, size takes any number of px (size={48}), whose corners, initials and rings follow the nearest named size; --wm-avatar-size sets the box from a theme or a class too. With href it is a link and with onPress a button, with the core's state layer (hover, focus and the pressed ripple) painted over the photo too. A link avatar takes target, rel and download, as an <a> does: with target="_blank" its rel always holds noopener noreferrer and its name says it opens in a new tab (labels.newTab).
AvatarGroup shows several as one unit, named once by aria-label (or aria-labelledby); a linked or pressable "+N" is named by labels.overflow. Each child sits in an item of the group's and reads the group's size through context, so an app's own component around an Avatar works. When two or more avatars are links or buttons, the group spaces itself so their 48px touch targets never overlap.
It renders on the server (a client component, since it reads the group's context). The photo sits over the fallback, so it shows as soon as it loads, with or without JS; if it fails, the fallback shows. Pass image to use your framework's image component, such as next/image.
shape is circle by default, or rounded (a shape-scale corner for its size), or a shape outline: one of the 35 M3 Expressive shapes as a constant (shape={cookie12SidedShape} from @windmorph/react/primitives) or your own MaterialShapePath. On a shape, the presence dot and the badge sit on the outline, and a group's ring follows the shape. icon sets the fallback when there is no name.
statusRing draws a ring a small gap away from the avatar, for a status an app shows on the avatar itself: active when there is something to see (something new from the account, a broadcast under way, the person speaking) and inactive, thinner and quieter, when there is nothing new. statusRingLabel, required with it, says what the ring means in the accessible name. The ring is drawn outside the avatar's box, so the avatar keeps its size and nothing moves when a ring appears or goes: leave 4px round it (5px from lg). statusRingSegments cuts it into segments, one for each thing to see, and statusRingInactiveSegments marks the ones already seen, from the top going clockwise.
badgePlacement="bottom" puts the badge on the avatar's bottom edge as a pill, for a short word such as "LIVE": leave 8px below the avatar for it (10px from lg). In an AvatarGroup an avatar with a ring is drawn above its neighbours' photos and takes no more room; give a spaced group whose avatars have rings a wider gap.
Shapes and bundle size: circle and rounded avatars carry no shape data, and each outline costs only its own path, about 0.4 kB gzipped for Cookie12Sided and up to 2.5 kB for SoftBoom, the largest. materialShapePaths holds all 35 (about 11 kB), for a shape picker. Shapes aren't mirrored in right-to-left layouts, as in Compose.
When not to use
For a status count or dot on an icon, use a Badge.
See also
- Badge: A small dot or a short count or label, placed on an anchor with BadgedBox.
- Chips: Assist, suggestion, filter and input chips for compact actions and entries, in a chip set.
- List: Rows with headline, overline, supporting text and leading or trailing content (icons, avatars, images, video thumbnails); items can be links, switches, checkboxes or radio buttons, and put in order by drag or a menu.