Skip to content
opsinjs
Edit this page

Components

ResultCard

One test result, shown in full. What was measured, the number, where it sits against its range, what that means in plain English, and what to do next.

Usage

pnpm dlx shadcn@latest add @opsinjs/result-card

The @opsinjs namespace is declared in your components.json. Everything it installs is code you then own. There is no runtime package to keep in step.

import { ResultCard } from "@/components/ui/result-card"
import { EXAMPLE_SOURCE } from "@/lib/opsinjs"
<ResultCard
  title="Example measurement"
  value={14}
  unit="mg/dL"
  precision={0}
  measuredAt="2026-03-14T08:12:00+00:00"
  now="2026-03-14T11:12:00+00:00"
  range={{ low: 10, high: 20, source: EXAMPLE_SOURCE }}
  status="steady"
  category="labs"
  meaning="Two or three short sentences, in the second person, written by the product."
/>

Examples

Theme
Density
Text
Status
Accent theme
Accent
result-card · base base · style base-lyraOpen under the product theme

A reading made of two numbers

segments carries a compound reading, each part a real Value. The unit prints once, is spoken after every part, and no bar is drawn.

Theme
Density
Text
Status
Accent theme
Accent
result-card-a-compound-reading · base base · style base-lyraOpen under the product theme
result-card-a-compound-reading.tsx
import { ResultCard } from "@/components/ui/result-card"

const EXAMPLE_NOW = "2026-03-14T11:12:00+00:00"

export default function ResultCardACompoundReading() {
  return (
    <div className="w-full max-w-lg">
      <ResultCard
        title="Example paired measurement"
        segments={[
          { label: "first part", value: 12 },
          { label: "second part", value: 8 },
        ]}
        unit="mmHg"
        precision={0}
        locale="en-GB"
        measuredAt="2026-03-14T07:40:00+00:00"
        now={EXAMPLE_NOW}
        category="heart"
        meaning="A pair is one measurement and is shown as one. There is no bar underneath it: two numbers have no single position on one line, and drawing one would mean choosing which half of the reading the picture is about."
        provenance="Example provenance for a reading whose two parts came from one measurement, taken by one device."
      />
    </div>
  )
}

The smallest card, and the sentence it will not leave out

No range, so no bar; no status, so no pill; no provenance, so no footnote. An absent meaning still renders a sentence saying there is none.

Theme
Density
Text
Status
Accent theme
Accent
result-card-no-explanation-supplied · base base · style base-lyraOpen under the product theme
result-card-no-explanation-supplied.tsx
import { ResultCard } from "@/components/ui/result-card"

const EXAMPLE_NOW = "2026-03-14T11:12:00+00:00"

export default function ResultCardNoExplanationSupplied() {
  return (
    <div className="w-full max-w-lg">
      <ResultCard
        title="Second example measurement"
        value={14}
        unit="mg/dL"
        precision={0}
        locale="en-GB"
        measuredAt="2026-03-14T09:05:00+00:00"
        now={EXAMPLE_NOW}
      />
    </div>
  )
}

The same result at two ages

Two cards differ only in measuredAt and share a level, because age lowers a reading's worth without raising the alarm.

Theme
Density
Text
Status
Accent theme
Accent
result-card-an-old-reading · base base · style base-lyraOpen under the product theme
result-card-an-old-reading.tsx
import { EXAMPLE_SOURCE } from "@/lib/opsinjs"
import { ResultCard } from "@/components/ui/result-card"

const EXAMPLE_NOW = "2026-03-14T11:12:00+00:00"

export default function ResultCardAnOldReading() {
  return (
    <div className="flex w-full max-w-lg flex-col gap-opsin-6">
      <ResultCard
        title="Example measurement"
        value={14}
        unit="mg/dL"
        precision={0}
        locale="en-GB"
        measuredAt="2026-03-14T08:12:00+00:00"
        now={EXAMPLE_NOW}
        range={{
          low: 10,
          high: 20,
          source: EXAMPLE_SOURCE,
          asOf: "2026-01-05T00:00:00+00:00",
        }}
        status="steady"
        category="labs"
        meaning="This reading was taken a few hours ago. The timestamp says when, and says nothing else. No product has told this card what counts as old for this measurement, so it makes no claim about that."
      />
      <ResultCard
        title="Example measurement"
        value={14}
        unit="mg/dL"
        precision={0}
        locale="en-GB"
        measuredAt="2025-11-14T08:12:00+00:00"
        now={EXAMPLE_NOW}
        range={{
          low: 10,
          high: 20,
          source: EXAMPLE_SOURCE,
          asOf: "2026-01-05T00:00:00+00:00",
        }}
        status="steady"
        category="labs"
        meaning="The same reading, four months older. The number has not changed, the interval has not changed and the level has not changed. What has changed is how much any of them is worth, and the date is what says so. Age is a reason to measure again, not a reason to raise the alarm."
        actions={[
          { label: "Book a repeat example test", href: "#example", recommended: true },
        ]}
        provenance="Example provenance recording who measured it, with what, and whose interval it is compared against."
      />
    </div>
  )
}

When to use it

Use it when

  • A single result with room for its range, meaning and next step, behind authentication.
  • A result seen for the first time, where the explanation matters as much as the number.

Do not use it when

  • Several readings side by side in a dashboard grid.Use metric-tile instead.
  • The number has no range, no status and nothing to explain.Use value instead.
  • You only need to show where a value sits within its range.Use range-bar instead.
  • The main message is an instruction rather than a measurement.Use care-card instead.
  • Something has changed and must interrupt the reader now.Use alert-banner instead.

Clinical meaning

Asserts. A measurement was taken, at a time, in a unit, with any stated range and the level the product assigned. Every number goes through Value.

Never read as. A diagnosis, a health summary or a clinician's advice. A next step is the product's, and your meaning and action labels say who is speaking. A result that may distress needs High-stakes moments around it.

Colour axis. Both, as Two colour axes requires: status reaches only the StatusPill, category only the title, and no prop tints the surface.

Thresholds. The product's. No default range, status derivation (Two colour axes) or staleness boundary (Trends and uncertainty) exists here; staleAfterHours passes through to RelativeTime. A reading you cannot vouch for must not drive attention or urgent.

Provenance and privacy. provenance is free text with no class, so keep an estimated or self-reported value free of status yourself. It has no mask; Consent and privacy is built around the card.

Accessibility

The audit changed nothing, finding no axe violation, target below the 44px floor or focus-visible gap. The title is a real heading at the caller's level, the StatusPill carries a word and an icon, and the card reflows unclipped at 320px and 200%.

Residual items.

  • By design, the root <article> takes aria-label from the title, not aria-labelledby, matching the visible heading. A visible-heading reference is a future enhancement.
  • className merges onto the root, so a caller's truncate can clip a reading. The component truncates nothing; the JSDoc warns of it.
  • No gate checks print, forced-colors or prefers-contrast.
KeyActionNotes
TabMoves to the first action, where the card has oneThe card itself is not a tab stop.
Shift+TabMoves backwards through the same stopsReverse order matches visual order.
EnterActivates the focused actionPlatform behaviour. Nothing is destructive.
SpaceActivates a focused button actionOn an onSelect action only.
EscapeNothingNot dismissible. Inside a Sheet or Dialog, Escape is theirs.
Arrow keysNothingThe bar is role="img", not a slider.
Contrast: 120 measured token pairs, 19 below floor
PairThemeAPCA LcWCAG 2.2Floor
activity ink on activity surfacelight88.59.61:1Pass
activity ink on activity surfacedark-83.112.58:1Pass
activity line on activity surfacelight67.64.42:1Pass
activity line on activity surfacedark-69.09.93:1Pass
activity accent on activity surfacelight44.12.34:1Below floor
activity accent on activity surfacedark-53.37.26:1Pass
activity accent on the pagelight46.12.41:1Below floor
activity accent on the pagedark-54.68.22:1Pass
activity ink on the pagelight90.59.90:1Pass
activity ink on the pagedark-84.414.24:1Pass
activity line on the bandlight66.14.32:1Pass
activity line on the banddark-67.48.60:1Pass
heart ink on heart surfacelight89.110.51:1Pass
heart ink on heart surfacedark-80.512.55:1Pass
heart line on heart surfacelight70.45.05:1Pass
heart line on heart surfacedark-64.59.46:1Pass
heart accent on heart surfacelight60.33.64:1Pass
heart accent on heart surfacedark-48.26.68:1Pass
heart accent on the pagelight63.23.81:1Pass
heart accent on the pagedark-49.57.27:1Pass
heart ink on the pagelight92.010.97:1Pass
heart ink on the pagedark-81.813.65:1Pass
heart line on the bandlight69.95.01:1Pass
heart line on the banddark-62.87.88:1Pass
labs ink on labs surfacelight88.89.78:1Pass
labs ink on labs surfacedark-83.112.69:1Pass
labs line on labs surfacelight67.94.51:1Pass
labs line on labs surfacedark-68.49.90:1Pass
labs accent on labs surfacelight59.33.49:1Pass
labs accent on labs surfacedark-52.77.21:1Pass
labs accent on the pagelight61.53.60:1Pass
labs accent on the pagedark-53.98.07:1Pass
labs ink on the pagelight90.910.09:1Pass
labs ink on the pagedark-84.314.22:1Pass
labs line on the bandlight66.54.42:1Pass
labs line on the banddark-66.78.49:1Pass
mind ink on mind surfacelight89.910.36:1Pass
mind ink on mind surfacedark-81.312.56:1Pass
mind line on mind surfacelight70.74.94:1Pass
mind line on mind surfacedark-65.49.54:1Pass
mind accent on mind surfacelight60.03.55:1Pass
mind accent on mind surfacedark-49.16.77:1Pass
mind accent on the pagelight62.83.70:1Pass
mind accent on the pagedark-50.07.42:1Pass
mind ink on the pagelight92.710.80:1Pass
mind ink on the pagedark-82.213.77:1Pass
mind line on the bandlight70.04.89:1Pass
mind line on the banddark-63.48.00:1Pass
nutrition ink on nutrition surfacelight89.310.06:1Pass
nutrition ink on nutrition surfacedark-81.912.55:1Pass
nutrition line on nutrition surfacelight69.74.78:1Pass
nutrition line on nutrition surfacedark-66.79.66:1Pass
nutrition accent on nutrition surfacelight39.22.11:1Below floor
nutrition accent on nutrition surfacedark-50.26.88:1Pass
nutrition accent on the pagelight41.82.19:1Below floor
nutrition accent on the pagedark-51.37.63:1Pass
nutrition ink on the pagelight91.910.44:1Pass
nutrition ink on the pagedark-82.913.91:1Pass
nutrition line on the bandlight68.84.71:1Pass
nutrition line on the banddark-64.88.19:1Pass
sleep ink on sleep surfacelight89.610.19:1Pass
sleep ink on sleep surfacedark-81.912.60:1Pass
sleep line on sleep surfacelight70.04.80:1Pass
sleep line on sleep surfacedark-66.49.65:1Pass
sleep accent on sleep surfacelight64.64.05:1Pass
sleep accent on sleep surfacedark-50.46.94:1Pass
sleep accent on the pagelight67.34.22:1Pass
sleep accent on the pagedark-51.47.67:1Pass
sleep ink on the pagelight92.310.60:1Pass
sleep ink on the pagedark-82.913.92:1Pass
sleep line on the bandlight69.14.75:1Pass
sleep line on the banddark-64.58.16:1Pass
body text on the pagelight101.617.18:1Pass
body text on the pagedark-100.518.00:1Pass
body text on a cardlight104.717.96:1Pass
body text on a carddark-99.616.32:1Pass
body text on the muted groundlight98.116.32:1Pass
body text on the muted grounddark-97.513.77:1Pass
secondary text on the pagelight83.97.42:1Pass
secondary text on the pagedark-80.713.44:1Pass
secondary text on a cardlight87.07.76:1Pass
secondary text on a carddark-79.812.19:1Pass
secondary text on the muted groundlight80.47.05:1Pass
secondary text on the muted grounddark-77.810.28:1Pass
a hairline boundary on the pagelight19.31.41:1Below floor
a hairline boundary on the pagedark-8.21.90:1Below floor
a hairline boundary on a cardlight22.41.47:1Below floor
a hairline boundary on a carddark-7.31.72:1Below floor
a hairline boundary on the muted groundlight15.81.34:1Below floor
a hairline boundary on the muted grounddark0.01.45:1Below floor
a placeholder boundary on the pagelight69.84.52:1Pass
a placeholder boundary on the pagedark-51.07.62:1Pass
a placeholder boundary on a cardlight72.84.72:1Pass
a placeholder boundary on a carddark-50.16.91:1Pass
a placeholder boundary on the muted groundlight66.24.29:1Pass
a placeholder boundary on the muted grounddark-48.15.83:1Pass
a placeholder fill on the pagelight8.31.18:1Below floor
a placeholder fill on the pagedark-8.21.90:1Below floor
a placeholder fill on a cardlight11.41.23:1Below floor
a placeholder fill on a carddark-7.31.72:1Below floor
a placeholder fill on the muted groundlight0.01.12:1Below floor
a placeholder fill on the muted grounddark0.01.45:1Below floor
a placeholder boundary on its own filllight58.93.84:1Pass
a placeholder boundary on its own filldark-41.54.01:1Below floor
the card hairline on the pagelight69.84.52:1Pass
the card hairline on the pagedark-28.74.19:1Below floor
the card hairline on a cardlight72.84.72:1Pass
the card hairline on a carddark-27.93.80:1Below floor
activity ink on the card materiallight93.610.34:1Pass
activity ink on the card materialdark-83.512.91:1Pass
heart ink on the card materiallight95.111.47:1Pass
heart ink on the card materialdark-80.912.38:1Pass
labs ink on the card materiallight94.010.54:1Pass
labs ink on the card materialdark-83.512.90:1Pass
mind ink on the card materiallight95.711.28:1Pass
mind ink on the card materialdark-81.412.49:1Pass
nutrition ink on the card materiallight95.010.91:1Pass
nutrition ink on the card materialdark-82.012.61:1Pass
sleep ink on the card materiallight95.411.08:1Pass
sleep ink on the card materialdark-82.112.62:1Pass

These are the measured token pairs this component draws colour from, not a measurement of the component itself.

Props interface

Prop

Type

Generated from ResultCardProps in registry/bases/base/result-card.tsx.

now and precision are required: the card never reads the clock, so pass one now to every card on a screen. value is number | null, never a string; a pair is segments. A third action, a second recommended and a titleLevel outside 2 to 6 each warn once and fall back.

Data attributes

AttributeConditionValue
data-slotOn every part, alwaysresult-card, result-card-header, -title, -time, -reading, -meaning, -actions, -footnote; result-card-action on a link action, button on an onSelect action
data-statusOn the embedded StatusPill only, with a statussteady | watch | attention | urgent
data-categoryOn ResultCard.Title, for one of the six categoriessleep | heart | activity | nutrition | mind | labs
data-opsinjs-valueOn every Value, including a drawn RangeBar's. De-duplicate before scraping.The unrounded number, or an empty string with no reading