Avatar

People, small: initials or a weave made from their name.

MCMira
JPJon
ALAda

Hover the group: it opens, and each person has a tooltip.

Click someone to change their status.

InitialsMCMCMCMCWeaveMCMCMCMC24324056

Installation

Terminal
npx shadcn@latest add https://fabrickit.org/r/avatar.json

This copies the component into components/fabricui and its engine into lib/fabricui. It's your code from then on. First time? Add the theme once: see Installation.

Code

components/fabricui/avatar.tsx
"use client";

import * as React from "react";
import { mount } from "@/lib/fabricui/mount";
import { weave as drawWeave, speaker } from "@/lib/fabricui/avatar-engine";
import "./avatar.css";

const useIsoLayoutEffect = typeof window !== "undefined" ? React.useLayoutEffect : React.useEffect;
const cx = (...c: (string | false | undefined)[]) => c.filter(Boolean).join(" ");

/** "Mira Chen" → "MC" */
const initialsOf = (name = "") => {
  const w = name.trim().split(/\s+/).filter(Boolean);
  return ((w[0]?.[0] ?? "") + (w.length > 1 ? w[w.length - 1][0] : "")).toUpperCase();
};
components/fabricui/avatar.css
/*
 * Avatar — a person, small. Shared by every page that shows people.
 *
 *   <span class="avatar avatar--md" data-name="Mira Chen">MC</span>         initials
 *   <span class="avatar avatar--md" data-name="Mira Chen" data-weave></span> weave (avatar.js draws it)
 *
 * Sizes: --xs 24, --sm 32, --md 40 (default), --lg 56.
 * A weave avatar is a 1-bit dither pattern made from the person's name (the
 * same ordered dither as the cloth): unique to them, the same every time.
 *
 * Status: add <span class="avatar__status" data-status="online|away|busy|offline">
 * inside. Group: wrap in .avatar-stack (it fans open on hover and focus).
 * Speaking: wrap in .avatar-speaker; avatar.js turns the speaker to cloth.
 */
.avatar:where(.fui-avatar, .fui-avatar *) {
  --s: 40px;
lib/fabricui/avatar-engine.js
/*
 * avatar-engine.js — draws weave avatars and turns speakers to cloth (see avatar.css). From avatar.js.
 *
 * Weave: every [data-weave] avatar gets a 1-bit dither pattern made from its
 * data-name: a soft field (a few blobs placed by a hash of the name) run
 * through the same 4×4 Bayer dither the cloth uses. Same name, same weave.
 *
 * The weave is drawn once and kept as an image, so the cloth (which draws
 * the page's own markup) can carry it too.
 *
 * Speaker: speaker(wrapper) returns { speak(on) }. While someone
 * speaks, their avatar turns to cloth and soft ripples run out from its
 * middle with a voice-like rhythm (cloth-drop.js speak()); when they stop
 * it lies flat again.
 */
import { Dither } from "./dither";

Usage

Usage
import { Avatar, AvatarStack, AvatarSpeaker } from "@/components/fabricui/avatar";

export function Member() {
  return <Avatar name="Mira Chen" weave status="online" />;
}

export function People() {
  return (
    <AvatarStack aria-label="People in this file">
      <Avatar as="button" name="Mira Chen" weave />
      <Avatar as="button" name="Jon Park" weave />
      <Avatar as="button" className="avatar--more" aria-label="2 more">+2</Avatar>
    </AvatarStack>
  );
}

export function OnCall({ talking }: { talking: boolean }) {
  return (
    <AvatarSpeaker speaking={talking}>
      <Avatar size="lg" name="Ada Lee" weave />
    </AvatarSpeaker>
  );
}

Props

PropTypeDefault
name

The person's name: their initials, the weave's seed, and the label screen readers hear.

string—
size

24, 32, 40 or 56px.

"xs" | "sm" | "md" | "lg""md"
weave

A 1-bit dither pattern made from the name instead of the initials: unique to them, the same every time.

booleanfalse
status

A dot in the corner. It pops when it changes.

"online" | "away" | "busy" | "offline"—
as

button, to make it clickable and reachable with Tab.

"span" | "button""span"
decorative

No label of its own, when what it sits in already names the person.

booleanfalse
children

Shown instead of the initials. With className="avatar--more" it's the "+3" at the end of a group.

ReactNode—
AvatarStack

Overlapping avatars that fan open on hover and focus.

component—
AvatarSpeaker

Wraps one Avatar. While speaking, it turns to cloth and ripples out from the middle like a voice.

component—