Care Team Presence
StablePresence with clinical semantics: in session, on call, signed out to whom — and who else is in this chart right now.
Why it exists
A green dot meaning "online" is worse than useless on a ward, because the two states that matter most both look identical to it.
A therapist who is in session is at their desk, is online, and must not be interrupted — interrupting a group session reaches eight patients rather than one. A hospitalist who is signed out is at their desk, is online, and is the wrong person to page; the right person is named in a handover the dot does not know about. The second half of the component answers the question a PDF on a shared drive answers today: who covers this patient at 02:00 on a Sunday, and until when. And the third — chart co-presence — is the only presence signal here that appears without being asked for, because the timing is the whole value: told at save, a second note in the same encounter is a merge problem with somebody else's unsigned draft; told before you type, it is a choice between three reasonable options.
- CareTeam
- participant[].period becomes a coverage window; a participant with no period is on the team but is not the answer to who is responsible now, and is dropped.
Playground
Change a prop and watch the component and its code change with it.
- onContact — nothing yet
import { CareTeamPresence } from "@/components/zoblocks/care-team-presence";export default function Example() { return ( <CareTeamPresence presence={vance} now="2026-08-24T02:30:00+05:30" compact={false} /> );}Examples
The cases worth copying. Open one in StackBlitz to run it with its dependencies installed.
DatacareTeamNightCoveragecareTeamCoverageGappractitionerSigner
In session is not away, and signed out is not offline
careTeamNightCoverageBoth of these people are at a computer and both would be a green dot. One must not be interrupted; the other is simply the wrong person, and the right one is named on the next line.
import { PresenceChip } from "@/components/zoblocks/care-team-presence";import { boateng, marsh, vance } from "./_shared/care-team";export default function NotAGreenDot() { return ( <div className="grid w-full max-w-[420px] gap-3.5"> <PresenceChip presence={{ clinician: marsh, state: "in-session", until: "15:50" }} /> <PresenceChip presence={{ clinician: vance, state: "signed-out", coveredBy: boateng, until: "07:00", }} /> </div> );}A hole in the rota is drawn as a hole
careTeamCoverageGapNothing covers 07:00–09:00. The resolver returns null rather than the nearest window, because filling a gap with a plausible name is how a page goes to somebody who is asleep.
import { CoverageCard, coverageFromCareTeam } from "@/components/zoblocks/care-team-presence";import { careTeamCoverageGap } from "./_shared/care-team";const windows = coverageFromCareTeam(careTeamCoverageGap.participant ?? []);export default function CoverageGap() { // 08:00 falls between the two windows. // → "Nobody is covering right now. Escalate to the on-call supervisor." return ( <div className="w-full max-w-[320px]"> <CoverageCard windows={windows} now="2026-08-24T08:00:00+05:30" /> </div> );}Do not disturb is a redirect, not a locked door
practitionerSignerA clinician in a group session with cover offers the cover. The same clinician with nobody covering offers an override — a second, deliberate action the host logs. Interrupting a group reaches eight patients rather than one, and the default has to reflect that.
import { PresenceChip, resolveEscalation, type Presence,} from "@/components/zoblocks/care-team-presence";import { marsh, okafor } from "./_shared/care-team";const withCover: Presence = { clinician: marsh, state: "in-group", coveredBy: okafor };const withoutCover: Presence = { clinician: marsh, state: "in-group" };export default function Escalation() { // → { kind: "covering", clinician: okafor, instead: marsh, reason: "L. Marsh, LCSW is in group" } const covered = resolveEscalation(withCover); // → { kind: "override-required", … } const uncovered = resolveEscalation(withoutCover); return ( <div className="grid w-full max-w-[420px] gap-3.5"> <div className="grid gap-1"> <PresenceChip presence={withCover} /> <span className="text-xs opacity-60"> {covered.kind}: with cover named, the chip offers the cover. </span> </div> <div className="grid gap-1"> <PresenceChip presence={withoutCover} /> <span className="text-xs opacity-60"> {uncovered.kind}: with nobody covering, it offers an override instead. </span> </div> </div> );}Told before you type, not at save
careTeamNightCoverageA second note in the same encounter is a merge problem once both exist. Announced before the first keystroke, it is a choice between three reasonable options — and none of them is highlighted, because which is right depends on facts the component does not have.
import { useState } from "react";import { ChartCoPresence } from "@/components/zoblocks/care-team-presence";import { marsh, serverTime } from "./_shared/care-team";export default function CoPresence() { const [last, setLast] = useState<string | null>(null); const openReadOnly = () => setLast("Opened their draft, read-only."); const requestHandoff = () => setLast("Requested a handoff."); const startAddendum = () => setLast("Started a separate addendum."); return ( <div className="grid w-full max-w-[420px] gap-2.5"> <ChartCoPresence others={[ { clinician: marsh, activity: "documenting", since: "2026-08-24T09:12:00+05:30", target: "Progress note", unsigned: true, }, ]} now={serverTime} onOpenTheirs={openReadOnly} onRequestHandoff={requestHandoff} onSeparateAddendum={startAddendum} /> <span className="text-xs opacity-60"> {last ?? "Pick one — none is highlighted, because which is right depends on facts this component does not have."} </span> </div> );}Variants
Every variant is the same accessibility contract and the same keyboard model. Pick by what the surface needs.
Default
Avatar, name, role and state, with the redirect on its own line.
compact=false
Compact
Avatar only, for a co-presence stack. The name stays in the accessible label rather than disappearing.
compact=true
Installation
npx @zoblocks/cli add care-team-presenceFirst install? Run zoblocks init once to say where your @/ alias points. The source is copied into your repository, along with anything it depends on.
clsxtailwind-mergeUsage
Props are the FHIR resource.
import { CoverageCard, PresenceChip,} from "@/components/zoblocks/care-team-presence";import "@/styles/zoblocks-presence.css";<PresenceChip presence={{ clinician: { id: "pr-4", display: "A. Vance, MD", role: "Attending" }, state: "signed-out", coveredBy: { id: "pr-1", display: "T. Boateng, MD", role: "Night attending" }, until: "07:00", }} onContact={(target) => page(target)}/><CoverageCard windows={rota} now={serverTime} onPage={page} />Use it when
- Beside a clinician's name anywhere the reader might be about to contact them — a care team panel, a message composer, a chart header.
- With CoverageCard on any surface where somebody might need to escalate out of hours. That is the question the shared-drive PDF answers today.
- With ChartCoPresence above the editor rather than inside it, so the warning arrives before the first keystroke.
- Compact, inside a co-presence stack, where the count matters more than any one face.
Avoid it when
- As a productivity signal. "Who is online" is a management question and this is a clinical one; the states exist to route contact, not to report attendance.
- Without a role on the clinician. A name with no role is not actionable, and the component will render it but the reader still cannot use it.
- As the only escalation path. It names who to reach; the page itself, and the audit entry for an override, belong to the host.
API
Every prop is typed. Props not listed are forwarded to the root element.
PresenceChip
4 props · the front doorpresencerequiredPresence- Default
— - The person and their current state — available, in session, signed out, off shift — with whoever is covering for them.
compactboolean- Default
false - Avatar only, for a co-presence stack. The name stays in the label.
nowstring- Default
— - ISO 8601, supplied by the host. Needed for the degraded state's age.
onContact((target: EscalationTarget) => void)- Default
— - Contact this person. Routed through `resolveEscalation`, so a do-not-disturb clinician offers their cover instead and an override is a second, deliberate action.
CoverageCard
4 propsnowrequiredstring- Default
— - ISO 8601, supplied by the host. The gap this component exists to find is a window in time.
windowsrequiredreadonly CoverageWindow[]- Default
— - Who is covering, and when. Overlaps and gaps are both drawn: a gap in coverage is the fact a reader is looking for.
backupClinician- Default
— - Who to reach when the primary does not answer. Rendered before it is needed rather than found during an escalation.
onPage((clinician: Clinician) => void)- Default
— - Fired when the reader pages somebody. The component never contacts anyone itself.
ChartCoPresence
5 propsothersrequiredreadonly ChartPresence[]- Default
— - Who else has this chart open right now. Two people writing the same note is a merge nobody wins.
nowstring- Default
— - ISO 8601, supplied by the host. Adds "started … ago" to the conflict notice; omitted, the notice drops that clause.
onOpenTheirs((other: ChartPresence) => void)- Default
— - Opens the other person's draft, read-only.
onRequestHandoff((other: ChartPresence) => void)- Default
— - Fired when the reader asks the current editor to hand over.
onSeparateAddendum((other: ChartPresence) => void)- Default
— - Fired when the reader chooses to write their own addendum instead of waiting. The honest alternative to a silent overwrite.
Accessibility
Screen readers and semantics
- The ring is a shape before it is a colour. Nine states will not fit in nine hues on a 28px avatar — three would be indistinguishable to a reader with a common colour deficiency and all nine at arm's length on a ward monitor. Solid, blocked, doubled, halved, dashed, dotted or absent carries the state; the hue repeats it.
- The whole presence is one spoken statement. "A. Vance, MD. Attending. Signed out. Covered by T. Boateng, MD, night attending." Name, role, state, redirect — a reader who stops after the third part has enough to decide whether to make contact, and one who hears the fourth knows where to go instead.
- The role is never omitted. "Dr Vance" is not actionable and "Attending, night coverage until 07:00" is. The difference is whether a reader knows they have found the right person, which is the entire job of this component.
- The conflict notice is polite and throttled. One announcement per ten seconds. A ward round where six people open the same chart would otherwise produce six interruptions in as many seconds, and a screen-reader user would lose their place each time — this component exists to prevent an interruption, not to become one.
- A rota gap is an alert, not an empty state. role="alert" with the escalation named in the accessible label. Every other state here is deliberately quiet; nobody being responsible for a patient at 02:00 is the one thing that should stop a reader.
- The one animation is a slow breath, and it respects the preference. The crisis-line ring fades over 2.4 seconds rather than flashing. A crisis line is staffed for a whole shift, and a blinking ring in somebody's peripheral vision for eight hours is an accessibility problem. prefers-reduced-motion stops it entirely.
Conformance · WCAG 2.2 AA · 8 of 8 pass
| Criterion | Status | How | Evidence |
|---|---|---|---|
| 1.4.1Use of colour | pass | Every state has a ring geometry and a state word, and both reach the accessible name. A test asserts the nine states produce nine distinct ring shapes, so two states can never collapse into one hue. | care-team-presence.test.tsx |
| 4.1.2Name, role, value | pass | role="group" carrying the composed statement, with the visual content aria-hidden so a screen reader gets one sentence rather than a scattering of fragments. | care-team-presence.test.tsx |
| 4.1.3Status messages | pass | The co-presence conflict is aria-live="polite" and throttled to one announcement per ten seconds; the rota gap is role="alert" because nobody being responsible is the one state here that should interrupt. | care-team-presence.test.tsx |
| 2.5.8Target size (minimum) | pass | Every button — contact, page, and the three conflict actions — has a 28px minimum block size, above the 24px floor. | care-team-presence.test.tsx |
| 2.2.2Pause, stop, hide | pass | The crisis-line ring is the only animation, it is a 2.4s opacity breath rather than a flash, and prefers-reduced-motion removes it. Nothing else moves. | care-team-presence.test.tsx |
| 2.1.1Keyboard | pass | Every affordance is a native button. The component manages no focus and traps none. | care-team-presence.test.tsx |
| 1.4.11Non-text contrast | pass | The rings and the button borders draw from gated status tokens; the ring is also 2px or wider so the geometry survives at the contrast floor. | contrast.gate |
| 1.3.1Info and relationships | pass | The redirect, the cover and the degraded age are text in the accessible name rather than position or colour, so a reader who cannot see the layout still gets the relationship. | care-team-presence.test.tsx |
Clinical
Four of the nine states exist because behavioral health needs them and no generic presence system has them: in session, in group, on the crisis line, and assigned therapist. Interrupting a group reaches eight patients rather than one, and the assigned therapist is the person a disclosure decision routes through.
- Industries
- healthcare, behavioral-health
- Workflows
- care-coordination, documentation, scheduling
- Terminology
- FHIR
- Permissions
- careteam.read
- Audit
- Emits no AuditEvent
Protected health information
Handles no PHI
Renders clinicians rather than patients. Chart co-presence implies which chart is open, so it should not be rendered outside the chart it describes.
Source
Exactly what lands in your repository, read from the published registry so it can never drift from what the CLI installs.
Show sourceHide source457 lines
/** * CareTeamPresence — presence with clinical semantics. * * <PresenceChip presence={marsh} now={serverTime} /> * <CoverageCard windows={rota} now={serverTime} onPage={page} /> * <ChartCoPresence others={inThisChart} now={serverTime} /> * * Not "online". A therapist who is in session is at their desk and must not be * interrupted; a hospitalist who is signed out is online and is the wrong * person to page. The ring carries the state as a shape rather than a hue, * because nine colours on a 24px avatar is unreadable before it is * inaccessible. * * `ChartCoPresence` is the one presence signal that appears without being * asked for, and the reason is timing: told at save, a second note in the same * encounter is a merge problem; told before you type, it is a choice between * three reasonable options. * * Transport-agnostic. The host subscribes once and passes presence down. * * Styling lives in `styles/zoblocks-presence.css`, installed alongside. */import * as React from "react";import { cn } from "@/lib/utils";import { ACTIVITY_LABEL, PRESENCE_LABEL, PRESENCE_RING, clockTime, conflictsWith, describeConflict, describeElapsedShort, describePresence, isDoNotDisturb, resolveCoverage, resolveEscalation, type ChartPresence, type Clinician, type CoverageWindow, type EscalationTarget, type Presence,} from "@/lib/zoblocks-presence";export { ACTIVITY_LABEL, DO_NOT_DISTURB, PRESENCE_LABEL, PRESENCE_RING, REDIRECTS, clockTime, conflictsWith, coverageFromCareTeam, describeConflict, describeElapsedShort, describePresence, isDoNotDisturb, resolveCoverage, resolveEscalation, type Activity, type ChartPresence, type Clinician, type Coverage, type CoverageWindow, type EscalationTarget, type Presence, type PresenceState,} from "@/lib/zoblocks-presence";/** * Two letters, from the display name. Never a photograph. * * Built by slicing rather than by indexing. The indexed version needed two * `?? ""` fallbacks that no input could reach — `split` on a trimmed string * never yields an empty word — and an unreachable fallback is a branch no * honest test can cover. */function initials(display: string): string { const letters = display .replace(/,.*$/, "") .trim() .split(/\s+/) .filter(Boolean) .map((word) => word.charAt(0).toUpperCase()); // First and last for a full name; whatever there is for one word or none. return (letters.length > 1 ? [...letters.slice(0, 1), ...letters.slice(-1)] : letters).join("");}/* ------------------------------------------------------------------ *//* One person *//* ------------------------------------------------------------------ */export interface PresenceChipProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "children"> { /** * The person and their current state — available, in session, signed out, off shift — with * whoever is covering for them. */ presence: Presence; /** ISO 8601, supplied by the host. Needed for the degraded state's age. */ now?: string; /** Avatar only, for a co-presence stack. The name stays in the label. */ compact?: boolean; /** * Contact this person. * * Routed through `resolveEscalation`, so a do-not-disturb clinician offers * their cover instead and an override is a second, deliberate action. */ onContact?: (target: EscalationTarget) => void;}export const PresenceChip = React.forwardRef<HTMLDivElement, PresenceChipProps>( function PresenceChip({ presence, now, compact = false, onContact, className, ...rest }, ref) { const { clinician, state } = presence; const escalation = resolveEscalation(presence); const dnd = isDoNotDisturb(state); return ( <div {...rest} ref={ref} className={cn("zb-presence", className)} data-zb-presence="" data-zb-state={state} data-zb-dnd={dnd ? "" : undefined} data-zb-compact={compact ? "" : undefined} role="group" aria-label={describePresence(presence, now)} > <span className="zb-presence__avatar" data-zb-ring={PRESENCE_RING[state]} aria-hidden="true" > {initials(clinician.display)} </span> {compact ? null : ( <span className="zb-presence__body" aria-hidden="true"> <span className="zb-presence__name"> {clinician.display} {clinician.assignedTherapist ? ( <span className="zb-presence__assigned">assigned therapist</span> ) : null} </span> {/* The role is never omitted. "Dr Vance" is not actionable; "Attending, night coverage until 07:00" is, and the difference is whether a reader knows they have found the right person. */} <span className="zb-presence__meta"> {clinician.role ? <span className="zb-presence__role">{clinician.role}</span> : null} <span className="zb-presence__state">{PRESENCE_LABEL[state]}</span> {presence.detail ? ( <span className="zb-presence__detail">{presence.detail}</span> ) : null} {presence.until ? ( <span className="zb-presence__until">until {clockTime(presence.until, now)}</span> ) : null} </span> {presence.coveredBy ? ( <span className="zb-presence__cover"> → covered by {presence.coveredBy.display} {presence.until ? ` until ${clockTime(presence.until, now)}` : ""} </span> ) : null} {/* A degraded channel says how stale it is. A dot that froze three hours ago and still looks live is the failure this state exists to prevent. */} {state === "degraded" && now && presence.since ? ( <span className="zb-presence__degraded"> Last seen {describeElapsedShort(Date.parse(now) - Date.parse(presence.since))} ago · channel lost </span> ) : null} </span> )} {onContact ? ( <button type="button" className="zb-presence__contact" data-zb-escalation={escalation.kind} onClick={() => onContact(escalation)} > {escalation.kind === "covering" ? `Page ${escalation.clinician.display}` : escalation.kind === "override-required" ? "Interrupt…" : "Page"} </button> ) : null} </div> ); },);/* ------------------------------------------------------------------ *//* Coverage *//* ------------------------------------------------------------------ */export interface CoverageCardProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "children"> { /** * Who is covering, and when. Overlaps and gaps are both drawn: a gap in coverage is the fact * a reader is looking for. */ windows: readonly CoverageWindow[]; /** ISO 8601, supplied by the host. The gap this component exists to find is a window in time. */ now: string; /** * Who to reach when the primary does not answer. Rendered before it is needed rather than * found during an escalation. */ backup?: Clinician; /** Fired when the reader pages somebody. The component never contacts anyone itself. */ onPage?: (clinician: Clinician) => void;}/** * Who is responsible right now, and until when. * * The question a PDF on a shared drive answers today. A gap in the rota is * rendered as a gap rather than filled with the nearest plausible name — * paging somebody who is asleep because the component rounded to the closest * window is worse than saying nobody is covering. */export const CoverageCard = React.forwardRef<HTMLDivElement, CoverageCardProps>( function CoverageCard({ windows, now, backup, onPage, className, ...rest }, ref) { const coverage = resolveCoverage(windows, now, backup); if (!coverage) { return ( <div {...rest} ref={ref} className={cn("zb-coverage zb-coverage--gap", className)} data-zb-coverage="gap" role="alert" aria-label="Nobody is covering this patient right now. Escalate to the on-call supervisor." > <span className="zb-coverage__title" aria-hidden="true"> Nobody is covering right now </span> <span className="zb-coverage__detail" aria-hidden="true"> No rota window covers this moment. Escalate to the on-call supervisor. </span> </div> ); } // Each clause is a sentence and starts like one. Joining "Night attending" // and "until 09:00" with a full stop and leaving the second lower-case // gives a screen reader nothing to punctuate. const label = [ `Responsible right now: ${coverage.responsible.display}`, coverage.responsible.role, coverage.reason, `Until ${clockTime(coverage.until, now)}`, coverage.backup ? `Back-up ${coverage.backup.display}` : undefined, ] .filter(Boolean) .join(". "); return ( <div {...rest} ref={ref} className={cn("zb-coverage", className)} data-zb-coverage="covered" role="group" aria-label={`${label}.`} > <span className="zb-coverage__title" aria-hidden="true"> Responsible right now </span> <div className="zb-coverage__who" aria-hidden="true"> <span className="zb-presence__avatar" data-zb-ring="solid"> {initials(coverage.responsible.display)} </span> <span> <span className="zb-coverage__name">{coverage.responsible.display}</span> <span className="zb-coverage__meta"> {coverage.responsible.role ? `${coverage.responsible.role} · ` : ""} {coverage.reason ?? "Covering"} {` · until ${clockTime(coverage.until, now)}`} </span> </span> </div> {coverage.backup ? ( <span className="zb-coverage__backup" aria-hidden="true"> Back-up: {coverage.backup.display} {coverage.backup.role ? `, ${coverage.backup.role}` : ""} {coverage.backup.contact ? ` · ${coverage.backup.contact}` : ""} </span> ) : null} {onPage ? ( <button type="button" className="zb-coverage__page" onClick={() => onPage(coverage.responsible)} > Page {coverage.responsible.display} </button> ) : null} </div> ); },);/* ------------------------------------------------------------------ *//* Co-presence *//* ------------------------------------------------------------------ */export interface ChartCoPresenceProps extends Omit< React.HTMLAttributes<HTMLDivElement>, "children"> { /** * Who else has this chart open right now. Two people writing the same note is a merge nobody * wins. */ others: readonly ChartPresence[]; /** ISO 8601, supplied by the host. Adds "started … ago" to the conflict notice; omitted, the notice drops that clause. */ now?: string; /** Opens the other person's draft, read-only. */ onOpenTheirs?: (other: ChartPresence) => void; /** Fired when the reader asks the current editor to hand over. */ onRequestHandoff?: (other: ChartPresence) => void; /** * Fired when the reader chooses to write their own addendum instead of waiting. The honest * alternative to a silent overwrite. */ onSeparateAddendum?: (other: ChartPresence) => void;}/** * Who else is in this chart, and what they are doing. * * The conflict notice is `aria-live="polite"` and throttled: a stream of * arrival announcements is an interruption, and this component's whole purpose * is to prevent one kind of interruption rather than introduce another. */export const ChartCoPresence = React.forwardRef<HTMLDivElement, ChartCoPresenceProps>( function ChartCoPresence( { others, now, onOpenTheirs, onRequestHandoff, onSeparateAddendum, className, ...rest }, ref, ) { const conflict = conflictsWith(others); /* * One announcement per ten seconds. * * Without the throttle, a ward round where six people open the same chart * produces six interruptions in as many seconds — and a screen-reader user * loses whatever they were reading each time. */ const [announced, setAnnounced] = React.useState<string>(""); // Negative infinity rather than 0: the first conflict on a freshly-mounted // chart is always worth saying immediately, and `performance.now()` starts // at an arbitrary point that would otherwise decide it. const lastAt = React.useRef(Number.NEGATIVE_INFINITY); const message = conflict ? describeConflict(conflict, now) : ""; React.useEffect(() => { if (!message) { setAnnounced(""); return; } const elapsed = performance.now() - lastAt.current; if (elapsed >= 10_000) { lastAt.current = performance.now(); setAnnounced(message); return; } const timer = setTimeout(() => { lastAt.current = performance.now(); setAnnounced(message); }, 10_000 - elapsed); return () => clearTimeout(timer); }, [message]); if (!others.length) return null; return ( <div {...rest} ref={ref} className={cn("zb-copresence", className)} data-zb-copresence="" data-zb-conflict={conflict ? "" : undefined} > <span className="zb-copresence__stack" aria-hidden="true"> {others.slice(0, 4).map((other) => ( <span key={other.clinician.id} className="zb-presence__avatar" data-zb-ring="solid" data-zb-activity={other.activity} title={`${other.clinician.display} — ${ACTIVITY_LABEL[other.activity]}`} > {initials(other.clinician.display)} </span> ))} {others.length > 4 ? ( <span className="zb-copresence__more">+{others.length - 4}</span> ) : null} </span> {conflict ? ( <div className="zb-copresence__conflict"> <p className="zb-copresence__message" aria-hidden="true"> {describeConflict(conflict, now)} </p> {/* Three options, none of them "carry on anyway". Told before you type, this is a choice; told at save, it is a merge problem with somebody else's unsigned note. */} <div className="zb-copresence__actions"> {onOpenTheirs ? ( <button type="button" onClick={() => onOpenTheirs(conflict)}> Open theirs read-only </button> ) : null} {onRequestHandoff ? ( <button type="button" onClick={() => onRequestHandoff(conflict)}> Request handoff </button> ) : null} {onSeparateAddendum ? ( <button type="button" onClick={() => onSeparateAddendum(conflict)}> Create a separate addendum </button> ) : null} </div> </div> ) : null} {/* Polite and throttled. The component exists to prevent an interruption, not to become one. */} <p className="zb-presence__sr" aria-live="polite"> {announced} </p> </div> ); },);