组件

Avatar

A face, circled in felt tip. The picture is circled by a hand-drawn loop; without one the initials sit on a disc of marker in a stationery color chosen from the name. A status dot goes on the corner, and a group overlaps its faces and ends in a sketched "+3".

安装

terminal
npx shadcn@latest add @wobko/avatar

第一次使用?先把 registry 加进 components.json。 如何安装

示例

Photo and initials

A picture circled by hand, and what shows while there is none: initials on a disc of marker whose color is chosen from the name. The four sizes are `sm`, `default`, `lg` and `xl`; `AvatarBadge` puts a status dot on the corner.

Color from the name

Give `AvatarFallback` a `name` and it makes the initials, picks one of eight stationery colors from the name (the same person is the same color everywhere) and lets a screen reader hear the full name instead of two letters. `ring` picks the pen of the loop, and `"none"` draws no loop for long lists.

Groups

`AvatarGroup` overlaps faces and a paper-colored ring cuts each one out of the last (`--ll-avatar-ring` changes the color on a different surface). `AvatarGroupCount` is the sketched disc for everyone who did not fit; it takes text or an icon.

Team card

A people list in a card: face, name, role, and a presence dot. Each face is a separate small drawing (the list is short); a list of hundreds would use `ring="none"`.

API 参考

Avatar

The Radix Avatar root, a round `span`. It does not clip (the picture and the disc round themselves, always as circles: the hand-drawn loop is a circle too, so a `rounded-lg` on the root, as some sidebar templates use, does not square the face) so the loop can bleed past its box. `data-size` is read by its parts.

属性类型默认值说明
size"sm" | "default" | "lg" | "xl""default"24, 32, 40 or 56 px. Anything else: give it a `size-*` class.
ring"ink" | "you" | "marker" | "none""ink"The pen of the loop round the face: ink fine-liner, blue felt, a marker halo ("this one is current"), or none, which draws nothing (long lists).
seedstring | number-Pins the hand of the loop. Default: derived from useId().

AvatarFallback

The initials disc, shown while there is no picture.

属性类型默认值说明
namestring-The person's name: picks the color, makes the initials when there are no children, and is read out by screen readers in place of the letters.
tone"tomato" | "tangerine" | "lemon" | "grass" | "teal" | "sky" | "grape" | "bubblegum"-A color of your own instead of the one the name picks.
delayMsnumber-Radix: wait this long before showing the fallback, to avoid a flash while the picture loads.

AvatarBadge

A dot on the corner of the face. Its size follows the avatar's; an icon child shows from `default` up.

属性类型默认值说明
status"online" | "away" | "busy" | "offline" | "marker""marker"grass, tangerine, tomato, pencil gray, or the marker of the theme. Give it text for screen readers (`<span className="sr-only">online</span>`).

无障碍

  • The loop, the disc and the dot are aria-hidden decoration. Give the picture an `alt` (or `alt=""` next to the name in text), and give AvatarFallback a `name` so the person is read out instead of two letters.
  • Color is never the only carrier: the initials say who, and the badge needs its own text for its meaning (online, busy). The initials are ink on a 62% marker, 5.5:1 or better on all eight colors.
  • An avatar is not interactive. Wrap it in a Button or link yourself, and the hand-drawn loop then sits inside that control's focus ring.
  • The same name is always the same color on the server and in the browser (a hash of the trimmed, lower-cased name), so nothing changes at hydration.
  • Windows high contrast removes the drawings and keeps the picture or initials.

源码

CLI 会复制进你项目的文件。

正在加载源码