DocsBlog
  • 1.1.2

  • light

    dark

    system

    Switch mode
  • Cerberus

    Acheron

    Elysium

Get Started
Components
Data Grid
Signals
Styling
Theming

Concepts

OverviewCompositionCerberus ContextTesting

Layout

Aspect RatioBleedBoxCenterContainerDividerFlexFloatGridGroupLink OverlayScrollableStackWrap

Components

AccordionAdmonitionAvatarButtonCarouselCheckboxClipboardCollapsibleComboboxConfirm ModalCTAModalDate PickerDialogFieldFieldsetFile UploaderIcon ButtonInputLoading StatesMenuNotificationsNumber InputPaginationPin InputProgressPrompt ModalRadioRatingSelectSplit ButtonSwitchTableTabsTagTextTextareaToggleTooltip

Utilities

Client OnlyDownload TriggerEnvironmentFeature FlagsFocus TrapForFormat ByteFormat NumberFormat Relative TimeFrameHighlightJSON Tree ViewLocaleLocal StoragePortalPresenceShowsplitPropsTheme

Avatar

The Avatar component is used to represent user profile picture or initials.

  • npm
  • source
  • recipe
  • Ark
import { Avatar } from '@cerberus/react'

Usage

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.

Note

The avatar uses a smart hierarchy method. If a source is provided and loads successfully - it will be shown. In all other cases, the fallback will be shown.

Sizes

You can change the size of an Avatar with the size prop.

Gradients

Use the gradient prop to use any gradient for the background color.

Group

Use the Group component to stack Avatars together.

Badge

Use the Float component to show badges.

asChild Prop

You 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.

Customization

You can customize the Avatar any way you like with style props and data-selectors.

Primitives

The layers of the Avatar which can be used to create a fully custom solution.

ComponentDescription
AvatarRootThe context provider for the Avatar parts
AvatarImageThe img of the avatar
AvatarFallbackThe fallback content to display for the avatar

Data Attributes

The primitives additionally use the following data attributes for custom styling:

NameValueDescription
data-scopeavatarThe scope of the components.
data-partrootThe root layer of the scope.
data-partfallbackThe fallback layer of the scope.
data-partimageThe image layer of the scope.

API

Props

The Avatar component is an abstraction of the primitives and accepts the following props:

NameDefaultDescription
fallbackThe fallback content to display for the avatar.
srcThe src of the avatar.
altThe alt of the avatar. Required if using src.
gradientnoneThe gradient theme to display
sizemdThis size of the avatar.

The Avatar component also accepts all the props of the AvatarRoot primitive props

Parts

The AvatarParts API is an Object containing the full family of components.

Note

It is best to only use the AvatarParts if you are building a custom solution. Importing Object based components will ship every property it includes into your bundle, regardless if you use it or not.

NameDescription
RootThe AvatarRoot component which is the Provider for the family.
ImageThe AvatarImage component which displays the image.
FallbackThe AvatarFallback component which is the content to show when there is no image (or it fails to load).

On this page

  • Edit this page on Github
md
mdUser Avatar
Copy
xs
sm
md
lg
xl
2x
3x
4x
Copy

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

Copy
md
mdUser Avatar
Copy
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>
  )
}
Copy
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>
  )
}
Protector Cerberus
Copy
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>
  )
}
Cu
Copy
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>
  )
}