# Avatar

A small picture that stands for a person, team or account.

```tsx
import { Avatar, AvatarGroup } from '@halo-ds/react';
```

## When to use it
Avatars help people recognise who is who: in comments, member lists, profiles and shared files. They show a photo or illustration when there is one, and initials or an icon when there is not.

The Avatar family has four parts: Avatar (the picture), Avatar image (90 ready-made faces), Avatar status (presence dots and badges) and Avatar group (several avatars overlapping).

## Do
- Show the person's name next to the avatar, or in a Tooltip when space is tight.
- Use a real photo when one exists; fall back to Initials, then Icon.
- Keep the same colour for the same person everywhere.
- Put identity badges on top and presence at the bottom.

## Don't
- Rely on the status colour alone; say "Online" or "Busy" somewhere too.
- Use more than two badges on one avatar.
- Mix sizes in the same list or group.
- Use the Avatar image faces for real people in production; replace them with the person's own photo.

## Props
### Avatar props
| Prop | Type | What it does |
| --- | --- | --- |
| `src` | `string \| undefined` | Photo or illustration. If it is missing or fails to load, initials or the icon show instead. Figma: Type=Image. |
| `name` | `string \| undefined` | The person's name. Read by screen readers and used to make initials. |
| `initials` | `string \| undefined` | Up to two letters. Defaults to the first letters of `name`. Figma: Initials. |
| `icon` | `ReactNode` | Replaces the default person icon when there is no image or name. Figma: Type=Icon. |
| `size` | `AvatarSize \| undefined` | XS 24, S 32, M 40, L 48, XL 64. Figma: Size. |
| `color` | `AvatarColor \| undefined` | Background for initials and icon avatars. Figma: Colour. |
| `status` | `StatusSlot \| undefined` | Badge on the bottom right: a status type, or an `AvatarStatus` for a count or logo. Figma: Bottom status. |
| `topStatus` | `StatusSlot \| undefined` | Badge on the top right. Figma: Top status. |
| `award` | `"verified" \| "first-step" \| "on-fire" \| "champion" \| "legend" \| "quick-thinker" \| "lift-off" \| "most-loved" \| "rare-find" \| "bullseye" \| "finish-line" \| "sum...` | An award on the bottom right, as a name like "champion" or an `Award` element. It takes the bottom corner, so a bottom `status` moves to the top when the top is free. Figma: Award, Change award. |
| `classNames` | `Partial<Record<AvatarPart, string>> \| undefined` | Extra class names for the parts inside the component, by part name, like `{ header: 'my-header' }`. |
| `styles` | `Partial<Record<AvatarPart, CSSProperties>> \| undefined` | Inline styles for the parts inside the component, by part name, like `{ footer: { gap: 4 } }`. |
It also takes the usual HTML attributes for its element.

### AvatarGroup props
| Prop | Type | What it does |
| --- | --- | --- |
| `size` | `AvatarSize \| undefined` | Sets the size of every avatar in the group. Figma: Size. |
| `max` | `number \| undefined` | How many avatars to show before the rest collapse into a "+N" circle. Figma: Count. |
| `total` | `number \| undefined` | The total number of people, when it is more than the avatars you pass in. |
| `children` (required) | `ReactNode` | `Avatar` elements. |
It also takes the usual HTML attributes for its element.

## Examples
### Overview
```tsx
import { Avatar, AvatarGroup } from '@halo-ds/react';

export default function Example() {
  return (
    <div style={{ display: 'grid', gap: 24, justifyItems: 'center' }}>
      <div style={{ display: 'flex', gap: 12, alignItems: 'center' }}>
        <Avatar size="sm" name="Ada Obi" />
        <Avatar size="md" name="Kofi Mensah" status="online" />
        <Avatar size="lg" name="Lena Park" color="purple" />
      </div>
      <AvatarGroup max={3} total={8}>
        <Avatar name="Ada Obi" />
        <Avatar name="Kofi Mensah" />
        <Avatar name="Lena Park" />
        <Avatar name="Mateo Silva" />
      </AvatarGroup>
    </div>
  );
}
```

### Types
A photo, initials, or an icon when there is neither.
```tsx
import { Avatar } from '@halo-ds/react';

export default function Demo() {
  return (
    <div className="demo-row">
      <Avatar size="xl" src="https://images.unsplash.com/photo-1534528741775-53994a69daeb?w=200&q=80" name="Tobi Adeyemi" />
      <Avatar size="xl" name="Ada Okafor" color="purple" />
      <Avatar size="xl" color="blue" />
    </div>
  );
}
```

### Sizes
Extra small 24, small 32, medium 40, large 48 and extra large 64.
```tsx
import { Avatar } from '@halo-ds/react';

export default function Demo() {
  return (
    <div className="demo-row">
      {(['xs', 'sm', 'md', 'lg', 'xl'] as const).map((s) => (
        <Avatar key={s} size={s} name="Ada Okafor" color="purple" />
      ))}
    </div>
  );
}
```

### Colours
Five background colours. Use them to tell people apart, not to mean anything.
```tsx
import { Avatar } from '@halo-ds/react';

export default function Demo() {
  return (
    <div className="demo-row">
      {(['neutral', 'purple', 'blue', 'green', 'orange'] as const).map((c) => (
        <Avatar key={c} size="lg" color={c} initials="AO" name={c} />
      ))}
    </div>
  );
}
```

### Status and badges
Presence on the bottom corner, and a second badge on the top.
```tsx
import { Avatar } from '@halo-ds/react';

export default function Demo() {
  return (
    <div className="demo-row">
      <Avatar size="xl" name="Zainab Bello" color="green" status="online" />
      <Avatar size="xl" name="Kemi Ade" color="blue" status="busy" topStatus="verified" />
      <Avatar size="xl" name="Tunde Ola" color="orange" award="champion" />
    </div>
  );
}
```

More: https://halodesignsystem.dev/components/avatar
