import { Avatar } from '@cerberus/react'The Avatar component is used to represent a user or entity. It can be used to display a user's profile picture, initials, or a generic icon.
You can change the size of an Avatar with the size prop.
Use the gradient prop to use any gradient for the background color.
Use the Group component to stack Avatars together.
Use the Float component to show badges.
asChild PropYou can use the asChild prop to render the Avatar component as a different element. Cerberus will pass all the props onto your child.
This is great for when you need to link the avatar to a profile page.
You can customize the Avatar any way you like with style props and data-selectors.
The layers of the Avatar which can be used to create a fully custom solution.
| Component | Description |
|---|---|
| AvatarRoot | The context provider for the Avatar parts |
| AvatarImage | The img of the avatar |
| AvatarFallback | The fallback content to display for the avatar |
The primitives additionally use the following data attributes for custom styling:
| Name | Value | Description |
|---|---|---|
data-scope | avatar | The scope of the components. |
data-part | root | The root layer of the scope. |
data-part | fallback | The fallback layer of the scope. |
data-part | image | The image layer of the scope. |
The Avatar component is an abstraction of the primitives and accepts the following props:
| Name | Default | Description |
|---|---|---|
| fallback | The fallback content to display for the avatar. | |
| src | The src of the avatar. | |
| alt | The alt of the avatar. Required if using src. | |
| gradient | none | The gradient theme to display |
| size | md | This size of the avatar. |
The Avatar component also accepts all the props of the AvatarRoot primitive props
The AvatarParts API is an Object containing the full family of components.
| Name | Description |
|---|---|
| Root | The AvatarRoot component which is the Provider for the family. |
| Image | The AvatarImage component which displays the image. |
| Fallback | The AvatarFallback component which is the content to show when there is no image (or it fails to load). |
On this page
charon-light
charon-dark
nyx-light
nyx-dark
amphiaraus-light
amphiaraus-dark
styx-light
styx-dark
thanatos-light
thanatos-dark
hades-light
hades-dark
asphodel-light
asphodel-dark
import { UserAvatar } from '@carbon/icons-react'
import { Avatar, Group } from '@cerberus/react'
export function GroupDemo() {
return (
<Group layout="stack" orientation="horizontal">
<Avatar bgColor="page.bg.200" fallback={<UserAvatar />} />
<Avatar bgColor="page.bg.100" fallback="md" />
<Avatar
alt="User Avatar"
fallback="md"
src="https://avatars.githubusercontent.com/u/71111994?s=200&v=4"
/>
</Group>
)
}
import { UserAvatar } from '@carbon/icons-react'
import { Avatar } from '@cerberus/react'
import { Box, Circle, Float, HStack } from 'styled-system/jsx'
export function FloatDemo() {
return (
<HStack justify="center" w="3/4">
<Box pos="relative">
<Avatar bgColor="page.bg.200" fallback={<UserAvatar />} />
<Float placement="bottom-end" offsetX="1" offsetY="1">
<Circle
bgColor="success.bg.active"
outline="0.2em solid"
outlineColor="page.surface.initial"
size="8px"
/>
</Float>
</Box>
</HStack>
)
}
import { css } from '@/styled-system/css'
import { AvatarRoot } from '@cerberus/react'
import Image from 'next/image'
import Link from 'next/link'
export function NextDemo() {
return (
<AvatarRoot size="lg" asChild>
<Link href="/">
<Image
alt="Protector Cerberus"
className={css({
objectFit: 'cover',
})}
src="https://cerberus.digitalu.design/logo.svg"
height={50}
width={50}
/>
</Link>
</AvatarRoot>
)
}
import { Avatar } from '@cerberus/react'
export function CustomAvatar() {
return (
<Avatar
fallback="Cu"
bgColor="black"
bgImage="none"
border="2px solid"
borderColor="danger.border.initial"
color="danger.text.initial"
fontFamily="sans"
rounded="sm"
transform="skewX(-10deg)"
/>
)
}
import { UserAvatar } from '@carbon/icons-react'
import { Avatar } from '@cerberus/react'
import { HStack } from 'styled-system/jsx'
export function BasicDemo() {
return (
<HStack justify="center" w="3/4">
<Avatar bgColor="page.bg.200" fallback={<UserAvatar />} />
<Avatar bgColor="page.bg.200" fallback="md" />
<Avatar
alt="User Avatar"
fallback="md"
src="https://avatars.githubusercontent.com/u/71111994?s=200&v=4"
/>
</HStack>
)
}
import { Avatar } from '@cerberus/react'
import { HStack } from 'styled-system/jsx'
export function SizesDemo() {
return (
<HStack justify="center" w="3/4">
<Avatar bgColor="page.bg.200" fallback="xs" size="xs" />
<Avatar bgColor="page.bg.200" fallback="sm" size="sm" />
<Avatar bgColor="page.bg.200" fallback="md" size="md" />
<Avatar bgColor="page.bg.200" fallback="lg" size="lg" />
<Avatar bgColor="page.bg.200" fallback="xl" size="xl" />
<Avatar bgColor="page.bg.200" fallback="2x" size="2xl" />
<Avatar bgColor="page.bg.200" fallback="3x" size="3xl" />
<Avatar bgColor="page.bg.200" fallback="4x" size="4xl" />
</HStack>
)
}
import { UserAvatar } from '@carbon/icons-react'
import { Avatar, For, Text } from '@cerberus/react'
import { GRADIENTS } from '@cerberus/tokens/src/const'
import { Grid, GridItem, HStack } from 'styled-system/jsx'
export function GradientDemo() {
return (
<Grid
columns={{
base: 1,
md: 2,
}}
columnGap="xl"
rowGap="md"
>
<For each={GRADIENTS}>
{(gradient) => (
<GridItem colSpan={1} key={gradient}>
<HStack gap="md">
<Avatar fallback={<UserAvatar />} gradient={gradient} />
<Text textStyle="label-sm">{gradient}</Text>
</HStack>
</GridItem>
)}
</For>
</Grid>
)
}