Components / Feedback and display
Avatar
A person, team or thing shown as a picture, falling back to initials and then to an icon. AvatarGroup overlaps several and sums up the rest as "+3". An avatar only shows who it is; to make one pressable, put it inside a Button or Link.
When to useLink to "When to use"
- Who did or owns something: the author of a comment, the people assigned to a task, the account in a menu.
- A thing with an identity: a team, a workspace or a project, with
iconorshape="square". - Several people in little space:
AvatarGroupwithmax.
Use something else when:
- the picture is content, not an identity: Image
- it is a status or a category with no person behind it: Badge
- it is only an icon: Icon
- the person is still loading: Skeleton with
shape="circle"
UsageLink to "Usage"
import { Avatar, AvatarGroup } from "@arshad-shah/cynosure";
import { folder } from "@arshad-shah/cynosure/icons";
<Avatar name="Ada Lovelace" />
<Avatar name="Ada Lovelace" src={ada.photo} status="online" />
<Avatar name="Design files" icon={folder} shape="square" />
<AvatarGroup label="Reviewers" max={3}>
{reviewers.map((person) => (
<Avatar key={person.id} name={person.name} src={person.photo} />
))}
</AvatarGroup>Picture, initials, iconLink to "Picture, initials, icon"
name is required: it is what assistive technology reads and where the initials come from. The initials are the first letters of the first and last word, upper-cased; one word gives one letter. Whole emoji and non-Latin letters are kept. initials replaces them.
With src, the fallback shows while the picture loads and stays if it fails; the broken picture is removed. A new src is tried again.
icon is for things that are not people: it shows instead of initials worked out from the name. A name with no letter, number or emoji shows the user icon.
Sizes and shapesLink to "Sizes and shapes"
size is xs, sm, md (default), lg or xl. sm, md and lg are the control heights, so an avatar lines up with a Button or a field of the same size. shape="square" rounds the corners like a control of that size.
Tone and colourLink to "Tone and colour"
tone colours the fallback; color takes any CSS colour for a one-off. tone="auto" picks one of accent, info, success, warning or danger from the name: the same name always gets the same tone, on every render and on the server. It is decoration that makes a list easier to scan, never the only way to tell people apart: show or speak the name too.
StatusLink to "Status"
status adds a dot at the bottom end corner and is spoken after the name: "Ada Lovelace, online". Translate the words with labels.
GroupLink to "Group"
AvatarGroup overlaps its avatars along the reading direction and gives them all its size. With max, the avatars past that number become one "+N" avatar whose accessible name counts and lists them ("3 more: Katherine Johnson, Barbara Liskov, Margaret Hamilton"); change the words with labels.more(count, names). label names the group.
PropsLink to "Props"
| Prop | What it does | Type | Default |
|---|---|---|---|
nameRequired | Who or what it is: the accessible name, and where the initials come from. An empty name is not announced. | string | |
initials | Replaces the initials worked out from name (one or two characters). | string | |
src | The picture. The fallback shows while it loads, and stays when it is missing or fails to load. | string | |
icon | The fallback for things that are not people: shown instead of initials worked out from name. Without it, a name with no letters falls back to the user icon. | IconData | |
size | Width and height. Inside an AvatarGroup the group's size is used. Default "md". | AvatarSize | "md" |
shape | Outline: a circle, or a square with rounded corners. Default "circle". | "circle" | "square" | "circle" |
tone | Colour of the fallback. "auto" picks a tone from name, the same one every time, so people in a list are easier to tell apart (decoration: the name still has to be shown or spoken). Default "neutral". | Tone | "auto" | "neutral" |
color | Any CSS colour for the fallback, for a one-off. Overrides tone. | string | |
status | A dot at the corner, spoken after the name ("Ada Lovelace, online"). | AvatarStatus | |
labels | The spoken names of the statuses, to translate them. | Partial<AvatarLabels> | |
decorative | Hides the avatar from assistive technology, for when the name is written beside it. | boolean | |
className | Added to the root element, for layout. | string | |
style | Layout only. Restyle through --cy-avatar-* tokens. | CSSProperties |
Generated from the type definitions in @arshad-shah/cynosure 0.5.0.
AvatarGroupLink to "AvatarGroup"
| Prop | What it does | Type | Default |
|---|---|---|---|
nameRequired | Who or what it is: the accessible name, and where the initials come from. An empty name is not announced. | string | |
initials | Replaces the initials worked out from name (one or two characters). | string | |
src | The picture. The fallback shows while it loads, and stays when it is missing or fails to load. | string | |
icon | The fallback for things that are not people: shown instead of initials worked out from name. Without it, a name with no letters falls back to the user icon. | IconData | |
size | Width and height. Inside an AvatarGroup the group's size is used. Default "md". | AvatarSize | "md" |
shape | Outline: a circle, or a square with rounded corners. Default "circle". | "circle" | "square" | "circle" |
tone | Colour of the fallback. "auto" picks a tone from name, the same one every time, so people in a list are easier to tell apart (decoration: the name still has to be shown or spoken). Default "neutral". | Tone | "auto" | "neutral" |
color | Any CSS colour for the fallback, for a one-off. Overrides tone. | string | |
status | A dot at the corner, spoken after the name ("Ada Lovelace, online"). | AvatarStatus | |
labels | The spoken names of the statuses, to translate them. | Partial<AvatarLabels> | |
decorative | Hides the avatar from assistive technology, for when the name is written beside it. | boolean | |
className | Added to the root element, for layout. | string | |
style | Layout only. Restyle through --cy-avatar-* tokens. | CSSProperties |
Generated from the type definitions in @arshad-shah/cynosure 0.5.0.
Behaviour and accessibilityLink to "Behaviour and accessibility"
Avatar has no keyboard or pointer behaviour: it cannot be focused or pressed.
- Name: the root has
role="img"and is named byname. The picture inside hasalt=""and the initials are not announced separately, so the name is read once. - Status: part of the accessible name, so it never depends on colour. Offline is also drawn hollow.
- Decorative: when the name is written beside the avatar,
decorativehides it from assistive technology (aria-hidden, no role). An avatar with an empty name is hidden the same way. - Group:
role="group"named bylabel. The "+N" avatar is an image named bylabels.more. - Contrast: fallback initials keep 4.5:1 or better in every tone (tested).
- Right to left: the status dot sits at the left corner and a group overlaps towards the left.
- Forced colours: an outline keeps the avatar's shape and the status dot draws in the text colour.
TouchLink to "Touch"
Nothing to touch. When an avatar is wrapped in a Button or Link, that component provides the hit area.
ThemingLink to "Theming"
Tokens: --cy-avatar-size-{xs,sm,md,lg,xl}, --cy-avatar-radius, --cy-avatar-font-weight, --cy-avatar-soft-mix, --cy-avatar-status-size, --cy-avatar-ring-color, --cy-avatar-ring-width and --cy-avatar-overlap.
| Token | What it sets |
|---|---|
--cy-avatar-size-{xs,sm,md,lg,xl} | Width and height at each size |
--cy-avatar-radius | Corner radius of the square shape |
--cy-avatar-font-weight | Weight of the initials |
--cy-avatar-soft-mix | Tint strength of the fallback (percentage of the tone mixed into the surface) |
--cy-avatar-status-size | Diameter of the status dot |
--cy-avatar-ring-color | Colour of the ring around grouped avatars and the status dot; set it to the surface they sit on |
--cy-avatar-ring-width | Width of that ring |
--cy-avatar-overlap | How far each avatar in a group slides over the one before it |
createTheme({ components: { avatar: { radius: "4px", overlap: "6px" } } });className and style are for layout only.
RelatedLink to "Related"
These examples run Cynosure 0.5.0 (commit 50ce30b), the version on npm.