A person's picture or initials on their own color, an agent's mark, and a presence dot, in five sizes.
Online
InitialsMPMPMPMPMP
Agent
Away
Offline
import type { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Avatar } from "./ui/uicontext/components/Avatar.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { color, font } from "./ui/uicontext/components/tokens.stylex.ts"import { ada, ben, mira, sam, scout } from "./people.ts"const styles = stylex.create({ rows: { display: "grid", gap: 20 }, row: { display: "flex", flexWrap: "wrap", alignItems: "center", gap: 16 }, label: { inlineSize: "5.5rem", color: color.muted, fontSize: font.sm },})const labels: Record<string, string> = { ada: "Online", mira: "Initials", scout: "Agent", ben: "Away", sam: "Offline" }const sizes = ["xs", "sm", "md", "lg", "xl"] as const// a picture, initials when there's none, the agent mark, and a presence dot on eachexport const AvatarSizes = <M>(h: Html.H<M>) => h.div.attrs(sx(styles.rows)).children( [ada, mira, scout, ben, sam].map((person) => h.div.key(person.id).attrs(sx(styles.row)).children( h.span.attrs(sx(styles.label)).children(labels[person.id] ?? ""), ...sizes.map((size) => Avatar(h, { ...person, key: `${person.id}-${size}`, size })), )), )Installation
pnpm dlx shadcn@latest add checkfu/uicontext/avatarUsage
import { Avatar } from "./ui/uicontext/components/Avatar.ts"export const Owner = <M>(h: Html.H<M>) => Avatar(h, { id: "ada", name: "Ada Lovelace", presence: "active", size: "md" })API reference
AvatarGroupComponent
Props
| Name | Type | Default | Description |
|---|---|---|---|
peoplerequired | AvatarPerson[] | — | Who's in it, in the order they show. |
labelrequired | string | — | What the group is: "Reviewers", "In this doc". It names the group and heads the list. |
max | number | 4 | How many tiles show, the "+N" counted as one; 4 by default. |
size | AvatarSize | — | — |
static | boolean | — | The "+N" only counts, with no list to open: for a crowded row where the list lives elsewhere. |
AvatarView function
Options
| Name | Type | Default | Description |
|---|---|---|---|
key | string | — | Names this avatar among others in the same view; needed for more than one with a picture. |
size | "xs" | "sm" | "md" | "lg" | "xl" | sm | 20, 24, 32, 40 or 64px; sm by default. |
decorative | boolean | — | Leave the avatar out of the accessibility tree, when its name is already written beside it. |
style | Style | — | StyleX styles applied after the avatar's own. |