# Avatar

A person's photo, or their initials on a gradient disc. Staff take the navy info gradient and contacts a lighter slate, so the firm's people and its clients never look alike. Built on ui-sdk's Avatar: the image shows once it loads and the fallback covers a missing or broken photo.

- Beta: ready to use; its API can still change in a minor release.
- Category: Status & indicators

```tsx
import { Avatar, AvatarGroup } from "@leap-crm/design-system";
```

## Best practices

- Do: Set `person` to `staff` for the firm's lawyers and `contact` for clients and other parties, so the two never look alike in a list of matter people.
- Do: Pass `name` on every avatar that stands for someone. It is the photo's alt text and the only name a screen reader hears.
- Do: Set `mask` on a client's avatar, so their initials stay out of session replay.
- Do: Use `AvatarGroup` for the staff on a matter or opportunity. Past `max` the rest collapse into a +N disc, and hover or focus lists everyone by name.
- Don't: Show an empty owner slot with a staff or contact avatar. Use `person="unassigned"`, which takes no colour, so an empty slot never reads as a person.
- Don't: Lower the opacity of a whole row to show an inactive person. Fade the avatar and set the name to the muted text colour, so the text stays readable.

## Related

- [Record Chip](./record-chip.md)
- [Icon Tile](./icon-tile.md)
- [Logo](./logo.md)

## Examples

What the examples import:

```tsx
import { Bot, Building2, User } from "lucide-react";
import { Fragment } from "react";
import { Avatar, AvatarGroup } from "@leap-crm/design-system";
```

Scaffolding the examples call. It lives in the docs page, not in the library:

```tsx
const sizes = ["xxs", "xs", "sm", "md", "lg", "xl", "2xl"] as const;

const photo = `data:image/svg+xml,${encodeURIComponent(
  '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><defs><linearGradient id="g" x2="1" y2="1"><stop offset="0" stop-color="#5b7099"/><stop offset="1" stop-color="#3e5480"/></linearGradient></defs><rect width="64" height="64" fill="url(#g)"/><circle cx="32" cy="25" r="9" fill="#ccdfee"/><path d="M17 49c1.5-8 7.5-12.5 15-12.5S45.5 41 47 49a3.5 3.5 0 0 1-3.5 4h-23A3.5 3.5 0 0 1 17 49z" fill="#ccdfee"/></svg>',
)}`;

const team = [
  { id: "1", name: "Ada Hartley", initials: "AH", role: "Responsible" },
  { id: "2", name: "Ben Okafor", initials: "BO", role: "Acting" },
  {
    id: "3",
    name: "Chloe Ng",
    initials: "CN",
    image: photo,
    role: "Assisting",
  },
  { id: "4", name: "Dev Patel", initials: "DP" },
  { id: "5", name: "Eve Moreau", initials: "EM" },
  { id: "6", name: "Finn Walsh", initials: "FW" },
];

function SizeGrid({ person }: { person: "staff" | "contact" }) {
  return (
    <div className="grid grid-cols-[auto_repeat(7,auto)] items-center justify-start gap-x-5 gap-y-4">
      <span />
      {sizes.map(size => (
        <span key={size} className="text-small text-neutral-text-muted">
          {size}
        </span>
      ))}
      {(["Initials", "Icon", "Image"] as const).map(type => (
        <Fragment key={type}>
          <span className="text-small text-neutral-text-muted">{type}</span>
          {sizes.map(size => (
            <Avatar
              key={`${type}-${size}`}
              size={size}
              person={person}
              name="Jane Citizen"
              initials="JC"
              image={type === "Image" ? photo : undefined}
              fallback={type === "Icon" ? <User /> : undefined}
            />
          ))}
        </Fragment>
      ))}
    </div>
  );
}
```

### Staff

The firm's people: the info gradient, light to deep, with navy initials. Icons fill half the disc; at 2xl the line stays 2 px.

```tsx
<SizeGrid person="staff" />
```

### Contact

Clients and other parties: a lighter slate gradient.

```tsx
<SizeGrid person="contact" />
```

### Fallback icons

fallback replaces the initials: a person with no name yet, an organisation, an agent.

```tsx
<div className="flex items-center gap-3">
  <Avatar person="staff" fallback={<User />} name="Unassigned" />
  <Avatar
    person="contact"
    fallback={<Building2 />}
    name="Citizen Holdings"
  />
  <Avatar person="staff" fallback={<Bot />} name="Firm Pilot" />
</div>
```

### Group

Faces overlap 4 px, first on top, each ringed in the surface colour, with +N for the rest. Hover or Tab to it to list everyone, after the deliberate delay.

```tsx
<div className="flex flex-col items-start gap-4">
  {(["xxs", "xs", "sm", "md"] as const).map(size => (
    <AvatarGroup
      key={size}
      items={team}
      size={size}
      tooltipTitle="Matter team"
    />
  ))}
  <AvatarGroup
    items={team.slice(0, 4)}
    person="contact"
    size="md"
    tooltipSections={[
      { title: "Clients", items: team.slice(0, 2) },
      { title: "Other side", items: team.slice(2, 4) },
    ]}
  />
</div>
```

### On a tooltip

variant="tooltip" inverts the fallback for the dark tooltip surface.

```tsx
<div className="bg-signal-tooltip flex items-center gap-2 rounded-lg p-3">
  <Avatar
    size="sm"
    variant="tooltip"
    initials="AH"
    name="Ada Hartley"
  />
  <span className="text-small text-on-tooltip">Ada Hartley</span>
</div>
```

## Props

### Avatar

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `image` | `string \| null` |  | Photo URL. The initials or fallback show until it loads, and if it fails. |
| `initials` | `string \| null` |  | Up to two letters, shown when there's no image or it fails. From the name when left out. |
| `name` | `string` |  | Who it is. The image's alt text, and the avatar's name for screen readers. |
| `size` | `"xxs" \| "xs" \| "sm" \| "md" \| "lg" \| "xl" \| "2xl"` | `"xl"` | xxs 16 to 2xl 64: the disc and its initials together. |
| `person` | `"staff" \| "contact" \| "unassigned"` | `"contact"` | Staff (the firm's people), a contact (clients and other parties), or unassigned: a colourless face for no one, with a person icon as its fallback. |
| `variant` | `"default" \| "tooltip"` | `"default"` | Tooltip inverts the fallback for the dark tooltip surface. |
| `weight` | `"book" \| "semibold"` | `"book"` | Initials weight. Book (450) by default; semibold for small dense labels. |
| `fallback` | `ReactNode` |  | Replaces the initials, like an icon for an unassigned row, an organisation or an agent. |
| `mask` | `boolean` | `false` | Client PII: masks the initials from session replay. |
| `ring` | `boolean` | `false` | A 2 px ring in the surface colour, to separate stacked avatars. |
| `bordered` | `boolean` | `false` | A hairline border, so a pale fallback matches a photo's edge. |
| `className` | `string` |  | Classes added to the root element, merged with its own. Tokens only. |
| `fallbackClassName` | `string` |  | Classes for the initials or icon fallback, like a different tint. |

### AvatarGroup

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `items` (required) | `AvatarItem[]` |  | The people, first on top. Past max, the rest collapse into a +N disc. |
| `max` | `number` | `4` | How many faces show before the rest collapse into a +N disc. |
| `size` | `"xxs" \| "xs" \| "sm" \| "md" \| "lg" \| "xl" \| "2xl"` | `"sm"` | The size of every face, xxs 16 to 2xl 64. |
| `person` | `"staff" \| "contact" \| "unassigned"` | `"staff"` | Staff or contacts, for every face without its own. |
| `className` | `string` |  | Classes added to the root element, merged with its own. Tokens only. |
| `tooltipTitle` | `string` |  | A heading over the tooltip's list of names. |
| `tooltipSections` | `AvatarTooltipSection[]` |  | Replaces the tooltip's single titled list; empty sections are left out. |
| `tooltipSide` | `SimpleTooltipProps["side"]` | `"bottom"` | Which side the list of names opens on. |
| `tooltipAlign` | `SimpleTooltipProps["align"]` | `"end"` | How the list of names lines up along that side. |
| `tooltipFallbackClassName` | `string` |  | Classes for each name's fallback in the tooltip list. |
| `disableTooltip` | `boolean` | `false` | Leaves out the list of names, for a group that's already labelled beside it. |
| `fallbackClassName` | `string` |  | Classes for every face's fallback. |
| `avatarClassName` | `string` |  | Classes for every face. |
| `ring` | `boolean` | `true` | The separating ring and a hairline edge. On by default. |
