Who someone is, in one row: an avatar, a name and a quieter line that cuts off rather than wraps.
- 5.8 kB JS 5.2 kB CSS gzipped
- No serious axe issues
- Server-rendered, hydrates
- 44px touch targets
- Right-to-left
- 9 tests
RequesterMarisol Kowalczyk-Hernández[email protected] · Enterprise
AgentTriage botTagged it Billing 4m ago
import type { View } from "effect/ui"import type { Html } from "effect/ui/html"import * as stylex from "@stylexjs/stylex"import { PersonLabel } from "./ui/uicontext/components/PersonLabel.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { color, corner, font, space, stroke } from "./ui/uicontext/components/tokens.stylex.ts"const styles = stylex.create({ panel: { display: "grid", gap: space.md, inlineSize: "min(100%, 20rem)", padding: space.lg, borderWidth: stroke.hairline, borderStyle: "solid", borderColor: color.line, borderRadius: corner.card, backgroundColor: color.panel }, field: { display: "grid", gap: space.xs }, name: { fontSize: font.xs, color: color.muted },})const field = <M>(h: Html.H<M>, name: string, value: View.Content<M>) => h.div.key(name).attrs(sx(styles.field)).children(h.span.attrs(sx(styles.name)).children(name), value)// a support ticket's side panel: who asked, who has it, who's watchingexport const TicketPeople = <M>(h: Html.H<M>) => h.div.attrs(sx(styles.panel)).children( field(h, "Requester", PersonLabel(h, { person: { id: "mk", name: "Marisol Kowalczyk-Hernández" }, meta: "[email protected] · Enterprise" })), field(h, "Assignee", PersonLabel(h, { person: { id: "ada", name: "Ada Okafor", presence: "active" }, meta: "Support, Tier 2", href: "#ada" })), field(h, "Agent", PersonLabel(h, { person: { id: "triage", name: "Triage bot", agent: true }, meta: "Tagged it Billing 4m ago", size: "sm" })), )When to use
Who someone is, in one row: an avatar, a name and a quieter line that cuts off rather than wraps. Use Avatar instead when there's room for only the face.
Usage
import { PersonLabel } from "./ui/uicontext/components/PersonLabel.ts"export const Owner = <M>(h: Html.H<M>) => PersonLabel(h, { person: { id: "ada", name: "Ada Okafor" }, meta: "Head of Product" })Examples
Sizes
lg heads a profile, sm fits a table cell and cuts off rather than wraps.
Lena Fischer, awayVP Sales · Berlin
| Rep | Open pipeline |
|---|---|
| Priya RamanMid-market · London | $412,000 |
| Tomás GarcíaEnterprise · Madrid | $1,280,500 |
| Wei ChenSMB · Singapore | $96,300 |
import type { Html } from "effect/ui/html"import * as stylex from "@stylexjs/stylex"import { PersonLabel } from "./ui/uicontext/components/PersonLabel.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { color, font, space, stroke } from "./ui/uicontext/components/tokens.stylex.ts"const styles = stylex.create({ wrap: { inlineSize: "min(100%, 34rem)" }, table: { inlineSize: "100%", tableLayout: "fixed", borderCollapse: "collapse", fontSize: font.sm }, th: { paddingBlock: space.sm, paddingInline: space.sm, textAlign: "start", fontSize: font.xs, fontWeight: 500, color: color.muted, borderBlockEndWidth: stroke.hairline, borderBlockEndStyle: "solid", borderBlockEndColor: color.line }, td: { paddingBlock: space.sm, paddingInline: space.sm, borderBlockEndWidth: stroke.hairline, borderBlockEndStyle: "solid", borderBlockEndColor: color.line }, num: { inlineSize: "8.5rem", textAlign: "end", fontVariantNumeric: "tabular-nums", color: color.muted, whiteSpace: "nowrap" }, head: { marginBlockEnd: space.lg },})const reps = [ { id: "pr", name: "Priya Raman", meta: "Mid-market · London", deals: "$412,000" }, { id: "tg", name: "Tomás García", meta: "Enterprise · Madrid", deals: "$1,280,500" }, { id: "wc", name: "Wei Chen", meta: "SMB · Singapore", deals: "$96,300" },]// `lg` heads a profile; `sm` fits a table cell, cut off with an ellipsis when the column is narrowexport const SalesTeam = <M>(h: Html.H<M>) => h.div.attrs(sx(styles.wrap)).children( h.div.attrs(sx(styles.head)).children(PersonLabel(h, { person: { id: "ln", name: "Lena Fischer", presence: "away" }, meta: "VP Sales · Berlin", size: "lg" })), h.table.attrs(sx(styles.table)).children( h.thead.children(h.tr.children(h.th.attrs({ scope: "col", ...sx(styles.th) }).children("Rep"), h.th.attrs({ scope: "col", ...sx(styles.th, styles.num) }).children("Open pipeline"))), h.tbody.children( reps.map((rep) => h.tr.key(rep.id).children( h.td.attrs(sx(styles.td)).children(PersonLabel(h, { person: { id: rep.id, name: rep.name }, meta: rep.meta, size: "sm" })), h.td.attrs(sx(styles.td, styles.num)).children(rep.deals), )), ), ), )API reference
Options
| Name | Type | Description |
|---|---|---|
personrequired | { /** A stable id: it picks the avatar's color. */ readonly id: string readonly name: string readonly image?: string readonly presence?: typeof AvatarPresence.Type readonly agent?: boolean } | — |
meta | string | The quieter line under the name: a role, an email, when they last replied. |
size | "sm" | "md" | "lg" | sm for lists and table cells, md (the default) for panels, lg for a profile header. |
href | string | Makes the whole row a link to the person. |
key | string | Names this avatar among others in the same view; needed for more than one with a picture. |
style | Style | — |
Installation
pnpm dlx shadcn@latest add checkfu/uicontext/person-label