The Avatar
component is used to represent a user, and displays the profile picture, initials or fallback icon.
import { Avatar, AvatarButton, AvatarLink } from "@vitality-ds/components";
An Avatar can contain either a user profile photo or the user's initials. When both details are present, the initials will show before the image loads.
Use the default size when possible. Depending on the visual context in which the Avatar is used, there are options to alter its size. The size should generally match the surrounding font size.
<Stack direction="horizontal" spacing="sm"> <Avatar initials="TM" /> <Avatar size="xs" initials="MM" /> <Avatar size="sm" initials="QT" /> <Avatar size="md" initials="LA" /> <Avatar size="lg" initials="WWW" /> <Avatar size="lg" imageSrc="https://i.pravatar.cc/300" initials="LA" /> <Avatar size="xl" initials="TM" /> </Stack>
The Avatar
component provides fairly limited options for colour.
- Use the default colour most of the time
- If necessary to draw attention the the Avatar, use primary
<Stack direction="horizontal"> <Avatar initials="TM" /> <Avatar color="primary" initials="MW" /> </Stack>
If the Avatar is interactive, use either AvatarButton
or AvatarLink
. Whilst links will commonly navigate the user to that avatar's profile page, the use case for an AvatarButton is not always as clear. Thus, an AvatarButton requires a tooltip be provided via the tooltipContent
prop to help the user understand what the button's action will do. Read more on tooltips here.
<Stack direction="horizontal"> <AvatarButton tooltipContent="Copy user details" buttonProps={{ onClick: () => alert("User details copied to clipboard!"), }} imageSrc="https://i.pravatar.cc/200" size="lg" initials="LA" /> <AvatarLink linkProps={{ href: "https://google.com", target: "_blank", }} imageSrc="https://i.pravatar.cc/300" size="lg" initials="LA" /> </Stack>
Description
Optional colour set on the component when displaying initials
Type
"primary"
Description
URL of the avatar image to load.
Type
string
Description
The initials of the user being represented. These are timmed to 2 characters.
Type
string
Description
The Size of the avatar
Type
"sm" | "md" | "lg" | "xs" | "xl"
Default Value
md
Description
Props passed to the surrounding button element
Type
HTMLButtonElement
Description
Optional colour set on the component when displaying initials
Type
"primary"
Description
URL of the avatar image to load.
Type
string
Description
The initials of the user being represented. These are timmed to 2 characters.
Type
string
Description
The Size of the avatar
Type
"sm" | "md" | "lg" | "xs" | "xl"
Description
Text to display in the AvatarButton's tooltip when hovered
Type
ReactNode
Description
Optional colour set on the component when displaying initials
Type
"primary"
Description
URL of the avatar image to load.
Type
string
Description
The initials of the user being represented. These are timmed to 2 characters.
Type
string
Description
Props passed to the <a> element.
Type
AvatarLinkPropsType
Description
The Size of the avatar
Type
"sm" | "md" | "lg" | "xs" | "xl"