Web and native

Avatar in kanso-ui 0.59.0, for React.

import { Avatar } from '@kanso-labs/kanso-ui'

A person, drawn as a circle holding their photo or, until it loads or when there is none, their initials.

The photo is cropped to fill the circle. With no name to take initials from, it draws Material Design's anonymous person icon. It shares its box, sizes, tones and loading with ProductIcon, so a person and a thing fill the same slot.

What you provide

  • name (required, even with a photo): it supplies both the initials and the accessible name, so a screen reader announces the person rather than two letters. The initials are the first and last words of the name, passing over a title before it ("Dr."), a suffix after it ("Jr.", "III") and a bracketed aside at its end. A name written without spaces takes one initial.
  • decorative when the person's name is already written beside the avatar, so a screen reader reads it once.

Props

PropTypeDefaultDescription
decorativebooleanfalseHides the avatar from assistive technology, for one beside the person's name — a row whose headline is the name, a byline — where it would otherwise announce the name a second time. `name` still supplies the initials, and is not announced.
groupbooleanfalseDraws a team rather than a person: Kanso's rounded square in place of the circle. Use the circle for a person, and the square for a team, never the other way round.
imgPropsPick<ImgHTMLAttributes<HTMLImageElement>, 'crossOrigin' | 'decoding' | 'fetchPriority' | 'loading' | 'referrerPolicy' | 'sizes' | 'srcSet'>—Attributes for the picture's own `<img>`: a `srcSet` and `sizes` for a screen's density, a `referrerPolicy` or `crossOrigin` for where it is served from, a `fetchPriority`, or `loading` and `decoding`, which are `lazy` and `async` unless given.
name requiredstring—The person this represents. Supplies both the initials and the accessible name, so a screen reader announces who it is rather than reading two letters aloud. A display name, as a reader would see it written: the initials are its first and last words. A title before the name ("Dr."), a generational suffix after it ("Jr.", "III") and an aside in brackets at its end ("(she/her)") are passed over, as is punctuation a word opens with. A name written without spaces between its words, as Japanese and Chinese names are, is one word, and takes one initial.
showPersonIconbooleantrueWhether an avatar with no initials to take, for a blank `name`, draws the anonymous person glyph. `false` leaves the tinted disc empty, for a loading skeleton.
size'lg' | 'md' | 'sm''md'Diameter, as Kanso's Avatar page gives it: `sm` 28px for a stack beside a title, `md` 36px for a row's lead and the app bar, `lg` 56px for a large lead.
srcstring—A photo to show in place of the initials. The initials stay until it has loaded, and come back if it fails.
tone'accent' | 'ink' | 'negative' | 'neutral' | 'positive' | 'primary' | 'secondary' | 'tertiary''neutral'Who the person is, as one of Kanso's three avatar styles: `ink` for the person signed in, `neutral`, the tonal style on `container`, for anyone else, and `accent`, on `accent-soft`, for a persona that speaks for the product — never for a person. Give each person one style everywhere. `negative`, `positive`, `primary`, `secondary` and `tertiary` are deprecated: they draw as `neutral`, and warn once in development.

Also takes the props of Omit<RenderComponentProps<'span'>, 'children'>.

Example

import { Avatar, Text } from '@kanso-labs/kanso-ui'
<Avatar name="Ada Lovelace" />
<Avatar name="Grace Hopper" src={photo} size="lg" tone="secondary" />
<>
  <Avatar decorative name="Ada Lovelace" />
  <Text variant="bodyLarge">Ada Lovelace</Text>
</>

The design’s classes

k-avatar, k-avatar--sm, k-avatar--lg, k-avatar--ink, k-avatar--accent, k-avatar--group, k-avatars, k-persona, k-persona__text, k-persona__name, k-persona__meta. Maps to Avatar in kanso-ui and react-native-kanso-ui; the persona is new in Kanso.