# Avatar

A portrait circled with the pen; initials on a wash of ink when there's no picture.

Docs: https://ballpoint.st9wd.com/docs/avatar

```bash
npx shadcn@latest add @ballpoint/avatar
```

```tsx
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"

<Avatar>
  <AvatarImage src="/me.jpg" alt="Me" />
  <AvatarFallback>ON</AvatarFallback>
</Avatar>
```

Props:

- `size`: `"sm" | "default" | "lg" | "xl"` (default `"default"`). 24, 32, 40 or 56px; the initials and the status dot scale with it.
- `seed`: `string | number`. Pins the drawing.

Pen settings: `draw`, `passes`, `weight`, `speed` (see Pen settings).

Every other prop goes to Base UI's Avatar: https://base-ui.com/react/components/avatar

## Example

```tsx
import { Avatar, AvatarBadge, AvatarFallback, AvatarGroup, AvatarGroupCount, AvatarImage } from "@/components/ui/avatar";

export default function AvatarDemo() {
  return (
    <div className="flex flex-wrap items-center gap-8">
      <Avatar size="lg" seed="av-image">
        <AvatarImage src="/doodle-portrait.svg" alt="A doodled portrait" />
        <AvatarFallback>DP</AvatarFallback>
      </Avatar>
      <Avatar seed="av-fallback">
        <AvatarFallback>AL</AvatarFallback>
        <AvatarBadge seed="av-dot" />
      </Avatar>
      <Avatar size="sm" seed="av-small">
        <AvatarFallback>GH</AvatarFallback>
      </Avatar>
      <AvatarGroup>
        {["AL", "GH", "KJ"].map((initials) => (
          <Avatar key={initials} seed={`av-group-${initials}`}>
            <AvatarFallback>{initials}</AvatarFallback>
          </Avatar>
        ))}
        <AvatarGroupCount>+4</AvatarGroupCount>
      </AvatarGroup>
    </div>
  );
}
```

## User list

Avatars with a name, an email and an online dot.

```tsx
import { Avatar, AvatarBadge, AvatarFallback } from "@/components/ui/avatar";

const people = [
  ["AL", "Ada Lovelace", "ada@example.com", true],
  ["GH", "Grace Hopper", "grace@example.com", false],
  ["KJ", "Katherine Johnson", "katherine@example.com", true],
] as const;

export default function AvatarList() {
  return (
    <ul className="flex w-full max-w-sm flex-col gap-5">
      {people.map(([initials, name, email, online]) => (
        <li key={initials} className="flex items-center gap-4">
          <Avatar size="lg" seed={`al-${initials}`}>
            <AvatarFallback>{initials}</AvatarFallback>
            {online && <AvatarBadge seed={`al-dot-${initials}`} />}
          </Avatar>
          <div className="flex min-w-0 flex-col">
            <span className="font-bold">{name}</span>
            <span className="truncate text-sm text-ink-3">{email}</span>
          </div>
        </li>
      ))}
    </ul>
  );
}
```

## Sizes

Four sizes, from a margin dot to a profile picture.

```tsx
import { Avatar, AvatarFallback } from "@/components/ui/avatar";

const sizes = ["sm", "default", "lg", "xl"] as const;

export default function AvatarSizes() {
  return (
    <div className="flex items-end gap-6">
      {sizes.map((size) => (
        <figure key={size} className="flex flex-col items-center gap-2">
          <Avatar size={size} seed={`asz-${size}`}>
            <AvatarFallback>GH</AvatarFallback>
          </Avatar>
          <figcaption className="font-mono text-sm text-ink-3">{size}</figcaption>
        </figure>
      ))}
    </div>
  );
}
```

## Stacked

A group that overlaps like coins, with how many more.

```tsx
import { Avatar, AvatarFallback, AvatarGroup, AvatarGroupCount } from "@/components/ui/avatar";

const people = ["AL", "GH", "KJ", "MJ", "DV"];

export default function AvatarStack() {
  const shown = people.slice(0, 3);
  return (
    <div className="flex flex-col gap-6">
      <div className="flex items-center gap-4">
        <AvatarGroup>
          {shown.map((initials) => (
            <Avatar key={initials} seed={`ast-${initials}`}>
              <AvatarFallback>{initials}</AvatarFallback>
            </Avatar>
          ))}
          <AvatarGroupCount seed="ast-more">+{people.length - shown.length}</AvatarGroupCount>
        </AvatarGroup>
        <span className="text-ink-2">Ada, Grace, Katherine and 2 others are writing.</span>
      </div>
      <AvatarGroup>
        {people.map((initials) => (
          <Avatar key={initials} size="lg" seed={`ast-lg-${initials}`}>
            <AvatarFallback>{initials}</AvatarFallback>
          </Avatar>
        ))}
      </AvatarGroup>
    </div>
  );
}
```

## Profile

A large avatar with a status dot, a role and a follow button.

```tsx
import { Avatar, AvatarBadge, AvatarFallback } from "@/components/ui/avatar";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";

export default function AvatarProfile() {
  return (
    <div className="flex w-full max-w-md items-center gap-5">
      <Avatar size="xl" seed="apr-grace">
        <AvatarFallback>GH</AvatarFallback>
        <AvatarBadge seed="apr-dot" />
      </Avatar>
      <div className="flex min-w-0 flex-1 flex-col gap-1">
        <div className="flex flex-wrap items-center gap-2">
          <span className="text-xl font-bold">Grace Hopper</span>
          <Badge variant="secondary" size="sm" seed="apr-role">
            Editor
          </Badge>
        </div>
        <span className="text-ink-3">Writing since 1952. Online now.</span>
      </div>
      <Button variant="outline" size="sm" seed="apr-follow">
        Follow
      </Button>
    </div>
  );
}
```

## Pen settings

- `draw`: `"auto" | "mount" | "none"` (default `"auto"`). When the strokes draw themselves in: the first time they scroll into view, as soon as they render, or never (already drawn).
- `passes`: `1 | 2 | 3`. How many times an outline is gone over. Each component picks its own default.
- `weight`: `number` (default `1`). Line weight multiplier. Also settable in CSS as --ink-weight.
- `speed`: `number` (default `1`). Drawing speed multiplier. Also settable in CSS as --ink-speed.
