# Person Label

> Who someone is, in one row: an avatar, a name and a quieter line that cuts off rather than wraps.

Page: https://uicontext.com/docs/components/person-label

Group: Primitives.

## 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](https://uicontext.com/docs/components/avatar.md) instead when there's room for only the face.

## Usage

```ts
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

Each example is a complete file. Its imports point where the CLI installs the source.

### A ticket's people

The example the page opens with: Person Label in “A ticket's people”.

```ts title="src/demo.ts" source="www/src/examples/person-label/demo.ts"
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 watching
export 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: "marisol@harborview.example · 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" })),
	)
```

### Sizes

`lg` heads a profile, `sm` fits a table cell and cuts off rather than wraps.

```ts title="src/sizes.ts" source="www/src/examples/person-label/sizes.ts"
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 narrow
export 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 |
| --- | --- | --- |
| `person` (required) | `{ /** 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

```sh
pnpm dlx shadcn@latest add checkfu/uicontext/person-label
```

With npm: `npx shadcn@latest add checkfu/uicontext/person-label`. With yarn: `yarn dlx shadcn@latest add checkfu/uicontext/person-label`. With bun: `bunx --bun shadcn@latest add checkfu/uicontext/person-label`.

It writes these files:

- `src/ui/uicontext/components/Avatar.ts`
- `src/ui/uicontext/components/Button.ts`
- `src/ui/uicontext/components/Glyph.ts`
- `src/ui/uicontext/components/IconStroke.ts`
- `src/ui/uicontext/components/InlineNotice.ts`
- `src/ui/uicontext/components/PersonLabel.ts`
- `src/ui/uicontext/components/Popover.ts`
- `src/ui/uicontext/components/Sx.ts`
- `src/ui/uicontext/components/button.stylex.ts`
- `src/ui/uicontext/components/domain/Format.ts`
- `src/ui/uicontext/components/domain/Glyph.ts`
- `src/ui/uicontext/components/tokens.stylex.ts`
- `src/ui/uicontext/components/touch.stylex.ts`
- `src/ui/uicontext/components/variants.ts`

And installs the npm packages `@stylexjs/stylex`, `effect`.

## Source

- [src/PersonLabel.ts](https://github.com/checkfu/uicontext/blob/main/src/PersonLabel.ts)

## Related

- [Button](https://uicontext.com/docs/components/button.md) (`button`): A button, and a link that looks like one, in every tone and three sizes.
- [Toggle](https://uicontext.com/docs/components/toggle.md) (`toggle`): A button that stays pressed, such as Bold or Pin.
- [Toggle Group](https://uicontext.com/docs/components/toggle-group.md) (`toggle-group`): Buttons that stay pressed and share one value, such as text styles.
- [Input](https://uicontext.com/docs/components/input.md) (`input`): Text inputs, selects and textareas in a labeled field with a hint and an error, and their styles for controls you lay out yourself.
- [Status](https://uicontext.com/docs/components/status.md) (`status`): Status badges and tags for runs and records.
- [Glyphs](https://uicontext.com/docs/components/glyphs.md) (`glyphs`): Small marks for status, priority, color and people.
