Skip to content

Allergy Chip

Stable

The chip that refuses to conflate how bad the last reaction was with how bad the next one could be.

15 states4 props27.9 KB installedsince 0.4.0
npx @zoblocks/cli add allergy-chip
View sourceRegistry JSON ↗

Why it exists

AllergyIntolerance carries two severity-shaped fields that mean opposite things.

`criticality` is a clinician's judgement of the risk of a future life-threatening reaction; `reaction.severity` describes how bad a past one was. A patient whose only documented reaction was mild urticaria can still be criticality high — that is the entire reason the field exists — and nearly every implementation renders one and drops the other, keeping the past. The second failure is subtler and more common: no known allergies and nobody asked are shown the same way, and an empty allergy list beside a prescribing button is an assertion the software has not earned. Both failures are structural rather than cosmetic, so both get shapes: the two fields render as different kinds of thing, and the two empty states are different components that look nothing alike.

AllergyIntolerance
type, category, criticality, verificationStatus, reaction[].manifestation and severity, onset, lastOccurrence and asserter. The no-known-allergy SNOMED codes are read as a positive assertion with provenance rather than as an allergy to nothing.

Playground

Change a prop and watch the component and its code change with it.

Design language
Props
Density
Events
  • onOpenDetail — nothing yet
Playground.tsx
import { AllergyChip } from "@/components/zoblocks/allergy-chip";export default function Example() {  return (    <AllergyChip density="default" />  );}

Examples

The cases worth copying. Open one in StackBlitz to run it with its dependencies installed.

DataallergyHighRiskallergyModerateallergyUnconfirmedallergyRefutedallergyList

Two rows, one manifestation, opposite consequences

allergyHighRisk

Both patients reacted with mild urticaria. Only the criticality field separates them, and it is the field most implementations drop — so the two rows render as identical warnings and a prescriber treats them the same.

The two absences that are not the same fact

allergyList

A no-known assertion is a positive clinical finding with an author and a date, and it is safe to prescribe against. An unrecorded status is neither. Supply an assertion without its author and the component renders the second, because that is what an unattributed assertion is worth.

An intolerance is not a weak allergy

allergyModerate

Akathisia on aripiprazole and sedation on quetiapine dominate psychotropic histories and are the entries most often lost, because somebody decided they were not real allergies. The kind is rendered as its own class.

A refuted entry stays in the record

allergyRefuted

Struck through and dimmed rather than deleted. A refuted allergy that vanishes gets re-reported at the next intake, and the rechallenge that disproved it is the most useful thing in the chart.

Variants

Every variant is the same accessibility contract and the same keyboard model. Pick by what the surface needs.

Default

Substance, criticality, verification and the worst past reaction.

density="default"

Compact

For an allergy banner across the top of a chart, where vertical space is the constraint.

density="compact"

Installation

Terminal
npx @zoblocks/cli add allergy-chip

First install? Run zoblocks init once to say where your @/ alias points. The source is copied into your repository, along with anything it depends on.

Dependenciesclsxtailwind-merge

Usage

Props are the FHIR resource.

usage.tsx
import { AllergyChip, AllergyList, fromAllergyIntolerance } from "@/components/zoblocks/allergy-chip";import "@/styles/zoblocks-allergy.css";<AllergyList  records={records}  noneKnown={{ asserter: "R. Okafor, RN", assertedAt: "14 Aug 2026" }}  onAsk={openIntake}/>

Use it when

  • In an allergy banner, a pre-prescribe check, a medication administration screen and intake reconciliation — the four places the criticality field decides what happens next.
  • Through AllergyList rather than mapping AllergyChip yourself, so the two empty states are handled rather than falling through to a blank.
  • With onAsk wired on any screen that can prescribe, so the unrecorded state is a gate rather than a note.
  • For psychotropic histories, where intolerance rather than allergy dominates — akathisia on aripiprazole, sedation on quetiapine — and where those entries are the ones most often lost.

Avoid it when

  • As a way to change a criticality. It is a documented clinical act with an author, not a click on a chip.
  • With criticality omitted when the record has one. Rendering only the past reaction is the exact failure the component was built to stop.
  • For a deduplicated view of several source systems. Three penicillin entries that disagree should look like three entries that disagree.

API

Every prop is typed. Props not listed are forwarded to the root element.

AllergyChip

4 props · the front door
recordrequired
AllergyRecord
Default—
The AllergyIntolerance, already adapted. Carries `criticality` and `reaction.severity` separately, because they mean opposite things and merging them is the defect this component exists to prevent.
density
'compact' | 'default'
Default"default"
Row height and type scale. Inherited from the nearest density provider when omitted.
expandClass
ClassExpander
Default—
Expands a substance into the class it implicates. Injected, never bundled.
onOpenDetail
((record: AllergyRecord) => void)
Default—
Opens the reaction history, asserter and source.

AllergyList

7 props
askLabel
string
Default"Ask and record"
What to render when nobody has asked. "No known allergies" is a clinical assertion somebody made; an empty list is not, and the two must not look alike.
density
'compact' | 'default'
Default"default"
Row height and type scale. Inherited from the nearest density provider when omitted.
expandClass
ClassExpander
Default—
Not yet documented.
noneKnown
Partial<NoKnownAllergies>
Default—
A no-known-allergies assertion. Requires both an asserter and a date. Supplying one without the other renders not-asked, because an unattributed assertion of absence is not an assertion — and it is the one that gets prescribed against.
onAsk
(() => void)
Default—
Rendered inside the not-asked state. "Ask and record", typically.
onOpenDetail
((record: AllergyRecord) => void)
Default—
Not yet documented.
records
readonly AllergyRecord[]
Default—
The allergies, in the order they should be read. An empty array and a `null` mean different things — see `askLabel`.

Accessibility

Screen readers and semantics

  • The name reads kind, substance, criticality, verification — in that order. Criticality before verification because it decides whether to prescribe; verification last because it decides how much to trust the rest. The past reaction comes after both, since leading with it is the mistake the component exists to correct.
  • Criticality carries a shape. It routes through ClinicalStatus, so high criticality is a filled triangle as well as a red chip. A red chip is never the only cue, and this is the one component where a missed cue is a prescription.
  • The two empty states differ in shape, not only in colour. The asserted state is a solid green panel; the unrecorded state is a dashed amber one. A reader scanning a chart has to tell them apart without reading either, and the dash survives greyscale, forced colours and the ward printer.
  • A refuted entry stays readable. Struck through and dimmed rather than removed. A refuted allergy that vanishes gets re-reported at the next intake, and the rechallenge that disproved it is the most useful thing in the record — so it is dimmed to 0.75 rather than to the point of illegibility.
  • Inert unless there is a history to open. role="group" with a label by default. The chip is never where a criticality is changed — that is a documented clinical act, not a click — so the only interaction it offers is reading more.

Conformance · WCAG 2.2 AA · 7 of 8 pass

CriterionStatusHowEvidence
1.3.1Info and relationshipspassOne labelled group per record, with the four facts composed into a single name in a fixed order. The relationship between the two severity-shaped fields is in the sentence rather than in visual adjacency.allergy-chip.test.tsx
1.4.1Use of colourpassCriticality routes through ClinicalStatus so it carries a shape and a word. The two empty states differ by border style as well as hue, and a test asserts the dash survives.allergy-chip.test.tsx
4.1.2Name, role, valuepassrole="group" with a composed label; a real button only when onOpenDetail is supplied. The ask affordance in the unrecorded state is a native button.allergy-chip.test.tsx
2.1.1KeyboardpassBoth affordances — open detail and ask — are native buttons, reached and activated by keyboard with no handler of the component's own.allergy-chip.test.tsx
2.5.8Target sizepassThe chip and the ask button both hold a 24px minimum at both densities.allergy-chip.test.tsx
1.4.10ReflowpassThe substance wraps at word boundaries rather than truncating mid-word, and the class expansion takes its own line below 480px.allergy-chip.test.tsx
1.4.12Text spacingpassA three-row grid with no fixed heights; increased line-height and letter-spacing grow the card rather than clipping it.allergy-chip.test.tsx
2.2.1Timing adjustablen/aNo timing of any kind.—

Clinical

The allergy banner and the pre-prescribe check. Also the reconciliation surface at intake, which is where a no-known assertion gets its author and date — and where, without them, a prescriber later reads an empty list as a cleared one.

Industries
healthcare, behavioral-health
Workflows
intake, medication, documentation, care-coordination
Terminology
SNOMED CT, RxNorm, FHIR
Permissions
allergy.read
Audit
Emits no AuditEvent

Protected health information

Handles PHI

Renders substances, reactions and the clinician who asserted them. The unrecorded state is deliberately loud rather than discreet: an absence here is a safety signal, not a privacy one.

Source

Exactly what lands in your repository, read from the published registry so it can never drift from what the CLI installs.

Show source312 lines
allergy-chip.tsx
/** * AllergyChip — the chip that refuses to conflate how bad the last reaction * was with how bad the next one could be. * *     <AllergyChip record={penicillin} /> *     <AllergyList records={records} noneKnown={assertion} /> * * Substance first and at full weight. Criticality — future risk — as the * primary signal. The worst past reaction as secondary text, never as the * headline, because leading with it is the mistake the component exists to * correct: a patient whose only documented reaction was mild urticaria can * still be high criticality, and that is the whole reason the field exists. * * `AllergyList` carries the other half. "No known allergies" is a positive * clinical finding with an author and a date; "nobody asked" is an absence. * They look nothing alike here, and an assertion missing its author degrades * to the second — because an empty list beside a prescribing button is a claim * the software has not earned. * * Styling lives in `styles/zoblocks-allergy.css`, installed alongside. */import * as React from "react";import { cn } from "@/lib/utils";import { ClinicalStatus } from "@/components/zoblocks/clinical-status";import {  KIND_LABEL,  NOT_ASKED_SENTENCE,  SEVERITY_LABEL,  VERIFICATION_LABEL,  describeAllergy,  describeNoKnown,  isActive,  resolveListState,  worstReaction,  type AllergyRecord,  type ClassExpander,  type Criticality,  type NoKnownAllergies,} from "@/lib/zoblocks-allergy";export {  CRITICALITY_LABEL,  INACTIVE_VERIFICATIONS,  KIND_LABEL,  NOT_ASKED_SENTENCE,  NO_KNOWN_ALLERGY_CODES,  SEVERITY_LABEL,  VERIFICATION_LABEL,  describeAllergy,  describeNoKnown,  fromAllergyIntolerance,  isActive,  noKnownFromFHIR,  resolveListState,  toKind,  toVerification,  worstReaction,  type AllergyKind,  type AllergyListState,  type AllergyRecord,  type ClassExpander,  type Criticality,  type NoKnownAllergies,  type Reaction,  type ReactionSeverity,  type Verification,} from "@/lib/zoblocks-allergy";/** Criticality maps onto the shared vocabulary so the shape agrees library-wide. */const CRITICALITY_STEP: Record<Criticality, string> = {  high: "critical",  low: "moderate",  "unable-to-assess": "not-assessed",};export interface AllergyChipProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "children"> {  /**   * The AllergyIntolerance, already adapted. Carries `criticality` and `reaction.severity`   * separately, because they mean opposite things and merging them is the defect this   * component exists to prevent.   */  record: AllergyRecord;  /** Row height and type scale. Inherited from the nearest density provider when omitted. */  density?: "compact" | "default";  /** Expands a substance into the class it implicates. Injected, never bundled. */  expandClass?: ClassExpander;  /** Opens the reaction history, asserter and source. */  onOpenDetail?: (record: AllergyRecord) => void;}export const AllergyChip = React.forwardRef<HTMLElement, AllergyChipProps>(function AllergyChip(  { record, density = "default", expandClass, onOpenDetail, className, ...rest },  ref,) {  const worst = worstReaction(record);  const expansion = expandClass?.(record.substance) ?? null;  const active = isActive(record.verification);  const shell = {    className: cn("zb-allergy", className),    "data-zb-allergy": "",    "data-zb-kind": record.kind,    "data-zb-criticality": record.criticality ?? undefined,    "data-zb-verification": record.verification ?? undefined,    "data-zb-density": density,    // Refuted and entered-in-error are not warnings any more, and the record    // has to keep saying so rather than being deleted — a refuted allergy that    // vanishes gets re-reported at the next intake.    "data-zb-inactive": active ? undefined : "",    "aria-label": describeAllergy(record),    ...rest,  };  const content = (    <>      <span className="zb-allergy__head" aria-hidden="true">        <span className="zb-allergy__substance">{record.substance}</span>        {record.kind !== "allergy" ? (          <span className="zb-allergy__kind">{KIND_LABEL[record.kind]}</span>        ) : null}        {expansion ? (          <span className="zb-allergy__class">            Class: {expansion.label} · {expansion.count} members          </span>        ) : null}      </span>      <span className="zb-allergy__signals" aria-hidden="true">        {/*          Future risk, as the primary signal and with a shape.          The two fields are rendered as different things on purpose: a chip          for what could happen, plain text for what did.        */}        {record.criticality ? (          <ClinicalStatus            scale="criticality"            step={CRITICALITY_STEP[record.criticality]}            density="compact"            aria-hidden="true"          />        ) : null}        {record.verification ? (          <span className="zb-allergy__verification">            {VERIFICATION_LABEL[record.verification]}          </span>        ) : null}      </span>      {/*        The past, as secondary text. Never the headline.        "Urticaria — mild, 1998" beside "High criticality" reads as a        contradiction only until you know the two fields answer different        questions, which is why both are always present when both are known.      */}      <span className="zb-allergy__past" aria-hidden="true">        {worst ? (          <>            <span className="zb-allergy__manifestation">{worst.manifestation}</span>            {worst.severity ? (              <span className="zb-allergy__severity" data-zb-severity={worst.severity}>                {SEVERITY_LABEL[worst.severity]}              </span>            ) : null}            {worst.onset ? <span className="zb-allergy__when">{worst.onset}</span> : null}            {worst.note ? <span className="zb-allergy__when">{worst.note}</span> : null}          </>        ) : record.criticality ? (          <span className="zb-allergy__manifestation" data-zb-none="">            No reaction recorded          </span>        ) : null}        {record.note ? <span className="zb-allergy__when">{record.note}</span> : null}      </span>    </>  );  if (onOpenDetail) {    return (      <button        {...(shell as React.ButtonHTMLAttributes<HTMLButtonElement>)}        ref={ref as React.Ref<HTMLButtonElement>}        type="button"        onClick={() => onOpenDetail(record)}      >        {content}      </button>    );  }  return (    <div      {...(shell as React.HTMLAttributes<HTMLDivElement>)}      ref={ref as React.Ref<HTMLDivElement>}      role="group"    >      {content}    </div>  );});/* ------------------------------------------------------------------ *//* The list, and its two empty states                                  *//* ------------------------------------------------------------------ */export interface AllergyListProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "children"> {  /**   * The allergies, in the order they should be read. An empty array and a `null` mean   * different things — see `askLabel`.   */  records?: readonly AllergyRecord[];  /**   * A no-known-allergies assertion.   *   * Requires both an asserter and a date. Supplying one without the other   * renders not-asked, because an unattributed assertion of absence is not an   * assertion — and it is the one that gets prescribed against.   */  noneKnown?: Partial<NoKnownAllergies>;  /** Row height and type scale. Inherited from the nearest density provider when omitted. */  density?: "compact" | "default";  expandClass?: ClassExpander;  onOpenDetail?: (record: AllergyRecord) => void;  /** Rendered inside the not-asked state. "Ask and record", typically. */  onAsk?: () => void;  /**   * What to render when nobody has asked. "No known allergies" is a clinical assertion   * somebody made; an empty list is not, and the two must not look alike.   */  askLabel?: string;}export const AllergyList = React.forwardRef<HTMLDivElement, AllergyListProps>(function AllergyList(  {    records,    noneKnown,    density = "default",    expandClass,    onOpenDetail,    onAsk,    askLabel = "Ask and record",    className,    ...rest  },  ref,) {  const state = resolveListState({ records: records ?? [], noneKnown: noneKnown ?? {} });  return (    <div      {...rest}      ref={ref}      className={cn("zb-allergy-list", className)}      data-zb-allergy-list={state.kind}    >      {state.kind === "records" ? (        state.records.map((record) => (          <AllergyChip            key={record.id}            record={record}            density={density}            {...(expandClass ? { expandClass } : {})}            {...(onOpenDetail ? { onOpenDetail } : {})}          />        ))      ) : state.kind === "none-known" ? (        /*         * A positive clinical finding, and it looks like one.         *         * Green, with an author and a date, because that is what makes it safe         * to prescribe against — and the author and date are what separate it         * from the state below.         */        <div className="zb-allergy-none" role="group" aria-label={describeNoKnown(state.assertion)}>          <span className="zb-allergy-none__head" aria-hidden="true">            <ClinicalStatus scale="criticality" step="normal" shape="dot" density="compact" />            No known{state.assertion.scope ? ` ${state.assertion.scope}` : ""} allergies          </span>          <span className="zb-allergy-none__meta" aria-hidden="true">            Asserted by {state.assertion.asserter} · {state.assertion.assertedAt}            {state.assertion.context ? ` · ${state.assertion.context}` : ""}          </span>        </div>      ) : (        /*         * Not an empty list. A gap, and a gate.         *         * Deliberately unlike the state above in shape as well as colour: a         * reader scanning a chart should be able to tell these apart without         * reading either, because the consequence of confusing them is a         * prescription written against an allergy history nobody took.         */        <div className="zb-allergy-unknown" role="group" aria-label={NOT_ASKED_SENTENCE}>          <span className="zb-allergy-unknown__head" aria-hidden="true">            <ClinicalStatus scale="criticality" step="not-assessed" shape="dot" density="compact" />            Allergy status not recorded          </span>          <span className="zb-allergy-unknown__meta" aria-hidden="true">            No entry, and no assertion that there is nothing to enter.          </span>          {onAsk ? (            <button type="button" className="zb-allergy-unknown__ask" onClick={onAsk}>              {askLabel}            </button>          ) : null}        </div>      )}    </div>  );});