Avatar

The <smart-avatar> component renders a user/entity avatar in either single or grouped form. It follows the Base + Standard + Wrapper pattern with an InjectionToken-based extension mechanism. The abstract AvatarBaseComponent defines the shared API — imageUrl, initials, size, shape, notificationPosition, group (for stacked/multi-avatar display), optional IAvatarOptions, cssClass (alias class), and a derived isGroup computed signal that is true when group() has at least one item. AvatarStandardComponent is a barebones placeholder concrete implementation. AvatarComponent is the public wrapper that renders AvatarStandardComponent by default and accepts a custom replacement via AVATAR_STANDARD_COMPONENT_TOKEN.


Usage

<smart-avatar [initials]="initials" [size]="size" [shape]="shape" />

<smart-avatar [group]="team" [options]="groupOptions" size="sm" />

The preview renders the code above in an application that registers every preset (provideSmartPresets(), see Installation) and the English translations; without the presets, a component that has one renders its standard implementation instead, for most components unstyled markup.

Components

AvatarComponent (<smart-avatar>)

Main wrapper component. Renders AvatarStandardComponent by default. When AVATAR_STANDARD_COMPONENT_TOKEN is provided, renders the injected component via NgComponentOutlet and passes it every input, class included.

AvatarStandardComponent (<smart-avatar-standard>)

Barebones placeholder concrete implementation. Renders a host <span> carrying the external cssClass plus data-size and data-shape attributes. Inside:

  • Group mode (isGroup() is true): one <span class="smart-avatar-group-item"> per IAvatarItem (tracked by id). Each item renders an <img> when the item has imageUrl, otherwise a <span class="smart-avatar-initials"> with the item's initials.
  • Single mode (isGroup() is false): an <img> when imageUrl() is set, otherwise <span class="smart-avatar-initials"> when initials() is set, otherwise a <span aria-hidden="true" class="smart-avatar-placeholder">·</span> fallback.

It does not include Tailwind UI styling — it exists solely as the default structural placeholder until a custom implementation is registered through the token.

AvatarPresetComponent (<smart-avatar-preset>)

Styled variation that extends AvatarBaseComponent and is a drop-in replacement for AvatarStandardComponent. Register it via AVATAR_STANDARD_COMPONENT_TOKEN ({ provide: AVATAR_STANDARD_COMPONENT_TOKEN, useValue: AvatarPresetComponent }) to restyle every <smart-avatar>, register every preset at once with provideSmartPresets(), or use the <smart-avatar-preset> selector directly. It renders three content modes — an <img> (when imageUrl is set), an initials chip (when initials is set or options.placeholderType === 'initials'), or an SVG icon placeholder (the default) — across the full SmartAvatarSize scale (xs→size-8, sm→size-9.5, md→size-11, lg→size-15.5, xl→size-20) in both circle (rounded-full) and rounded (rounded-lg) shapes. When notificationPosition (top/bottom) is set the avatar is wrapped in a relative container with a corner status dot; when group() is non-empty it renders an overlapping stacked group (negative -space-x-2, ringed members), reversed when options.stackDirection === 'bottom-to-top'. In group mode the status dot is not rendered. All classes are smart:-prefixed Tailwind with explicit dark: variants; the class recipes are internal to the preset (not exported).

Used directly, <smart-avatar-preset> takes the extra classes as class or [cssClass]; on <smart-avatar> pass class and the wrapper forwards it.

AvatarBaseComponent (abstract)

Abstract base directive for extending custom avatar implementations. Static smartType: DynamicComponentType = 'avatar'. Exposes:

  • imageUrl: InputSignal<string | undefined>
  • initials: InputSignal<string | undefined>
  • size: InputSignal<SmartAvatarSize> (default 'md')
  • shape: InputSignal<SmartAvatarShape> (default 'circle')
  • notificationPosition: InputSignal<'top' | 'bottom' | undefined>
  • group: InputSignal<IAvatarItem[] | undefined>
  • options: InputSignal<IAvatarOptions | undefined>
  • cssClass: InputSignal<string> (alias class, default '')
  • isGroup = computed(() => !!this.group()?.length)

API

Inputs

InputTypeDefaultDescription
imageUrlInputSignal<string | undefined>-URL of the avatar image (single mode)
initialsInputSignal<string | undefined>-Initials shown when no imageUrl is provided (single mode)
sizeInputSignal<SmartAvatarSize>'md'Avatar size: 'xs' | 'sm' | 'md' | 'lg' | 'xl'. Styled by the preset; the standard exposes it as data-size
shapeInputSignal<SmartAvatarShape>'circle'Avatar shape: 'circle' | 'rounded'. Styled by the preset; the standard exposes it as data-shape
notificationPositionInputSignal<'top' | 'bottom' | undefined>-Preset only: the corner of the status dot (single mode). The standard does not render it
groupInputSignal<IAvatarItem[] | undefined>-When set, renders a group of avatars instead of a single one
optionsInputSignal<IAvatarOptions | undefined>-Optional configuration (placeholder type, stack direction)
classInputSignal<string>''External CSS classes (alias for cssClass)

IAvatarItem

One avatar of a group. Each item must have a unique id (used as the @for track key). When imageUrl is present the item renders as an <img>; otherwise as initials.

FieldTypeDefaultDescription
idstringrequiredKey of the item.
imageUrlstringundefinedPicture URL.
initialsstringundefinedInitials when there is no picture.

IAvatarOptions

FieldTypeDefaultDescription
placeholderType'icon' | 'initials''icon'The fallback of a single avatar without imageUrl. initials are shown whenever they are set; without them AvatarPresetComponent renders an SVG icon ('icon') or an empty initials chip ('initials'), while AvatarStandardComponent renders a · placeholder and exposes the value as data-placeholder-type. Not used in group mode.
stackDirection'top-to-bottom' | 'bottom-to-top''top-to-bottom'Stacking order of a group. Styled by the preset ('bottom-to-top' reverses the overlapping stack); the standard exposes it as data-stack-direction on the group container (the root <span>, only in group mode), so plain CSS can target it.

Single vs Group Mode

The component automatically detects mode from group():

  • Group mode: when group() is a non-empty array, isGroup() is true and the component iterates group(). The single-mode imageUrl/initials/placeholder branch is not rendered.
  • Single mode: when group() is undefined or [], isGroup() is false and the component renders imageUrl (or initials, or placeholder) as a single avatar.

AVATAR_STANDARD_COMPONENT_TOKEN

InjectionToken that allows replacing the default AvatarStandardComponent with a custom implementation. Provide a Type<AvatarBaseComponent> to override; the wrapper passes it every input it declares, class included.

Extending the base class

import {
  ChangeDetectionStrategy,
  Component,
  computed,
  signal,
  ViewEncapsulation,
} from '@angular/core';

import {
  AvatarBaseComponent,
  AvatarComponent,
  AVATAR_STANDARD_COMPONENT_TOKEN,
  IAvatarItem,
  SmartAvatarSize,
} from '@smartsoft001/angular';

@Component({
  selector: 'docs-custom-avatar',
  template: `
    <span [class]="containerClasses()">
      @if (isGroup()) {
        @for (item of group(); track item.id) {
          <span class="docs-avatar__group-item">
            @if (item.imageUrl; as url) {
              <img [src]="url" alt="" />
            } @else {
              <span class="docs-avatar__initials">{{ item.initials }}</span>
            }
          </span>
        }
      } @else if (imageUrl(); as url) {
        <img [src]="url" alt="" />
      } @else if (initials(); as text) {
        <span class="docs-avatar__initials">{{ text }}</span>
      } @else {
        <span class="docs-avatar__placeholder" aria-hidden="true"
          >&middot;</span
        >
      }

      @if (notificationPosition(); as position) {
        <span
          class="docs-avatar__notification"
          [attr.data-position]="position"
        ></span>
      }
    </span>
  `,
  encapsulation: ViewEncapsulation.None,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CustomAvatarComponent extends AvatarBaseComponent {
  containerClasses = computed(() =>
    [
      'docs-avatar',
      `docs-avatar--${this.size()}`,
      `docs-avatar--${this.shape()}`,
      this.cssClass(),
    ]
      .filter(Boolean)
      .join(' '),
  );
}

@Component({
  selector: 'docs-avatar-custom-example',
  imports: [AvatarComponent],
  providers: [
    {
      provide: AVATAR_STANDARD_COMPONENT_TOKEN,
      useValue: CustomAvatarComponent,
    },
  ],
  template: `
    <smart-avatar
      [initials]="initials"
      [size]="size()"
      shape="rounded"
      notificationPosition="top"
    />

    <smart-avatar [group]="team" size="sm" />
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class AvatarCustomExampleComponent {
  initials = 'TW';
  size = signal<SmartAvatarSize>('md');

  team: IAvatarItem[] = [
    { id: 'ana', initials: 'AK' },
    { id: 'bo', initials: 'BS' },
    { id: 'cai', initials: 'CL' },
  ];
}

Source

The component lives in packages/shared/angular/src/lib/components/avatar and is documented for Claude Code by the angular-components-avatar skill.

SmartAvatar shows a user picture: an image (imageUrl), initials, or a placeholder, in five sizes and two shapes, with an optional status dot in a corner (notificationPosition). With a non-empty group it renders a stack of avatars instead. SmartAvatarStandard (the default) is unstyled markup that exposes size, shape, the placeholder type and the stack direction as data-* attributes for your own CSS; the styled look comes from SmartAvatarPreset.


Usage

import {
  IAvatarItem,
  IAvatarOptions,
  SmartAvatar,
  SmartAvatarShape,
  SmartAvatarSize,
} from '@smartsoft001/react';

const initials = 'JD';
const size: SmartAvatarSize = 'lg';
const shape: SmartAvatarShape = 'rounded';

const team: IAvatarItem[] = [
  { id: 'u1', imageUrl: 'https://i.pravatar.cc/64?img=1' },
  { id: 'u2', imageUrl: 'https://i.pravatar.cc/64?img=2' },
  { id: 'u3', initials: 'AK' },
];

const groupOptions: IAvatarOptions = { stackDirection: 'bottom-to-top' };

export function AvatarUsageExample() {
  return (
    <>
      <SmartAvatar initials={initials} size={size} shape={shape} />

      <SmartAvatar group={team} options={groupOptions} size="sm" />
    </>
  );
}

The preview renders the code above in an application that registers every preset (SMART_PRESET_COMPONENTS on SmartProvider, see Installation) and the English translations; without the presets, a component that has one renders its standard implementation instead, for most components unstyled markup.

Exports

All from @smartsoft001/react.

ExportKindWhat it is
SmartAvatarcomponentRenders the implementation registered as components.avatar on SmartProvider, SmartAvatarStandard by default.
SmartAvatarPresetcomponentStyled avatar variation (preset).
SmartAvatarStandardcomponentThe default avatar rendering: unstyled markup exposing size, shape, options.placeholderType and, for a group, options.stackDirection as data-* attributes.
useAvatarhookThe state every avatar variant shares: whether group holds avatars to stack.

The preset's class helpers (getAvatarImageClasses, getAvatarInitialsClasses, getAvatarIconWrapperClasses, getAvatarStatusClasses, getAvatarGroupContainerClasses, getAvatarGroupItemImageClasses, getAvatarGroupItemInitialsClasses, AVATAR_STATUS_WRAPPER) are exported too, for a custom implementation that wants the preset look.

Props and Types

SmartAvatarProps

PropTypeDefaultDescription
imageUrl?string—Picture URL; when missing, the initials or the placeholder are shown.
initials?string—Initials shown when there is no image.
size?SmartAvatarSize'md'The size scale (xs to xl). Styled by the preset; data-size on the standard.
shape?SmartAvatarShape'circle'circle or rounded (rounded square). Styled by the preset; data-shape on the standard.
notificationPosition?'top' | 'bottom'—Preset only: corner of the status dot of a single avatar; no dot when unset. SmartAvatarStandard ignores it.
group?IAvatarItem[]—Renders a stacked group instead of one avatar when non-empty.
options?IAvatarOptions—Placeholder type and stack direction.
className?string—Classes on the outermost element (group container, status wrapper or the avatar).

IAvatarOptions

FieldTypeDefaultDescription
placeholderType?'icon' | 'initials''icon'Fallback shown when there is no imageUrl (default 'icon'). Initials are shown whenever initials is set; otherwise SmartAvatarPreset renders an SVG icon ('icon') or an empty initials chip ('initials'), and SmartAvatarStandard renders a · placeholder. The standard also exposes the value as the data-placeholder-type attribute on its root element.
stackDirection?'top-to-bottom' | 'bottom-to-top''top-to-bottom'Stacking order of a group (default 'top-to-bottom'). Purely visual: styled by SmartAvatarPreset ('bottom-to-top' reverses the stack); SmartAvatarStandard exposes it as the data-stack-direction attribute on the group container.

IAvatarItem

One avatar of a group.

FieldTypeDefaultDescription
idstringrequiredKey of the item.
imageUrl?string—Picture URL.
initials?string—Initials when there is no picture.
  • SmartAvatarSize: 'xs' \| 'sm' \| 'md' \| 'lg' \| 'xl' — Size scale of the avatar.
  • SmartAvatarShape: 'circle' \| 'rounded' — circle or rounded (rounded square).

Replacing the Implementation

SmartAvatar renders the component registered under the 'avatar' key of SmartProvider's components, and SmartAvatarStandard when nothing is registered there. Every SmartAvatar below the provider then renders the registered component, which receives the same props.

SmartAvatarPreset is the styled (preset) implementation: register it under the 'avatar' key of SmartProvider's components, render it directly in place of SmartAvatar, or spread SMART_PRESET_COMPONENTS on the provider to register every preset at once (see the react-provider skill). Pass components as a stable object (a module constant or a memoised value), or the context changes on every render.

The useAvatar hook

The state every avatar variant shares: whether group holds avatars to stack.

ReturnsTypeDescription
isGroupbooleantrue when group holds avatars to stack.
import {
  IAvatarItem,
  SmartAvatar,
  SmartAvatarProps,
  SmartAvatarSize,
  SmartProvider,
  useAvatar,
} from '@smartsoft001/react';

export function CustomAvatar({
  imageUrl,
  initials,
  size = 'md',
  shape = 'circle',
  notificationPosition,
  group,
  className,
}: SmartAvatarProps) {
  const { isGroup } = useAvatar({ group });

  const containerClasses = [
    'docs-avatar',
    `docs-avatar--${size}`,
    `docs-avatar--${shape}`,
    className,
  ]
    .filter(Boolean)
    .join(' ');

  return (
    <span className={containerClasses}>
      {isGroup ? (
        group?.map((item) => (
          <span key={item.id} className="docs-avatar__group-item">
            {item.imageUrl ? (
              <img src={item.imageUrl} alt="" />
            ) : (
              <span className="docs-avatar__initials">{item.initials}</span>
            )}
          </span>
        ))
      ) : imageUrl ? (
        <img src={imageUrl} alt="" />
      ) : initials ? (
        <span className="docs-avatar__initials">{initials}</span>
      ) : (
        <span className="docs-avatar__placeholder" aria-hidden="true">
          &middot;
        </span>
      )}

      {notificationPosition && (
        <span
          className="docs-avatar__notification"
          data-position={notificationPosition}
        />
      )}
    </span>
  );
}

// A module constant: a new object on every render would change the context.
const components = { avatar: CustomAvatar };

const team: IAvatarItem[] = [
  { id: 'ana', initials: 'AK' },
  { id: 'bo', initials: 'BS' },
  { id: 'cai', initials: 'CL' },
];

export function AvatarCustomExample({
  size = 'md',
}: {
  size?: SmartAvatarSize;
}) {
  return (
    <SmartProvider components={components}>
      <SmartAvatar
        initials="TW"
        size={size}
        shape="rounded"
        notificationPosition="top"
      />

      <SmartAvatar group={team} size="sm" />
    </SmartProvider>
  );
}

Styling

  • SmartAvatarStandard carries no visual styling: style it with your own CSS on data-size, data-shape, data-placeholder-type and, for a group container, data-stack-direction.
  • SmartAvatarPreset styles every size, both shapes, the status dot and the stacked group, with smart:dark: variants; options.stackDirection: 'bottom-to-top' reverses the stack there.

Source

The component lives in packages/shared/react/src/lib/components/avatar and is documented for Claude Code by the react-components-avatar skill.