# Avatar

A person or a company shown by photo, initials or icon, alone or in a stacked group.

- Family: display
- Import: `import { Avatar, AvatarGroup } from "@senvenli/react/display";`
- Page: https://design.senvenli.com/docs/components/avatar
- JSON: https://design.senvenli.com/docs/components/avatar.json

## Example: People

Initials from the name, a photo when there is one, and an online dot.

```tsx
import { Avatar } from "@senvenli/react/display";
import { Stack } from "@senvenli/react/layout";

export default function Example() {
  return (
    <Stack direction="horizontal" space="space-150">
      <Avatar name="Amara Okafor" src="/avatars/01.webp" />
      {/* No photo: the initials, on a color picked from the name. */}
      <Avatar name="Lena Fischer" />
      <Avatar name="Marco Bellini" src="/avatars/03.webp" presence="online" />
    </Stack>
  );
}
```

## Examples

### Sizes

Small in dense rows, medium by default, large on a profile.

```tsx
import { Avatar } from "@senvenli/react/display";
import { Stack } from "@senvenli/react/layout";

export default function Example() {
  return (
    <Stack direction="horizontal" space="space-150" align="center">
      <Avatar name="Daniel Reyes" src="/avatars/04.webp" size="small" />
      <Avatar name="Daniel Reyes" src="/avatars/04.webp" size="medium" />
      <Avatar name="Daniel Reyes" src="/avatars/04.webp" size="large" />
    </Stack>
  );
}
```

### A company

Squares are for companies and logos; circles are for people.

```tsx
import { Avatar } from "@senvenli/react/display";
import { Stack } from "@senvenli/react/layout";

// A flat placeholder logo drawn in the file, so the example needs no network.
const LOGO = `data:image/svg+xml,${encodeURIComponent(
  `<svg xmlns="http://www.w3.org/2000/svg" width="96" height="96"><rect width="96" height="96" fill="hsl(150 30% 90%)"/><path d="M24 68 48 24l24 44Z" fill="hsl(150 30% 30%)"/></svg>`,
)}`;

export default function Example() {
  return (
    <Stack direction="horizontal" space="space-150">
      <Avatar name="Northwind Traders" shape="square" />
      <Avatar name="Summit Supply" shape="square" src={LOGO} />
    </Stack>
  );
}
```

### A group

Past `max`, the rest fold into a count.

```tsx
import { Avatar, AvatarGroup } from "@senvenli/react/display";

export default function Example() {
  return (
    <AvatarGroup aria-label="Project members" max={3}>
      <Avatar name="Amara Okafor" src="/avatars/01.webp" />
      <Avatar name="Marco Bellini" src="/avatars/03.webp" />
      <Avatar name="Claire Dubois" src="/avatars/07.webp" />
      <Avatar name="Omar Haddad" src="/avatars/06.webp" />
      <Avatar name="Sofia Marin" src="/avatars/05.webp" />
    </AvatarGroup>
  );
}
```

## Guidelines

### When to use it

- Identifying who did something or who belongs to something.

### Use something else when

- [icon](https://design.senvenli.com/docs/components/icon.md): The object is not a person or a company.

### Do and avoid

- Use circles for people and squares for companies.

## Accessibility

Built in:

- Named by `name`; presence is announced as online.
- AvatarGroup announces how many more people are hidden.

You provide:

- An `aria-label` on AvatarGroup that names the group.

## API reference

### Avatar

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| name | `string` |  | yes | The person's or company's name: the initials and the accessible name. |
| src | `string` |  | no | Photo or company logo; initials (or the icon) show until it loads and if it fails. |
| size | `AvatarSize` |  | no |  |
| shape | `AvatarShape` | `"circle"` | no | `circle` for people, `square` for companies and logos (contained, never stretched). |
| presence | `"online"` |  | no | Shows the 10px online dot and says "online" in the name. |

### AvatarGroup

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| children | `React.ReactNode` |  | yes | Avatars; past `max` they fold into a "+N" avatar. |
| max | `number` | `4` | no | How many show before the "+N"; default 4. |
| size | `AvatarSize` | `"medium"` | no |  |
| aria-label | `string` |  | no | Names the group ("Team members"). |

### Tokens it reads

`--ds-background-brand-subtle`, `--ds-background-information`, `--ds-background-neutral`, `--ds-background-success`, `--ds-icon`, `--ds-icon-brand`, `--ds-icon-danger`, `--ds-icon-information`, `--ds-icon-subtle`, `--ds-icon-success`, `--ds-icon-warning`, `--ds-radius-full`, `--ds-radius-medium`, `--ds-size-icon`, `--ds-size-icon-large`, `--ds-size-icon-small`, `--ds-space-100`, `--ds-space-300`, `--ds-space-400`, `--ds-space-600`, `--ds-surface`, `--ds-surface-sunken`, `--ds-text-brand`, `--ds-text-information`, `--ds-text-subtle`, `--ds-text-success`

## Related

- [badge](https://design.senvenli.com/docs/components/badge.md)
