Avatar

A small picture of a person, with their initials or an icon when there is no image.

ME

Usage

Code
import { Avatar, AvatarGroup } from '@leverui/components';
Code
<AvatarGroup>
  <Avatar.Root>
    <Avatar.Fallback />
    <Avatar.Image />
  </Avatar.Root>
</AvatarGroup>

For one component with props, see the snippet below.

Examples

Sizes

Use the size prop to change the size of the avatar

ME
ME
ME
ME
ME
ME

Variants

Use the variant prop to change the variant of the avatar

ME
ME
ME

Shape

Use the shape prop to change the shape of the avatar, from rounded to square

IC
ME
VK

Colors

Use the colorPalette prop to change the color of the avatar

gray

ME
ME

red

ME
ME

green

ME
ME

blue

ME
ME

teal

ME
ME

pink

ME
ME

purple

ME
ME

cyan

ME
ME

orange

ME
ME

yellow

ME
ME

Fallback

Render Avatar.Icon as the fallback when the name is not provided or when the image fails to load.

CV
WA

Random Color

Combine the colorPalette prop with some custom logic to dynamically change the color of the avatar

NQ
IC
TP

Ring

Use outline styles in authored CSS to add a ring around the avatar

R
R
R

Group

Use the AvatarGroup component to group multiple avatars together

TP
IC
JR
+3

Stacking

When using the AvatarGroup component, you can use the stacking prop to change the stacking order of the avatars

TP
IC
JR
+3
TP
IC
JR
+3
TP
IC
JR
+3

Persona

Here's an example of how to use the Avatar component to display a user persona.

OB

Oskar Brandt

[email protected]

ME

Mara Ellison

[email protected]

Badge

Show a badge on the right corner of the avatar by composing the Float and Circle components

RS

Overflow

Here's an example of how to handle an overflow of avatars by composing the Menu and Avatar components.

WA
MS
TH

Store

An alternative way to access the avatar state and methods is to use the RootProvider component and the useAvatar store hook.

ME
not loaded

Closed Component

Code
import { omit } from 'solid-js';
import type { JSX } from '@solidjs/web';
import { Avatar as AvatarParts, type AvatarRootProps } from '@leverui/components';

export type ClosedAvatarProps = AvatarRootProps & {
  name?: string | undefined;
  src?: string | undefined;
  srcSet?: string | undefined;
  loading?: 'eager' | 'lazy' | undefined;
  icon?: JSX.Element;
  fallback?: JSX.Element;
};

export function ClosedAvatar(props: ClosedAvatarProps) {
  const root = omit(props, 'name', 'src', 'srcSet', 'loading', 'icon', 'fallback', 'children');

  return (
    <AvatarParts.Root {...root}>
      <AvatarParts.Fallback name={props.name}>{props.fallback ?? props.icon}</AvatarParts.Fallback>
      <AvatarParts.Image src={props.src} srcset={props.srcSet} loading={props.loading} />
      {props.children}
    </AvatarParts.Root>
  );
}

Group them with AvatarGroup from @leverui/components.

Props

Root

PropDefaultTypeDescription
colorPalettegraystringColor palette, built-in or your own.
sizemd'full' | '2xs' | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl'Avatar size. Responsive.
variantsubtle'solid' | 'subtle' | 'outline'Avatar style. Responsive.
shapefull'square' | 'rounded' | 'full'Corner shape. Responsive.
asdivNative HTML tagHTML tag to render.
asChild—Solid render functionRender your own element with this part's props.
unstyledfalsebooleanTurn off the Lever UI styles.
ids—Element ID mapYour own IDs for the root, image, and fallback.
onStatusChange—(details) => voidCalled when the image loading status changes.
borderless—booleanRemove the border the avatar gets in a group.

Fallback

PropDefaultTypeDescription
name—stringName the initials come from. Without it, shows a generic icon.
asdivNative HTML tagHTML tag to render.
asChild—Solid render functionRender your own element with this part's props.

Image

PropDefaultTypeDescription
asimgNative HTML tagHTML tag to render.
asChild—Solid render functionRender your own element with this part's props.

Make the image alt and the fallback name match the person or thing shown. Leave alt empty only when text next to the avatar already names it.

AvatarGroup overlaps its avatars. Set --leverui-avatar-group-overlap on the group to change the overlap.

Customize with CSS

Give the root or a part a class. Load your CSS after the Lever UI stylesheet.

Classes: .leverui-avatar__root, .leverui-avatar__image, .leverui-avatar__fallback, .leverui-avatar__icon, .leverui-avatar-group.

Code
.profile-avatar {
  --leverui-colors-color-palette-muted: #dbeafe;
}

.profile-avatar .leverui-avatar__fallback {
  letter-spacing: 0.04em;
}

Explorer

Click a part name to highlight it in the preview.

Component Anatomy

Hover to highlight, click to select parts