suiss/ui
  • Docs
  • Components
  • Patterns
  • Interactions
  • Charts
  • Blocks
  • AI
GitHubCreate
DocsComponentsPatternsInteractionsChartsBlocksAICreate
Components84
  • Overview
  • Accordion
  • Alert
  • Alert Dialog
  • Alert Sheet
  • Amount Input
  • Aspect Ratio
  • Attachment
  • Avatar
  • Badge
  • Bottom Bar
  • Breadcrumb
  • Bubble
  • Button
  • Button Group
  • Calendar
  • Card
  • Carousel
  • Chart
  • Checkbox
  • Chip
  • Code Block
  • Collapsible
  • Combobox
  • Command
  • Context Menu
  • Dialog
  • Direction
  • Drawer
  • Dropdown Menu
  • Empty
  • FAB
  • Field
  • Fullscreen Menu
  • Haptics
  • Header
  • Hover Card
  • Icon
  • Input
  • Input Accessory Bar
  • Input Group
  • Input OTP
  • Item
  • Kbd
  • Keyboard Scroll View
  • Keypad
  • Label
  • Marker
  • Menubar
  • Message
  • Message Scroller
  • Native Select
  • Navigation Menu
  • Page Indicator
  • Pagination
  • Pin Pad
  • Popover
  • Progress
  • QR Scanner
  • Questionnaire
  • Radio Group
  • Resizable
  • Screen
  • Scroll Area
  • Select
  • Separator
  • Sheet
  • Sidebar
  • Signature Pad
  • Skeleton
  • Slider
  • Spinner
  • Switch
  • Tab Bar
  • Table
  • Tabs
  • Text
  • Textarea
  • Toast
  • Toggle
  • Toggle Group
  • Tooltip
  • Trace
  • Wheel Picker
  • Widget

suiss/ui · Component

Avatar

A circular image that represents a person, with initials or an icon when no image is available.

Avatar is an open-source component from suiss/ui for React, React Native, SwiftUI and Jetpack Compose. The @esuiss/ui CLI copies its source into your project, so you own the code.

import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"

export default function AvatarDemo() {
  return (
    <Avatar>
      <AvatarImage src="https://i.pravatar.cc/128?img=47" alt="Emma Wilson" />
      <AvatarFallback>EW</AvatarFallback>
    </Avatar>
  )
}

Avatar wraps the avatar primitive of the chosen base. An Avatar contains an AvatarImage and an AvatarFallback; the fallback shows while the image is loading or if it fails to load. Add an AvatarBadge to show a status dot or icon in the bottom-end corner.

To show several people together, place avatars in an AvatarGroup, which overlaps them and rings each one with the background color. End the group with an AvatarGroupCount to indicate how many more people there are.

Installation

$ pnpm dlx shadcn@latest add @esuiss/avatar

Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:

$ pnpm dlx @esuiss/ui@latest add avatar
  1. Install the following dependencies and add the cn helper:
$ pnpm add @base-ui/react
  1. Copy and paste the following code into your project.
components/ui/avatar.tsx
"use client"

import { Avatar as AvatarPrimitive } from "@base-ui/react/avatar"
import type * as React from "react"
import { cn } from "@/lib/utils"

function Avatar({
  className,
  size = "default",
  ...props
}: AvatarPrimitive.Root.Props & {
  size?: "default" | "sm" | "lg" | "xl"
}) {
  return (
    <AvatarPrimitive.Root
      data-slot="avatar"
  1. Update the import paths to match your project setup.

Usage

import {
  Avatar,
  AvatarBadge,
  AvatarFallback,
  AvatarGroup,
  AvatarGroupCount,
  AvatarImage,
} from "@/components/ui/avatar"
<Avatar>
  <AvatarImage src={people[0].src} alt={people[0].name} />
  <AvatarFallback>{people[0].initials}</AvatarFallback>
</Avatar>

Composition

Use the following composition to build a Avatar:

Avatar
├── AvatarImage
├── AvatarFallback
└── AvatarBadge
AvatarGroup
├── Avatar
│   ├── AvatarImage
│   └── AvatarFallback
└── AvatarGroupCount

Examples

Fallback

Put the person's initials in AvatarFallback. They show when no image is provided.

import { Avatar, AvatarFallback } from "@/components/ui/avatar"

export default function AvatarFallbackExample() {
  return (
    <Avatar>
      <AvatarFallback>LC</AvatarFallback>
    </Avatar>
  )
}

Fallback sizes

Initials fallbacks at every size. The fallback text scales with the avatar.

import { Avatar, AvatarFallback } from "@/components/ui/avatar"

export default function AvatarFallbackSizes() {
  return (
    <div className="flex items-center gap-3">
      <Avatar size="sm">
        <AvatarFallback>EW</AvatarFallback>
      </Avatar>
      <Avatar size="default">
        <AvatarFallback>EW</AvatarFallback>
      </Avatar>
      <Avatar size="lg">
        <AvatarFallback>EW</AvatarFallback>
      </Avatar>
      <Avatar size="xl">
        <AvatarFallback>EW</AvatarFallback>

Placeholder

Put a person icon in AvatarFallback. The icon scales to 60% of the avatar.

import { UserIcon } from "@phosphor-icons/react"
import { Avatar, AvatarFallback } from "@/components/ui/avatar"

export default function AvatarPlaceholder() {
  return (
    <div className="flex items-center gap-3">
      <Avatar size="sm">
        <AvatarFallback>
          <UserIcon className="fill-current" />
        </AvatarFallback>
      </Avatar>
      <Avatar size="default">
        <AvatarFallback>
          <UserIcon className="fill-current" />
        </AvatarFallback>
      </Avatar>

Sizes

Set size on each Avatar to sm, default, lg or xl.

import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"

export default function AvatarSizes() {
  return (
    <div className="flex items-center gap-3">
      <Avatar size="sm">
        <AvatarImage src="https://i.pravatar.cc/128?img=12" alt="Liam Carter" />
        <AvatarFallback>LC</AvatarFallback>
      </Avatar>
      <Avatar size="default">
        <AvatarImage src="https://i.pravatar.cc/128?img=12" alt="Liam Carter" />
        <AvatarFallback>LC</AvatarFallback>
      </Avatar>
      <Avatar size="lg">
        <AvatarImage src="https://i.pravatar.cc/128?img=12" alt="Liam Carter" />
        <AvatarFallback>LC</AvatarFallback>

With badge

Add an AvatarBadge with a check-mark icon to each size. At the sm size, icons inside the badge are hidden.

import { CheckIcon } from "@phosphor-icons/react"
import {
  Avatar,
  AvatarBadge,
  AvatarFallback,
  AvatarImage,
} from "@/components/ui/avatar"

export default function AvatarWithBadge() {
  return (
    <div className="flex items-center gap-4">
      <Avatar size="sm">
        <AvatarImage
          src="https://i.pravatar.cc/128?img=32"
          alt="Sofia Martinez"
        />

Group

Place avatars in an AvatarGroup and end it with an AvatarGroupCount showing +4. The count matches the size of the avatars in the group.

import {
  Avatar,
  AvatarFallback,
  AvatarGroup,
  AvatarGroupCount,
  AvatarImage,
} from "@/components/ui/avatar"

export default function AvatarGroupExample() {
  return (
    <AvatarGroup>
      <Avatar>
        <AvatarImage src="https://i.pravatar.cc/128?img=47" alt="Emma Wilson" />
        <AvatarFallback>EW</AvatarFallback>
      </Avatar>
      <Avatar>

Group with icon count

Put a plus icon in AvatarGroupCount instead of a number.

import { PlusIcon } from "@phosphor-icons/react"
import {
  Avatar,
  AvatarFallback,
  AvatarGroup,
  AvatarGroupCount,
  AvatarImage,
} from "@/components/ui/avatar"

export default function AvatarGroupWithIconCount() {
  return (
    <AvatarGroup>
      <Avatar size="lg">
        <AvatarImage src="https://i.pravatar.cc/128?img=47" alt="Emma Wilson" />
        <AvatarFallback>EW</AvatarFallback>
      </Avatar>

Accessibility

  • Give AvatarImage an alt that names the person.
  • AvatarBadge and AvatarGroupCount are plain elements; if they carry meaning, label them or describe the status in nearby text.

API Reference

Avatar

The circular root that sets the size.

PropTypeDefault
size"default" | "sm" | "lg" | "xl""default"

Also accepts the props of the primitive part it wraps.

size sets the diameter and also scales the fallback text and badge. It is exposed as data-size.

AvatarImage

The person's image, cropped to a circle.

Also accepts the props of the primitive part it wraps.

AvatarFallback

Content shown when the image is missing or still loading.

PropTypeDefault
delaynumber-

delay is the number of milliseconds to wait before showing the fallback.

Also accepts the props of the primitive part it wraps.

Always provide an AvatarFallback alongside AvatarImage, usually the person's initials. The fallback can also hold an icon, which scales to 60% of the avatar. It uses a vertical gradient of muted-foreground with text-primary-foreground.

AvatarBadge

A small status indicator pinned to the bottom-end corner.

Also accepts the props of React.ComponentProps<"span">.

The badge uses bg-primary by default; override it, for example with bg-green-500. At the sm size, icons inside the badge are hidden.

AvatarGroup

A row that overlaps avatars with a ring between them.

Also accepts the props of React.ComponentProps<"div">.

AvatarGroupCount

A trailing circle that shows how many avatars are not displayed.

Also accepts the props of React.ComponentProps<"div">.

Inside an AvatarGroup, AvatarGroupCount matches the size of the avatars in the group automatically.

Each part sets a data-slot, such as avatar, avatar-fallback or avatar-group-count, for styling.

Web

Web preview

import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"
import { Text } from "@/components/ui/text"

export default function AvatarDemo() {
  return (
    <Avatar>
      <AvatarImage
        alt="Ada Lovelace"
        source={{ uri: "https://i.pravatar.cc/150?img=5" }}
      />
      <AvatarFallback>
        <Text>AL</Text>
      </AvatarFallback>
    </Avatar>
  )
}
import SwiftUI

struct AvatarExample: View {
  var body: some View {
    Avatar(url: URL(string: "https://i.pravatar.cc/150?img=5"), initials: "AL")
      .accessibilityLabel(Text("Ada Lovelace"))
  }
}
import androidx.compose.foundation.layout.Row
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.painter.BrushPainter
import androidx.compose.ui.semantics.contentDescription
import com.esuiss.ui.components.Avatar
import com.esuiss.ui.components.AvatarFallback
import com.esuiss.ui.components.AvatarSize
import com.esuiss.ui.theme.Palette

class AvatarPerson(val name: String, val initials: String, val tones: @Composable () -> List<Color>)

val avatarPeople = listOf(
    AvatarPerson("Ada Lovelace", "AL") { listOf(Palette.pink500, Palette.purple500) },

Avatar is a round View that holds an AvatarImage and an AvatarFallback. The image stays hidden until it loads, and the fallback is shown while it loads or if it fails. Four sizes are available: sm, default, lg and xl; the fallback text, icons and badge scale with the size.

AvatarBadge adds a small status dot in the bottom-end corner, and AvatarGroup overlaps several avatars with an outline between them, with AvatarGroupCount for the remaining number.

Installation

$ pnpm dlx shadcn@latest add @esuiss/avatar

See Installation for the components.json setup. Or use the suiss/ui CLI:

$ pnpm dlx @esuiss/ui@latest add avatar
$ pnpm dlx shadcn@latest add @esuiss/avatar

See Installation for the components.json setup. Or use the suiss/ui CLI:

$ pnpm dlx @esuiss/ui@latest add avatar --platform swift
$ pnpm dlx shadcn@latest add @esuiss/avatar

See Installation for the components.json setup. Or use the suiss/ui CLI:

$ pnpm dlx @esuiss/ui@latest add avatar --platform kotlin

The CLI also adds what it builds on: Icon, Text.

  1. Install the following dependencies:
npx expo install cn
  1. Add the pieces it builds on: Icon, Text.

  2. Copy the primitives it uses into components/primitives:

uniwind/components/primitives/avatar.tsx
import * as React from "react"
import { type ImageSourcePropType, Image as RNImage, View } from "react-native"
import { useEffectEvent } from "./hooks"
import type { BaseUIComponentProps } from "./types"
import { useRender } from "./use-render"

type ImageLoadingStatus = "idle" | "loading" | "loaded" | "error"

interface RootState {
  imageLoadingStatus: ImageLoadingStatus
}

type ImageState = RootState

type FallbackState = RootState
uniwind/components/primitives/hooks.ts
import * as React from "react"
import { BackHandler } from "react-native"

function useEffectEvent<TArgs extends readonly unknown[], TResult>(
  callback: (...args: TArgs) => TResult
): (...args: TArgs) => TResult {
  const callbackRef = React.useRef(callback)

  React.useLayoutEffect(() => {
    callbackRef.current = callback
  })

  return React.useCallback(
    (...args: TArgs): TResult => callbackRef.current(...args),
    []
  )
uniwind/components/primitives/merge-props.ts
type AnyProps = Record<string, unknown>

type PropsGetter = (previous: AnyProps) => object

type MergePropsInput = object | PropsGetter | null | undefined

type Handler = (...args: unknown[]) => unknown

type StyleCallback = (state: never) => unknown

const EMPTY_PROPS: AnyProps = {}

function isEventHandler(key: string, value: unknown) {
  const code0 = key.charCodeAt(0)
  const code1 = key.charCodeAt(1)
  const code2 = key.charCodeAt(2)
uniwind/components/primitives/types.ts
import type * as React from "react"
import type {
  GestureResponderEvent,
  HostInstance,
  NativeSyntheticEvent,
  StyleProp,
  ViewStyle,
} from "react-native"

type Side = "top" | "bottom" | "left" | "right"
type Align = "start" | "center" | "end"
type Orientation = "horizontal" | "vertical"

type ComponentRenderFn<Props, State> = (
  props: Props,
  state: State
uniwind/components/primitives/use-render.tsx
import * as React from "react"
import { useComposedRefs } from "./hooks"
import { mergeClassNames, mergeProps, mergeStyles } from "./merge-props"
import type { ClassNameProp, RenderProp, StyleValue } from "./types"

type AnyProps = Record<string, unknown>

type RefInput<T> = React.Ref<T> | undefined

interface UseRenderParameters<State, RefType = unknown, Props = AnyProps> {
  defaultComponent?: React.ElementType | undefined
  render?: RenderProp<Props, State> | undefined
  props?: object | readonly (object | null | undefined)[] | undefined
  state?: State | undefined
  ref?: RefInput<RefType> | readonly RefInput<RefType>[] | undefined
  className?: ClassNameProp<State>
  1. Copy and paste the following code into components/ui/avatar.tsx:
uniwind/components/ui/avatar.tsx
import { cn } from "cn"
import * as React from "react"
import { View } from "react-native"
import * as AvatarPrimitive from "@/components/primitives/avatar"
import { resolveClassName } from "@/components/primitives/use-render"
import { IconClassContext } from "@/components/ui/icon"
import { Text, TextClassContext } from "@/components/ui/text"

type AvatarSize = "default" | "sm" | "lg" | "xl"

const AvatarSizeContext = React.createContext<AvatarSize>("default")

const AvatarGroupItemContext = React.createContext<number | null>(null)

const ROOT_SIZE: Record<AvatarSize, string> = {
  sm: "size-6",
  1. Update the import paths to match your project setup.
  1. Install the following dependencies:
npx expo install cn
  1. Add the pieces it builds on: Icon, Text.

  2. Copy the primitives it uses into components/primitives:

nativewind/components/primitives/avatar.tsx
import * as React from "react"
import { type ImageSourcePropType, Image as RNImage, View } from "react-native"
import { useEffectEvent } from "./hooks"
import type { BaseUIComponentProps } from "./types"
import { useRender } from "./use-render"

type ImageLoadingStatus = "idle" | "loading" | "loaded" | "error"

interface RootState {
  imageLoadingStatus: ImageLoadingStatus
}

type ImageState = RootState

type FallbackState = RootState
nativewind/components/primitives/hooks.ts
import * as React from "react"
import { BackHandler } from "react-native"

function useEffectEvent<TArgs extends readonly unknown[], TResult>(
  callback: (...args: TArgs) => TResult
): (...args: TArgs) => TResult {
  const callbackRef = React.useRef(callback)

  React.useLayoutEffect(() => {
    callbackRef.current = callback
  })

  return React.useCallback(
    (...args: TArgs): TResult => callbackRef.current(...args),
    []
  )
nativewind/components/primitives/merge-props.ts
type AnyProps = Record<string, unknown>

type PropsGetter = (previous: AnyProps) => object

type MergePropsInput = object | PropsGetter | null | undefined

type Handler = (...args: unknown[]) => unknown

type StyleCallback = (state: never) => unknown

const EMPTY_PROPS: AnyProps = {}

function isEventHandler(key: string, value: unknown) {
  const code0 = key.charCodeAt(0)
  const code1 = key.charCodeAt(1)
  const code2 = key.charCodeAt(2)
nativewind/components/primitives/types.ts
import type * as React from "react"
import type {
  GestureResponderEvent,
  HostInstance,
  NativeSyntheticEvent,
  StyleProp,
  ViewStyle,
} from "react-native"

type Side = "top" | "bottom" | "left" | "right"
type Align = "start" | "center" | "end"
type Orientation = "horizontal" | "vertical"

type ComponentRenderFn<Props, State> = (
  props: Props,
  state: State
nativewind/components/primitives/use-render.tsx
import * as React from "react"
import { useComposedRefs } from "./hooks"
import { mergeClassNames, mergeProps, mergeStyles } from "./merge-props"
import type { ClassNameProp, RenderProp, StyleValue } from "./types"

type AnyProps = Record<string, unknown>

type RefInput<T> = React.Ref<T> | undefined

interface UseRenderParameters<State, RefType = unknown, Props = AnyProps> {
  defaultComponent?: React.ElementType | undefined
  render?: RenderProp<Props, State> | undefined
  props?: object | readonly (object | null | undefined)[] | undefined
  state?: State | undefined
  ref?: RefInput<RefType> | readonly RefInput<RefType>[] | undefined
  className?: ClassNameProp<State>
  1. Copy and paste the following code into components/ui/avatar.tsx:
nativewind/components/ui/avatar.tsx
import { cn } from "cn"
import * as React from "react"
import { View } from "react-native"
import * as AvatarPrimitive from "@/components/primitives/avatar"
import { resolveClassName } from "@/components/primitives/use-render"
import { IconClassContext } from "@/components/ui/icon"
import { Text, TextClassContext } from "@/components/ui/text"

type AvatarSize = "default" | "sm" | "lg" | "xl"

const AvatarSizeContext = React.createContext<AvatarSize>("default")

const AvatarGroupItemContext = React.createContext<number | null>(null)

const ROOT_SIZE: Record<AvatarSize, string> = {
  sm: "size-6",
  1. Update the import paths to match your project setup.
  1. Add the pieces it builds on: Icon, Text.

  2. Copy the primitives it uses into components/primitives:

stylesheet/components/primitives/avatar.tsx
import * as React from "react"
import { type ImageSourcePropType, Image as RNImage, View } from "react-native"
import { useEffectEvent } from "./hooks"
import type { BaseUIComponentProps } from "./types"
import { useRender } from "./use-render"

type ImageLoadingStatus = "idle" | "loading" | "loaded" | "error"

interface RootState {
  imageLoadingStatus: ImageLoadingStatus
}

type ImageState = RootState

type FallbackState = RootState
stylesheet/components/primitives/hooks.ts
import * as React from "react"
import { BackHandler } from "react-native"

function useEffectEvent<TArgs extends readonly unknown[], TResult>(
  callback: (...args: TArgs) => TResult
): (...args: TArgs) => TResult {
  const callbackRef = React.useRef(callback)

  React.useLayoutEffect(() => {
    callbackRef.current = callback
  })

  return React.useCallback(
    (...args: TArgs): TResult => callbackRef.current(...args),
    []
  )
stylesheet/components/primitives/merge-props.ts
type AnyProps = Record<string, unknown>

type PropsGetter = (previous: AnyProps) => object

type MergePropsInput = object | PropsGetter | null | undefined

type Handler = (...args: unknown[]) => unknown

type StyleCallback = (state: never) => unknown

const EMPTY_PROPS: AnyProps = {}

function isEventHandler(key: string, value: unknown) {
  const code0 = key.charCodeAt(0)
  const code1 = key.charCodeAt(1)
  const code2 = key.charCodeAt(2)
stylesheet/components/primitives/types.ts
import type * as React from "react"
import type {
  GestureResponderEvent,
  HostInstance,
  NativeSyntheticEvent,
  StyleProp,
  ViewStyle,
} from "react-native"

type Side = "top" | "bottom" | "left" | "right"
type Align = "start" | "center" | "end"
type Orientation = "horizontal" | "vertical"

type ComponentRenderFn<Props, State> = (
  props: Props,
  state: State
stylesheet/components/primitives/use-render.tsx
import * as React from "react"
import { useComposedRefs } from "./hooks"
import { mergeClassNames, mergeProps, mergeStyles } from "./merge-props"
import type { ClassNameProp, RenderProp, StyleValue } from "./types"

type AnyProps = Record<string, unknown>

type RefInput<T> = React.Ref<T> | undefined

interface UseRenderParameters<State, RefType = unknown, Props = AnyProps> {
  defaultComponent?: React.ElementType | undefined
  render?: RenderProp<Props, State> | undefined
  props?: object | readonly (object | null | undefined)[] | undefined
  state?: State | undefined
  ref?: RefInput<RefType> | readonly RefInput<RefType>[] | undefined
  className?: ClassNameProp<State>
  1. Copy and paste the following code into components/ui/avatar.tsx:
stylesheet/components/ui/avatar.tsx
import * as React from "react"
import { StyleSheet, View } from "react-native"
import * as AvatarPrimitive from "@/components/primitives/avatar"
import { IconSizeContext } from "@/components/ui/icon"
import { Text, TextStyleContext } from "@/components/ui/text"
import { fontSize, radius, useTheme } from "@/components/ui/theme"

type AvatarSize = "default" | "sm" | "lg" | "xl"

const AvatarSizeContext = React.createContext<AvatarSize>("default")

const AvatarGroupItemContext = React.createContext<number | null>(null)

const ROOT_SIZE: Record<AvatarSize, number> = {
  sm: 24,
  default: 32,
  1. Update the import paths to match your project setup.
  1. Target iOS 17 or later.

  2. Add the Swift package to your app:

Package.swift
.package(url: "https://github.com/phosphor-icons/swift", from: "2.1.0")
  1. Copy the theme files every view uses:
swift/Theme/Theme.swift
import CoreText
import SwiftUI
import UIKit

struct RGBA: Sendable {
  let red: CGFloat
  let green: CGFloat
  let blue: CGFloat
  let alpha: CGFloat

  init(_ hex: UInt32, _ alpha: CGFloat = 1) {
    red = CGFloat((hex >> 16) & 0xFF) / 255
    green = CGFloat((hex >> 8) & 0xFF) / 255
    blue = CGFloat(hex & 0xFF) / 255
    self.alpha = alpha
  }
swift/Theme/Tokens.swift
import SwiftUI

public enum EsuissColor {
  public static let background = Color.adaptive(light: .init(0xFFFFFF), dark: .init(0x000000))
  public static let foreground = Color.adaptive(light: .init(0x1D1D1F), dark: .init(0xF5F5F7))
  public static let card = Color.adaptive(light: .init(0xFFFFFF), dark: .init(0x1D1D1F))
  public static let cardForeground = Color.adaptive(light: .init(0x1D1D1F), dark: .init(0xF5F5F7))
  public static let popover = Color.adaptive(light: .init(0xFFFFFF), dark: .init(0x1D1D1F))
  public static let popoverForeground = Color.adaptive(light: .init(0x1D1D1F), dark: .init(0xF5F5F7))
  public static let primary = Color.adaptive(light: .init(0x0071E3), dark: .init(0x0A84FF))
  public static let primaryForeground = Color.adaptive(light: .init(0xFFFFFF), dark: .init(0xFFFFFF))
  public static let secondary = Color.adaptive(light: .init(0x000000, 0.04), dark: .init(0xFFFFFF, 0.1))
  public static let secondaryForeground = Color.adaptive(light: .init(0x1D1D1F), dark: .init(0xF5F5F7))
  public static let muted = Color.adaptive(light: .init(0xF5F5F7), dark: .init(0x161617))
  public static let mutedForeground = Color.adaptive(light: .init(0x6E6E73), dark: .init(0x86868B))
  public static let accent = Color.adaptive(light: .init(0x000000, 0.06), dark: .init(0xFFFFFF, 0.1))
  1. Copy the source:
swift/Components/Avatar.swift
import SwiftUI

public enum AvatarSize: CaseIterable, Sendable {
  case sm, `default`, lg, xl

  var dimension: CGFloat {
    switch self {
    case .sm: 24
    case .default: 32
    case .lg: 40
    case .xl: 64
    }
  }

  var overlap: CGFloat {
    self == .xl ? 16 : 8
  1. Add the files to your app target.
  1. Apply the Compose compiler plugin, enable Compose, set compileSdk to 37 or higher and minSdk to 24 or higher, and add the dependencies:
build.gradle.kts
plugins {
    id("org.jetbrains.kotlin.plugin.compose")
}

android {
    compileSdk = 37
    defaultConfig { minSdk = 24 }
    buildFeatures { compose = true }
}

dependencies {
    implementation(platform("androidx.compose:compose-bom:2026.09.00"))
    implementation("androidx.compose.foundation:foundation")
    implementation("androidx.compose.ui:ui")
    implementation("com.adamglin:phosphor-icon-android:1.0.0")
}
  1. Copy the theme files every view uses:
kotlin/theme/Theme.kt
package com.esuiss.ui.theme

import android.content.res.AssetManager
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.Immutable
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.dropShadow
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.graphics.shadow.Shadow as DropShadow
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.Font
kotlin/theme/Tokens.kt
package com.esuiss.ui.theme

import androidx.compose.runtime.Immutable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp

@Immutable
data class Colors(
    val background: Color,
    val foreground: Color,
    val card: Color,
    val cardForeground: Color,
    val popover: Color,
    val popoverForeground: Color,
    val primary: Color,
  1. Copy the source and every file it uses:
kotlin/components/Avatar.kt
package com.esuiss.ui.components

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.text.BasicText
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
kotlin/components/Content.kt
package com.esuiss.ui.components

import androidx.compose.runtime.compositionLocalOf
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp

val LocalContentStyle = compositionLocalOf { TextStyle.Default }

val LocalContentColor = compositionLocalOf { Color.Unspecified }

val LocalIconSize = compositionLocalOf { 20.dp }
  1. Update the com.esuiss.ui package names to match your project.

Usage

import { Avatar, AvatarImage, AvatarFallback, AvatarBadge, AvatarGroup, AvatarGroupCount } from "@/components/ui/avatar"
import { Text } from "@/components/ui/text"
<Avatar>
  <AvatarImage
    alt="Ada Lovelace"
    source={{ uri: "https://i.pravatar.cc/150?img=5" }}
  />
  <AvatarFallback>
    <Text>AL</Text>
  </AvatarFallback>
</Avatar>
import SwiftUI

struct AvatarExample: View {
  var body: some View {
    Avatar(url: URL(string: "https://i.pravatar.cc/150?img=5"), initials: "AL")
      .accessibilityLabel(Text("Ada Lovelace"))
  }
}
import androidx.compose.foundation.layout.Row
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.painter.BrushPainter
import androidx.compose.ui.semantics.contentDescription
import com.esuiss.ui.components.Avatar
import com.esuiss.ui.components.AvatarFallback
import com.esuiss.ui.components.AvatarSize
import com.esuiss.ui.theme.Palette

class AvatarPerson(val name: String, val initials: String, val tones: @Composable () -> List<Color>)

val avatarPeople = listOf(
    AvatarPerson("Ada Lovelace", "AL") { listOf(Palette.pink500, Palette.purple500) },
    AvatarPerson("Alan Turing", "AT") { listOf(Palette.teal500, Palette.blue500) },
    AvatarPerson("Grace Hopper", "GH") { listOf(Palette.orange500, Palette.red500) },
)

@Composable
fun AvatarPhoto(person: AvatarPerson, size: AvatarSize = AvatarSize.Default, badge: (@Composable () -> Unit)? = null) {
    val tones = person.tones()
    val photo = remember(tones) { BrushPainter(Brush.linearGradient(tones)) }
    Avatar(
        size = size,
        image = photo,
        contentDescription = person.name,
        badge = badge,
        fallback = { AvatarFallback(person.initials) },
    )
}

@Composable
fun AvatarDefault() {
    Row {
        AvatarPhoto(avatarPeople[0])
    }
}

Examples

Fallback

Put initials in AvatarFallback. They show when there is no image.

Web

Web preview

import { Avatar, AvatarFallback } from "@/components/ui/avatar"
import { Text } from "@/components/ui/text"

export default function AvatarFallbackExample() {
  return (
    <Avatar accessibilityLabel="Alan Turing">
      <AvatarFallback>
        <Text>AT</Text>
      </AvatarFallback>
    </Avatar>
  )
}
import SwiftUI

struct AvatarFallbackExample: View {
  var body: some View {
    Avatar {
      AvatarFallback("AT")
    }
    .accessibilityLabel(Text("Alan Turing"))
  }
}
import androidx.compose.foundation.layout.Row
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import com.esuiss.ui.components.Avatar
import com.esuiss.ui.components.AvatarFallback

@Composable
fun AvatarFallbackOnly() {
    Row {
        Avatar(
            modifier = Modifier.semantics { contentDescription = "Alan Turing" },
            fallback = { AvatarFallback("AT") },
        )
    }

Sizes

Set size on each Avatar to sm, default, lg or xl.

Web

Web preview

import { View } from "react-native"
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"
import { Text } from "@/components/ui/text"

export default function AvatarSizes() {
  return (
    <View className="flex-row items-center gap-4">
      <Avatar size="sm">
        <AvatarImage
          alt="Ada Lovelace"
          source={{ uri: "https://i.pravatar.cc/150?img=5" }}
        />
        <AvatarFallback>
          <Text>AL</Text>
        </AvatarFallback>
      </Avatar>
import { View } from "react-native"
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"
import { Text } from "@/components/ui/text"

export default function AvatarSizes() {
  return (
    <View style={{ flexDirection: "row", alignItems: "center", gap: 16 }}>
      <Avatar size="sm">
        <AvatarImage
          alt="Ada Lovelace"
          source={{ uri: "https://i.pravatar.cc/150?img=5" }}
        />
        <AvatarFallback>
          <Text>AL</Text>
        </AvatarFallback>
      </Avatar>
import SwiftUI

struct AvatarSizesExample: View {
  var body: some View {
    HStack(spacing: 16) {
      ForEach(AvatarSize.allCases, id: \.self) { size in
        Avatar(url: URL(string: "https://i.pravatar.cc/150?img=5"), initials: "AL", size: size)
          .accessibilityLabel(Text("Ada Lovelace"))
      }
    }
  }
}
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.painter.BrushPainter
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.unit.dp
import com.esuiss.ui.components.Avatar
import com.esuiss.ui.components.AvatarFallback
import com.esuiss.ui.components.AvatarSize
import com.esuiss.ui.theme.Palette

class AvatarPerson(val name: String, val initials: String, val tones: @Composable () -> List<Color>)

Group

Overlapping avatars in an AvatarGroup with a count. Pass the same size to AvatarGroupCount as to the avatars.

Web

Web preview

import {
  Avatar,
  AvatarFallback,
  AvatarGroup,
  AvatarGroupCount,
  AvatarImage,
} from "@/components/ui/avatar"
import { Text } from "@/components/ui/text"

export default function AvatarGroupExample() {
  return (
    <AvatarGroup>
      <Avatar>
        <AvatarImage
          alt="Ada Lovelace"
          source={{ uri: "https://i.pravatar.cc/150?img=5" }}
import SwiftUI

struct AvatarGroupExample: View {
  var body: some View {
    AvatarGroup {
      ForEach(avatarPeople, id: \.name) { person in
        Avatar(url: URL(string: person.uri), initials: person.initials)
          .accessibilityLabel(Text(verbatim: person.name))
      }
      AvatarGroupCount("+4")
        .accessibilityLabel(Text("4 more"))
    }
  }
}

struct AvatarPerson {
import androidx.compose.foundation.layout.Row
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.painter.BrushPainter
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import com.esuiss.ui.components.Avatar
import com.esuiss.ui.components.AvatarFallback
import com.esuiss.ui.components.AvatarGroup
import com.esuiss.ui.components.AvatarGroupCount
import com.esuiss.ui.components.AvatarSize
import com.esuiss.ui.theme.Palette

With badge

An AvatarBadge with a check icon at each size. On the sm size, the badge hides its children and shows a plain dot.

Web

Web preview

import { CheckIcon } from "phosphor-react-native"
import { View } from "react-native"
import {
  Avatar,
  AvatarBadge,
  AvatarFallback,
  AvatarImage,
} from "@/components/ui/avatar"
import { Icon } from "@/components/ui/icon"
import { Text } from "@/components/ui/text"

export default function AvatarWithBadge() {
  return (
    <View className="flex-row items-center gap-4">
      <Avatar size="sm">
        <AvatarImage
import { CheckIcon } from "phosphor-react-native"
import { View } from "react-native"
import {
  Avatar,
  AvatarBadge,
  AvatarFallback,
  AvatarImage,
} from "@/components/ui/avatar"
import { Icon } from "@/components/ui/icon"
import { Text } from "@/components/ui/text"

export default function AvatarWithBadge() {
  return (
    <View style={{ flexDirection: "row", alignItems: "center", gap: 16 }}>
      <Avatar size="sm">
        <AvatarImage
import PhosphorSwift
import SwiftUI

struct AvatarWithBadgeExample: View {
  var body: some View {
    HStack(spacing: 16) {
      ForEach(AvatarSize.allCases, id: \.self) { size in
        Avatar(size: size) {
          AvatarFallback("AT")
          AvatarImage(url: URL(string: "https://i.pravatar.cc/150?img=12"))
          AvatarBadge(icon: Ph.check.bold)
        }
        .accessibilityLabel(Text("Alan Turing"))
      }
    }
  }
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.painter.BrushPainter
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.unit.dp
import com.adamglin.PhosphorIcons
import com.adamglin.phosphoricons.Bold
import com.adamglin.phosphoricons.bold.Check
import com.esuiss.ui.components.Avatar
import com.esuiss.ui.components.AvatarBadge
import com.esuiss.ui.components.AvatarFallback

Accessibility

  • AvatarImage uses alt as its accessibilityLabel.
  • The image is hidden from screen readers until it has loaded.
  • The badge has no label; describe the status in nearby text if it matters.

API Reference

Avatar

Round container that sets the size.

PropTypeDefault
sizeAvatarSize"default"

Also accepts the props of React.ComponentProps<typeof AvatarPrimitive.Root>.

AvatarImage

Image that appears once it has loaded.

Also accepts the props of React.ComponentProps<typeof AvatarPrimitive.Image>.

Give AvatarImage a source and an alt. Use onLoadingStatusChange to react to loading.

AvatarFallback

Initials or icon shown while the image is missing.

Also accepts the props of React.ComponentProps<typeof AvatarPrimitive.Fallback>.

Put initials or an Icon in the fallback; plain strings are wrapped in Text. Use delay to avoid a flash on fast connections. The fallback is softer in dark mode.

AvatarBadge

Status dot in the bottom-end corner.

Also accepts the props of React.ComponentProps<typeof View>, React.RefAttributes<View>.

AvatarGroup

Row that overlaps its avatars.

Also accepts the props of React.ComponentProps<typeof View>, React.RefAttributes<View>.

AvatarGroupCount

Round counter for the remaining items in a group.

PropTypeDefault
sizeAvatarSize"default"

Also accepts the props of React.ComponentProps<typeof View>, React.RefAttributes<View>.

Set size to match the avatars in the group.

AvatarSize

Values: .sm, .default, .lg, .xl.

Avatar

Round container that sets the size.

ParameterTypeDefault
sizeSize: .sm | .default | .lg | .xl.default
content() -> Content-
urlURL?-
fallback() -> Fallback-
initialsString-

Overloads: init(size:content:), init(url:size:fallback:), init(url:initials:size:).

AvatarImage

Image that appears once it has loaded.

ParameterTypeDefault
urlURL?-
_ imageImage-

Overloads: init(url:), init(_:).

AvatarFallback

Initials or icon shown while the image is missing.

ParameterTypeDefault
content() -> Content-
_ initialsString-
iconImage-

Overloads: init(content:), init(_:), init(icon:).

AvatarIcon

ParameterTypeDefault
_ imageImage-

AvatarBadge

Status dot in the bottom-end corner.

ParameterTypeDefault
content() -> Content-
iconImage-

Overloads: init(content:), init(), init(icon:).

AvatarGroup

Row that overlaps its avatars.

ParameterTypeDefault
content() -> Content-

AvatarGroupCount

Round counter for the remaining items in a group.

ParameterTypeDefault
sizeAvatarSize: .sm | .default | .lg | .xl.default
content() -> Content-
_ countString-

Overloads: init(size:content:), init(_:size:).

AvatarSize

Values: Sm, Default, Lg, Xl.

Avatar

Round container that sets the size.

ParameterTypeDefault
modifierModifierModifier
sizeAvatarSize: Sm | Default | Lg | XlAvatarSize.Default
imagePainter?null
contentDescriptionString?null
badge(@Composable () -> Unit)?null
fallback(@Composable () -> Unit)?null

AvatarFallback

Initials or icon shown while the image is missing.

ParameterTypeDefault
modifierModifierModifier
content@Composable () -> Unit-
textString-

Overloads: AvatarFallback(content), AvatarFallback(text).

AvatarBadge

Status dot in the bottom-end corner.

ParameterTypeDefault
modifierModifierModifier
content@Composable () -> Unit{}

AvatarGroup

Row that overlaps its avatars.

ParameterTypeDefault
modifierModifierModifier
content@Composable () -> Unit-

AvatarGroupCount

Round counter for the remaining items in a group.

ParameterTypeDefault
modifierModifierModifier
sizeAvatarSize: Sm | Default | Lg | XlAvatarSize.Default
content@Composable () -> Unit-
textString-

Overloads: AvatarGroupCount(content), AvatarGroupCount(text).

NextBadgePreviousAttachment

On this page

  1. 01Installation
  2. 02Usage
  3. 03Composition
  4. 04Examples
    • Fallback
    • Fallback sizes
    • Placeholder
    • Sizes
    • With badge
    • Group
    • Group with icon count
  5. 05Accessibility
  6. 06API Reference
    • Avatar
    • AvatarImage
    • AvatarFallback
    • AvatarBadge
    • AvatarGroup
    • AvatarGroupCount
  7. 07Installation
  8. 08Usage
  9. 09Examples
    • Fallback
    • Sizes
    • Group
    • With badge
  10. 10Accessibility
  11. 11API Reference
    • Avatar
    • AvatarImage
    • AvatarFallback
    • AvatarBadge
    • AvatarGroup
    • AvatarGroupCount
    • AvatarSize
    • Avatar
    • AvatarImage
    • AvatarFallback
    • AvatarIcon
    • AvatarBadge
    • AvatarGroup
    • AvatarGroupCount
    • AvatarSize
    • Avatar
    • AvatarFallback
    • AvatarBadge
    • AvatarGroup
    • AvatarGroupCount