StylishAvatar

fun StylishAvatar(initials: String = "", modifier: Modifier = Modifier, size: Dp = 40.dp, containerColor: Color = MaterialTheme.colorScheme.primaryContainer, contentColor: Color = MaterialTheme.colorScheme.onPrimaryContainer, avatarImage: @Composable () -> Unit? = null, content: @Composable () -> Unit? = null)

A circular avatar that shows a person's initials, an arbitrary image, or caller-supplied content.

When neither avatarImage nor content is provided, initials are rendered in MaterialTheme.typography.titleMedium, truncated to at most three characters. When avatarImage is provided it is clipped to the circle and fills the avatar. content takes precedence over avatarImage.

Accessibility: when initials is non-blank and no custom avatarImage or content is supplied, the initials are exposed as the avatar's androidx.compose.ui.semantics.contentDescription. For image avatars, set an appropriate description inside avatarImage (e.g. via Modifier.semantics) since the library cannot infer it.

The root carries the default test tag stylish_avatar for UI tests; callers can override it by passing their own Modifier.testTag(...) in modifier.

Parameters

initials

Short text shown in the avatar, typically a person's initials (max 3 characters are displayed). Ignored when avatarImage or content is provided.

modifier

Modifier applied to the avatar surface. The size is enforced via size, overriding any incoming size modifier.

size

Diameter of the avatar. Defaults to 40.dp.

containerColor

Background color of the avatar. Defaults to MaterialTheme.colorScheme.primaryContainer.

contentColor

Default content color (text/icon) inside the avatar. Defaults to MaterialTheme.colorScheme.onPrimaryContainer.

avatarImage

Optional image content, clipped to the circle and scaled to fill the avatar. Ignored when content is provided.

content

Optional fully custom content, drawn centered inside the circle and taking precedence over avatarImage and initials.