@hanzo/ui

Avatar

import { Avatar, AvatarImage, AvatarFallback, initialOf } from '@hanzo/ui'

Default

A picture with initials behind it; the initials show until the picture loads and stay if it never does.

Hanzo
HZ
export function Default() {
  return (
    <Avatar>
      <AvatarImage src="https://github.com/hanzoai.png" alt="Hanzo" />
      <AvatarFallback>HZ</AvatarFallback>
    </Avatar>
  )
}

Fallback

Initials alone when there is no picture or the link is dead; `delayMs` holds them back so a fast image does not flash them first.

MC
Mira Chen
MC
Lux
export function Fallback() {
  return (
    <XStack gap="$3" items="center">
      <Avatar>
        <AvatarFallback>MC</AvatarFallback>
      </Avatar>
      <Avatar>
        <AvatarImage
          src="https://github.com/hanzoai/no-such-avatar.png"
          alt="Mira Chen"
        />
        <AvatarFallback>MC</AvatarFallback>
      </Avatar>
      <Avatar>
        <AvatarImage src="https://github.com/luxfi.png" alt="Lux" />
        <AvatarFallback delayMs={600}>LX</AvatarFallback>
      </Avatar>
    </XStack>
  )
}

Sizes

`size` is a number of pixels or a size token; 32 is the default.

Zoo
ZO
Zoo
ZO
Zoo
ZO
Zoo
ZO
export function Sizes() {
  return (
    <XStack gap="$3" items="center">
      <Avatar size={24}>
        <AvatarImage src="https://github.com/zooai.png" alt="Zoo" />
        <AvatarFallback>ZO</AvatarFallback>
      </Avatar>
      <Avatar>
        <AvatarImage src="https://github.com/zooai.png" alt="Zoo" />
        <AvatarFallback>ZO</AvatarFallback>
      </Avatar>
      <Avatar size={48}>
        <AvatarImage src="https://github.com/zooai.png" alt="Zoo" />
        <AvatarFallback>ZO</AvatarFallback>
      </Avatar>
      <Avatar size="$6">
        <AvatarImage src="https://github.com/zooai.png" alt="Zoo" />
        <AvatarFallback>ZO</AvatarFallback>
      </Avatar>
    </XStack>
  )
}

Square

`circular={false}` with a radius of your own suits a workspace or organization mark; `bordered` draws the theme edge around it.

Lux
LX
LX
export function Square() {
  return (
    <XStack gap="$3" items="center">
      <Avatar circular={false} rounded="$3">
        <AvatarImage src="https://github.com/luxfi.png" alt="Lux" />
        <AvatarFallback>LX</AvatarFallback>
      </Avatar>
      <Avatar circular={false} rounded="$3" bordered>
        <AvatarFallback>LX</AvatarFallback>
      </Avatar>
    </XStack>
  )
}

Group

A team stacked with negative margins; a border in the page color keeps each face separate from the next, and the last one is a count.

Hanzo
HZ
Lux
LX
Zoo
ZO
+4
export function Group() {
  return (
    <XStack items="center">
      <Avatar borderWidth={2} borderColor="$background">
        <AvatarImage src="https://github.com/hanzoai.png" alt="Hanzo" />
        <AvatarFallback>HZ</AvatarFallback>
      </Avatar>
      <Avatar ml={-8} borderWidth={2} borderColor="$background">
        <AvatarImage src="https://github.com/luxfi.png" alt="Lux" />
        <AvatarFallback>LX</AvatarFallback>
      </Avatar>
      <Avatar ml={-8} borderWidth={2} borderColor="$background">
        <AvatarImage src="https://github.com/zooai.png" alt="Zoo" />
        <AvatarFallback>ZO</AvatarFallback>
      </Avatar>
      <Avatar ml={-8} borderWidth={2} borderColor="$background">
        <AvatarFallback>+4</AvatarFallback>
      </Avatar>
    </XStack>
  )
}

Types

export type AvatarSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl'
export type AvatarShape = 'square' | 'rounded' | 'circle'
export type AvatarProps = Omit<ComponentProps<typeof GuiAvatar>, 'size'> & {
  /**
   * A record size (xs…xl), or — as before the record sizes — any box gui's
   * Avatar takes (`size={64}`), which keeps the circular account look. Unset,
   * the 32px account avatar.
   */
  size?: AvatarSize | GuiSize
  /** Square (default for a record size), rounded, or circle (the default with no size). */
  shape?: AvatarShape
  /** The image. With `name`, the avatar draws its own image and fallback. */
  src?: string | null
  /** Whose avatar: its first character is the initial, and it seeds the colour. */
  name?: string | null
  /** What the colour is derived from, when it should outlive the name (a record id). */
  colorSeed?: string
  /** An icon in place of the initial; the avatar then takes its parent's ground. */
  icon?: ReactNode
  /** `outline` draws the hue's edge around a lighter fill. */
  variant?: 'soft' | 'outline'
  /** A ground-coloured halo that separates stacked avatars. */
  ring?: boolean
  /** Breathe while something about it is pending. */
  pulsing?: boolean
  /** Makes the avatar a button; it gains a halo under the pointer. */
  onPress?: () => void
  /** The image's accessible description. */
  alt?: string
}
export type AvatarImageProps = ComponentProps<typeof GuiAvatar.Image>
export type AvatarFallbackProps = ComponentProps<typeof GuiAvatar.Fallback>

Exports

AvatarAvatarImageAvatarFallbackinitialOftype AvatarPropstype AvatarSizetype AvatarShape