Avatar

The Avatar component adds additional visual information about a user.

When to use

  • When you want to show a user's image along contextual information.
  • When you want to attribute an action to a user.

Accessibility

  • Top level name prop will be set on the <img> element as its alt attribute.
  • If src fails to load, applies aria-label with provided name and role with 'img' to root div element.

Examples

Avatar with className support

JP
S

Avatar with all colors

A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z

Avatar with available sizes

U
U
U
U
U
U

Avatar with custom sizes

2
3
4
5
6
7
8
2
3
4
5
6
7
8

Avatar in available shapes

U
U
U
U

U
U
U
U

Avatar with error fallback

S
M
L
X
X
X

Avatar with initials

HS
HS
HS
HS

Avatar With Phone Number

93
92

Avatar with example overrides

UN
BK
UN
BK

Avatar with user icon overrides

Avatar group

U
U
U
U

Avatar group with different spacing

U
U
U
+4
U
U
U
+4
U
U
U
+4

Avatar group max

U
U
U
+2

Avatar group overrides

U
U
U
+2

API

Avatar props

NameTypeDefaultDescription
allowPhoneInitials
boolean
falseWhen Avatar detects name as phone number, it renders userIcon as initials. Setting this to true will display phone number's initial
color
string
Defines the custom color or gradient to be shown in background if the image fails to loads underneath the initials
initials
string
Initials to display when image fails to load.
name
string
Alternative text description of the image.
overrides
custom
Lets you customize all aspects of the component.
shape
'rectangle' | 'circle'
Defines the shape of avatar.
size
number
Defines the width/height of the image. Accepts size labels sm, md, lg and xl, or diameter ( in pixel ).
src
string
Image to display.

You can check the implementation of the component for more details.

Avatar exports

You can import this module like so:

import {Avatar} from 'spaceweb/avatar'

It exports the following components or utility functions:

  • Avatar
  • AvatarGroup
  • StyledAvatar
  • StyledAvatarGroup
  • StyledInitials
  • StyledRoot
  • getAvatarSize
  • useAvatarColor