DocsBlog
  • 0.25.3

  • light

    dark

    system

    Switch mode
  • Cerberus

    Acheron

    Elysium

Get Started
Components
Styling
Theming

Concepts

OverviewCompositionTesting

Layout

Aspect RatioBleedBoxCenterContainerDividerFlexFloatGridLink OverlayScrollableStackWrap

Components

AccordionAdmonitionAvatarButtonCarouselCheckboxClipboardCollapsibleComboboxConfirm ModalCTAModalDate PickerDialogFieldFieldsetFile UploaderIcon ButtonInputLoading StatesMenuNotificationsNumber InputPin InputProgressPrompt ModalRadioRatingSelectSplit ButtonSwitchTableTabsTagTextTextareaToggleTooltip

Utilities

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

Avatar

The Avatar component is used to represent a user or entity, displaying a profile picture, initials, or a generic icon.

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

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.

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.

xs
sm
md
lg
xl
2x
3x
4x
Copy
Avatar Demo
import { Avatar } from '@cerberus/react'
import { HStack } from 'styled-system/jsx'
export function AvatarPreview() {
return (
<HStack justify="center" w="3/4">
<Avatar fallback="xs" size="xs" />
<Avatar fallback="sm" gradient="charon-light" size="sm" />
<Avatar fallback="md" gradient="charon-dark" size="md" />
<Avatar fallback="lg" gradient="nyx-light" size="lg" />
<Avatar fallback="xl" gradient="nyx-dark" size="xl" />
<Avatar fallback="2x" gradient="amphiaraus-light" size="2xl" />
<Avatar fallback="3x" gradient="amphiaraus-dark" size="3xl" />
<Avatar fallback="4x" gradient="hades-dark" size="4xl" />
</HStack>
)
}

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.

Note

This is great for when you need to link the avatar to a profile page.

Protector Cerberus
Copy
next-avatar.tsx
import { Avatar } from '@cerberus/react'
import { css } from 'styled-system/css'
import Image from 'next/image'
import Link from 'next/link'
function NextAvatar() {
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>
)
}

Primitives

You can utilize the primitive components or the css prop to customize the avatar.

ComponentDescription
AvatarRootThe context provider for the Avatar parts
AvatarImageThe img of the avatar
AvatarFallbackThe fallback content to display for the avatar
Cu
Copy
avatar.tsx
import { Avatar } from '@cerberus/react'
import { css } from 'styled-system/css'
function CustomAvatar() {
return (
<Avatar
css={{
bgColor: 'black',
bgImage: 'none',
border: '6px solid',
borderColor: 'danger.border.initial',
color: 'danger.text.initial',
fontFamily: 'sans',
transform: 'skewX(-10deg)',
}}
size="4xl"
fallback="Cu"
/>
)
}

API

Props

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

NameDefaultDescription
gradientnoneThe gradient theme to display
sizemdThis size of the avatar.
altThe alt of the avatar.
srcThe src of the avatar.
fallbackThe fallback content to display for 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
Cerberus Design System | Docs