Back to Prisma

Avatar

apps/eclipse/content/design-system/components/avatar.mdx

latest5.7 KB
Original Source

import { Avatar } from "@prisma/eclipse";

Usage

Basic Avatar with Initials

tsx
import { Avatar } from "@prisma/eclipse";

export function UserProfile() {
  return <Avatar format="initials">JD</Avatar>;
}

Live Example:

<div className="flex items-center gap-4 my-4 not-prose"> <Avatar format="initials" size="lg">SM</Avatar> <Avatar format="initials" size="xl">MD</Avatar> <Avatar format="initials" size="2xl">LG</Avatar> <Avatar format="initials" size="3xl">XL</Avatar> </div>

Avatar with Image

tsx
import { Avatar } from "@prisma/eclipse";

export function UserProfileImage() {
  return (
    <Avatar 
      format="image" 
      src="/avatar.jpg" 
      alt="John Doe" 
      size="lg" 
    />
  );
}

Live Example:

<div className="flex items-center gap-4 my-4 not-prose"> <Avatar format="image" src="/img/logo.svg" alt="Prisma" size="lg" /> <Avatar format="image" src="/img/logo.svg" alt="Prisma" size="xl" /> <Avatar format="image" src="/img/logo.svg" alt="Prisma" size="2xl" /> <Avatar format="image" src="/img/logo.svg" alt="Prisma" size="3xl" /> </div>

Avatar with Icon

tsx
import { Avatar } from "@prisma/eclipse";

export function IconAvatar() {
  return (
    <Avatar format="icon" size="2xl">
      <UserIcon />
    </Avatar>
  );
}

Live Example:

<div className="flex items-center gap-4 my-4 not-prose"> <Avatar format="icon" size="lg"> <svg xmlns="http://www.w3.org/2000/svg" fill="white" viewBox="0.34 -0.059977834648891726 33.11668247084116 39.96397783464889" width="20" height="20"><path d="M32.908 30.475L19.151 1.26a2.208 2.208 0 0 0-1.88-1.257 2.183 2.183 0 0 0-2.01 1.042L.34 25.212a2.26 2.26 0 0 0 .025 2.426L7.66 38.935a2.346 2.346 0 0 0 2.635.969l21.17-6.262a2.32 2.32 0 0 0 1.457-1.258 2.27 2.27 0 0 0-.013-1.91zm-3.08 1.253L11.864 37.04c-.548.163-1.074-.312-.96-.865l6.418-30.731c.12-.575.914-.666 1.165-.134l11.881 25.23a.858.858 0 0 1-.541 1.188z" clipRule="evenodd" fillRule="evenodd"/></svg> </Avatar> <Avatar format="icon" size="xl"> <svg xmlns="http://www.w3.org/2000/svg" fill="white" viewBox="0.34 -0.059977834648891726 33.11668247084116 39.96397783464889" width="24" height="24"><path d="M32.908 30.475L19.151 1.26a2.208 2.208 0 0 0-1.88-1.257 2.183 2.183 0 0 0-2.01 1.042L.34 25.212a2.26 2.26 0 0 0 .025 2.426L7.66 38.935a2.346 2.346 0 0 0 2.635.969l21.17-6.262a2.32 2.32 0 0 0 1.457-1.258 2.27 2.27 0 0 0-.013-1.91zm-3.08 1.253L11.864 37.04c-.548.163-1.074-.312-.96-.865l6.418-30.731c.12-.575.914-.666 1.165-.134l11.881 25.23a.858.858 0 0 1-.541 1.188z" clipRule="evenodd" fillRule="evenodd"/></svg> </Avatar> <Avatar format="icon" size="2xl"> <svg xmlns="http://www.w3.org/2000/svg" fill="white" viewBox="0.34 -0.059977834648891726 33.11668247084116 39.96397783464889" width="28" height="28"><path d="M32.908 30.475L19.151 1.26a2.208 2.208 0 0 0-1.88-1.257 2.183 2.183 0 0 0-2.01 1.042L.34 25.212a2.26 2.26 0 0 0 .025 2.426L7.66 38.935a2.346 2.346 0 0 0 2.635.969l21.17-6.262a2.32 2.32 0 0 0 1.457-1.258 2.27 2.27 0 0 0-.013-1.91zm-3.08 1.253L11.864 37.04c-.548.163-1.074-.312-.96-.865l6.418-30.731c.12-.575.914-.666 1.165-.134l11.881 25.23a.858.858 0 0 1-.541 1.188z" clipRule="evenodd" fillRule="evenodd"/></svg> </Avatar> </div>

Disabled State

tsx
import { Avatar } from "@prisma/eclipse";

export function DisabledAvatar() {
  return (
    <Avatar 
      format="image" 
      src="/avatar.jpg" 
      alt="Disabled user" 
      size="lg" 
      disabled 
    />
  );
}

Avatar Props

  • format - The type of avatar content: "image", "icon", or "initials" (required)
  • size - Avatar size: "lg" (28x28, default), "xl" (32x32), "2xl" (36x36), "3xl" (40x40)
  • disabled - Whether the avatar is disabled: true or false (default: false)
  • src - Image source URL (required when format is "image")
  • alt - Alt text for image (optional, recommended for accessibility)
  • children - Content for icon or initials format
  • className - Additional CSS classes (optional)

Formats

Image Avatar

Display a user photo or image:

tsx
<Avatar 
  format="image" 
  src="/user-photo.jpg" 
  alt="User Name" 
  size="xl" 
/>

Initials Avatar

Display user initials (typically 1-2 characters):

tsx
<Avatar format="initials" size="xl">
  JD
</Avatar>

Icon Avatar

Display an icon or SVG:

tsx
<Avatar format="icon" size="2xl">
  <UserIcon />
</Avatar>

Sizes

The Avatar component supports four sizes:

  • lg - 28x28 pixels (default)
  • xl - 32x32 pixels
  • 2xl - 36x36 pixels
  • 3xl - 40x40 pixels
tsx
<div className="flex items-center gap-4">
  <Avatar format="initials" size="lg">SM</Avatar>
  <Avatar format="initials" size="xl">MD</Avatar>
  <Avatar format="initials" size="2xl">LG</Avatar>
  <Avatar format="initials" size="3xl">XL</Avatar>
</div>

Features

  • ✅ Three display formats: image, icon, and initials
  • ✅ Four size variants
  • ✅ Disabled state support
  • ✅ Built with Eclipse design tokens
  • ✅ Accessible with proper alt text support
  • ✅ Circular shape with consistent styling

Best Practices

  • Use the image format when you have a user photo available
  • Use the initials format for personalization without photos
  • Use the icon format for generic user representations or system avatars
  • Always provide alt text when using the image format for accessibility
  • Keep initials to 1-2 characters for best visual appearance
  • Choose appropriate sizes based on UI context (smaller for lists, larger for profiles)
  • Use the disabled state to indicate inactive or unavailable users

Accessibility

  • When using format="image", always provide an alt attribute
  • The component uses semantic HTML for proper screen reader support
  • Disabled avatars have appropriate visual indicators