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 itsalt
attribute. - If src fails to load, applies
aria-label
with provided name androle
with 'img' to root div element.
Examples
API
Avatar props
Name | Type | Default | Description |
---|---|---|---|
allowPhoneInitials | boolean | false | When 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