Components
Avatars
The Avatar component is used to represent user, and displays the profile picture, initials or a fallback icon.
Import
Avatar: The image that represents the user.AvatarBadge: A wrapper that displays it's content on the on the right corner of the avatar.AvatarGroup: A wrapper to stack multiple Avatars together.
import { Avatar, AvatarBadge, AvatarGroup } from '@outfitio/outkit';
Usage
Avatar Sizes
The Avatar component comes in 7 sizes - 2xs, xs, sm, md, lg, xl, 2xl
Avatar Fallbacks
If the user has not specified an avatar image, there are 2 fallbacks:
- If there's a
nameprop, we use it to generate the initials and a random, accessible background color. - If there's no
nameprop, we use a default avatar.
Avatar with badge
You can use the AvatarBadge to show a user is online.
Note the use of
emfor the size of theAvatarBadge. This is useful to size the badge relative to the avatar font size
AvatarGroup
In some cases, you might need to stack avatars as a group. Use the AvatarGroup component.
- To limit the amount of avatars to show, use the
maxprop. It'll truncate the avatars and show a "+X" label, where X is the remaining avatars. - To size all the avatars equally, pass the
sizeprop on the AvatarGroup. - To adjust the spacing between the avatars, pass the
spacingprop.
Accessibility
- The avatar component represents content and should have a text equivalent for users using assistive technologies. If
the avatar does not appear alongside a text label, use the
nameprop as alt text.
Best Practice
- When using an avatar group, include a
maxprop to limit the number of avatars.
Props
The Avatar component composes Box component so you can pass props for Box.
| Name | Type | Default | Description |
|---|---|---|---|
| size | 2xs, xs, sm, md, lg, xl, 2xl | md | The size of the avatar |
| showBorder | boolean | false | If true, the Avatar will show a border around it. Best for a group of avatars |
| isActive | boolean | false | Display an extra colored border around the avatar to signify the user is 'active' |
| activeColor | string: theme.color | info.500 | The theme color of the isActive border eg info.500, success.400 |
| name | string | The name of the user in the avatar | |
| src | string | The image url of the Avatar | |
| children | React.ReactNode | The badge at the bottom right corner of the Avatar. |