Synertech Web/ui v0.57.5 Site Storybook

Documentation / Display & media

Avatar

Server-compatible@synertech/uiOpen in Storybook

A user’s thumbnail: an image when there is one, otherwise a fallback text (initials). Five sizes from xs to xl, three shapes (circle, rounded, square) and an optional ring for stacking them.

Without src, the avatar shows fallback, or failing that the first letter of alt in upper case. A hook-free component: it renders on the server. It accepts every native <div> attribute.

Examples

Basic usage

An image with its alternative text, and initials when the image is missing.

Open in a tab
import { Avatar } from "@synertech/ui";

export function Basic() {
  return (
    <div className="flex items-center gap-3">
      <Avatar src="https://i.pravatar.cc/150?img=32" alt="Camille Durand" />
      <Avatar fallback="HM" alt="Hugo Martin" />
      <Avatar alt="Léa Bernard" />
    </div>
  );
}

Sizes

size sets the diameter and the size of the fallback text.

Open in a tab
import { Avatar } from "@synertech/ui";

export function Sizes() {
  return (
    <div className="flex items-center gap-3">
      <Avatar size="xs" fallback="XS" />
      <Avatar size="sm" fallback="SM" />
      <Avatar size="md" fallback="MD" />
      <Avatar size="lg" fallback="LG" />
      <Avatar size="xl" fallback="XL" />
    </div>
  );
}

Shapes

variant picks between the circle (default), the rounded square and the square.

Open in a tab
import { Avatar } from "@synertech/ui";

export function Variants() {
  return (
    <div className="flex items-center gap-3">
      <Avatar variant="circle" size="lg" src="https://i.pravatar.cc/150?img=12" alt="Hugo Martin" />
      <Avatar
        variant="rounded"
        size="lg"
        src="https://i.pravatar.cc/150?img=12"
        alt="Hugo Martin"
      />
      <Avatar variant="square" size="lg" src="https://i.pravatar.cc/150?img=12" alt="Hugo Martin" />
    </div>
  );
}

Avatar group

border adds a ring in the background colour: the thumbnails overlap cleanly.

Open in a tab
import { Avatar } from "@synertech/ui";

const team = [
  { name: "Camille Durand", initials: "CD" },
  { name: "Hugo Martin", initials: "HM" },
  { name: "Léa Bernard", initials: "LB" },
  { name: "Nathan Petit", initials: "NP" },
];

export function Group() {
  return (
    <div className="flex items-center">
      <div className="flex -space-x-3">
        {team.map((member) => (
          <Avatar
            key={member.name}
            border
            fallback={member.initials}
            alt={member.name}
            title={member.name}
          />
        ))}
      </div>
      <span className="ml-3 text-sm text-gray-600 dark:text-gray-400">+ 8 autres membres</span>
    </div>
  );
}

In a profile card

Classes passed in className customise the fallback colours.

Open in a tab
import { Avatar } from "@synertech/ui";

export function ProfileCard() {
  return (
    <div className="flex items-center gap-4 rounded-lg border border-gray-200 p-4 dark:border-gray-700">
      <Avatar size="xl" fallback="CD" alt="Camille Durand" className="bg-blue-100 text-blue-700" />
      <div>
        <p className="font-semibold text-gray-900 dark:text-gray-100">Camille Durand</p>
        <p className="text-sm text-gray-500 dark:text-gray-400">Responsable produit</p>
      </div>
    </div>
  );
}

API reference

Components

Avatar

ComponentServer-compatible
import { Avatar } from "@synertech/ui";

Props — AvatarProps

PropTypeDefaultDescription
alt string serverUILabels.avatarAlt

Alternative text of the image. English by default (avatarAlt): Avatar renders on the server, so UILabelsProvider does not reach it — pass the name of the person, or frenchUILabels.avatarAlt.

border boolean false
fallback string —

Text drawn when there is no picture, and under the picture while it loads or when it fails to: the first letter of alt without it.

size "xs" | "sm" | "md" | "lg" | "xl" "md"
src string —
variant "circle" | "square" | "rounded" "circle"

+ 279 inherited native attributes from HTMLAttributes, AriaAttributes, DOMAttributes (className, id, aria-*, event handlers…).