Avatar
A person as a round badge of initials, or their photo.
Overview
Marking who did something or who owns something, next to their name.
Identity
Do
import { Avatar, Cluster } from "@hackcove/ui";
<Cluster>
<Avatar name="Ada Lovelace" />
<Avatar name="Ada Lovelace" size="lg" />
<Avatar name="Grace Hopper" />
</Cluster>Don't
import { Avatar, Cluster } from "@hackcove/ui";
<Cluster>
<Avatar name="Ada" />
<Avatar name="A. Lovelace" />
</Cluster>Beside
Do
Ada Lovelace
import { Avatar, BodyStrong, Cluster } from "@hackcove/ui";
<Cluster>
<Avatar name="Ada Lovelace" />
<BodyStrong>Ada Lovelace</BodyStrong>
</Cluster>Don't
import { Avatar } from "@hackcove/ui";
<Avatar name="Ada Lovelace" />
aria-hidden: it names no one to a screen reader. Put the name beside it.Usage
- Pass the person's full
name, the same string everywhere: the colour and the initials are worked out from it, so one person looks the same in every list and header. sizeissm,md(default),lg,xlor2xl; usesmormdin a row and a larger one at the head of a profile.srcis the person's photo, as a path your app serves. It replaces the initials, and the Avatar never loads an image from another server on its own, so use your own local image.ringis for a stack of overlapping Avatars: each one overlaps the one before it, with a ring in the page colour. Leave it off a single Avatar.- Put the person's name beside the Avatar as text; the Avatar is a mark, not a label.
Accessibility
- Initials are drawn in a
<span>witharia-hidden="true"and atitleof the name, so a screen reader skips them: the name has to be on the page as text. - With
srcthe Avatar is an<img>whosealtandtitleare the name. aria-*anddata-*props go on the root element.
API
Avatar
A person as a round badge of initials, or as their photo when src is given. It never loads a remote image on its own: that is a request to another server for decoration, and it makes a screenshot depend on the network. src is the app's own local path.
name required- Type
string
ringA ring in the page colour, for a stack of overlapping avatars.
- Type
boolean- Default
false
size- Type
"sm" | "md" | "lg" | "xl" | "2xl"- Default
md
srcThe person's photo, a local path. It replaces the initials and is announced as name.
- Type
string
Functions
initialsOfThe up to two letters or digits of a name, upper-cased, or?when it has none: the same initialsAvatardraws, for where you need them as text.avatarColourClassThe background classAvatarpicks for a name, so the same name always gets the same colour.Avatarapplies it for you; passnametoAvatarinstead of using it.