Avatar

Free

A person as a coin of colored glass in their own color: initials, a figure, a photo or an empty seat, with a presence dot, its color picked from the name so a person looks the same everywhere.

npx shadcn@latest add https://pixilui.com/r/avatar.json

Preview

Each person keeps one color, picked from their name.
Face
Tone
Status

When to use

Use it when

  • A person beside their name: the account button, comments, approval rows, the requester on an approval.
  • Presence on a person (status).
  • An empty seat to invite someone.

Use something else when

  • An agent: agents keep their own shaped faces, so a person never reads as an agent.
  • Several people in a row: use Avatar group.

Installation

Terminal
npx shadcn@latest add https://pixilui.com/r/avatar.json

Adds avatar.tsx, and installs clsx and tailwind-merge. The URL works in any app with a components.json, with no registry to add first.

Usage

example.tsx
import { Avatar } from "@/components/pixilui/avatar";

<Avatar />

Fixed sizes: 16, 20, 24, 32 (default), 40, 48; one letter at 20 and below. Inside a Button pass the button's height less 8.

API reference

PropTypeDefault
namestring""The person's name: it picks the color, gives the initials and is the coin's accessible name. Leave it out for no one in particular (the figure).
srcstring–A photo. It fills the coin; a lens and a hairline sit over it.
tone"grey" | "blue" | "violet" | "fuchsia" | "pink" | "red" | "yellow"–The color. Without it the name picks one (grey when there is no name).
sizenumber32The coin's size in px: 16, 20, 24, 32 (default), 40 or 48. At 20 and below it carries one letter. Inside a Button pass the button's height less 8.
figurebooleanfalseDraw a person in relief instead of initials.
emptybooleanfalseAn empty seat: someone to invite.
emptyLabelstring"Invite someone"The empty seat's accessible name.

Also takes every native <span> attribute, and a ref.

Keyboard

TabNever takes focus on its own: focus the row or button it sits in.

Accessibility

  • With a name it is role="img" named by the name; beside the written name, pass aria-hidden so it is not read twice.
  • Without a name (the figure) it is hidden from assistive tech.
  • The presence dot is named ("Online", or statusLabel).
  • The letters keep 5.2:1 or more on every color.

Motion

  • None of its own: it holds still. A person arriving or leaving a stack uses the foundation's arrive and leave.
Avatar groupOverlapping coins, each cut out of the one behind it.
ChipA removed chip folds away while the row closes the gap.
ButtonThe button brightens on hover, dips to .96 when pressed, and shows pending and done.

PixilUI Pro opens soon. The first 20 licenses are $99.