Avatar

Avatar

HkAvatar is the identity chip: a round, fixed-size surface that either shows a picture or falls back to the first letter of a name. It is the one avatar grammar of the library — the round footprint, the letter chip and the failed-image latch all live here, so every roster, list row and account surface renders a person the same way. Reach for it wherever a person or an organisation is represented without an action attached.

  • When the avatar itself is a trigger that opens a menu, use HkAvatarButton: it composes this same avatar and adds the button semantics.
  • A count or a colour dot pinned to a corner of an avatar is HkCornerBadge, not a variant of this component.
  • A short piece of metadata that labels one row — a type, a state — is a Badge or a Tag chip rather than an avatar.

Import

tsx
1
import { HkAvatar } from "@celestia-island/hikari";
rust
1
2
use hikari_components::*;          // Avatar, AvatarSize
use hikari_components::prelude::*; // rsx!, VNode

The Rust form is a plain function, Avatar(AvatarProps { … }). Inside rsx! every prop may be omitted, an omitted prop takes its default, and the component's children are not rendered at all — the avatar's content is derived from src and name alone.

Sizes

Three steps — sm, md (the default) and lg — carried by hk-avatar-{size}: 32px, 40px and 48px square, with a matching font size for the letter chip.

A
G
A

Image and letter fallback

With src the component renders an <img> whose alt is name; without it — or once that image has failed to load — it renders the name's first character, upper-cased, in a span.hk-avatar-fallback chip. The fell-back letter is the first character of name as JavaScript counts characters, and a missing name falls to the localised ? placeholder.

The failed-image latch is per URL: a 404 swaps the broken picture for the very same letter chip the absent-src branch draws, and pointing src at a new URL gives the image a fresh attempt. That is what keeps a roster from showing the browser's broken-picture glyph. The Rust mirror renders whatever src it is given — it carries no load state, so the snapshot shows the image.

Ada Lovelace
格
?

API

Vue

Props

NameTypeDefaultRequired
srcString——
nameString——
size<code>String as PropType<"sm" | "md" | "lg"></code>"md"—

Rust

Props — Avatar

PropTypeDefaultDescription
srcOption<String>NoneImage source; when absent the initial fallback renders.
nameOption<String>NoneUser name (also the image alt).
sizeAvatarSizeAvatarSize::Md—

Accessibility

  • With an image the avatar is decorative-to-neutral: the <img alt> is name, so a person's name is announced once and the chip needs no extra label.
  • Without an image the fallback chip is plain text — the accessible name becomes the single initial. When the initial is the only thing distinguishing two people in a row, put the full name in the row's own text so the initial is not all that is announced.
  • The avatar is not focusable and has no interactive semantics; making it a trigger is HkAvatarButton's job, and that page carries the keyboard story.

Related components

  • HkAvatarButton — the same round avatar as a menu trigger.
  • HkCornerBadge — a dot, a count or a label pinned to an avatar's corner.
  • HkBadge — a small tone-coded label, for metadata rather than identity.