Files
HealthLog/src/components/labs/lab-reference-range-bar.tsx
T
BernhardBuckel a1a84f924b feat(labs): let the lab list's range bar use a wide card
On a wide window the compact lab list was one five-column row whose only
flexible column was the name: the name column sat mostly empty while the range
bar and the trend stayed small at the right edge.

The list's card is now a container, and the columns follow its width instead of
the window's. Below 64 rem of card the row is the lg table it was, with the
range bar at 12 rem; from 64 rem the bar column grows from 12 to 18 rem and the
trend column from 72 px to 8 rem, and the bar fills its column. The two tiers
exclude each other, so the result does not depend on the order the CSS is
emitted in. The trend sparkline itself is unchanged.

From lg up a long analyte name wraps instead of being cut off; a phone keeps the
single line with an ellipsis, and the bar keeps its own 12 rem cap there.

The shared 1280 px frame is untouched; a Playwright spec measures it on /labs,
/measurements and /mood at 1280, 1920 and 3440 px.

Fixes #1057
2026-10-04 10:56:43 +02:00

72 lines
2.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"use client";
import { RangeBar } from "@/components/targets/range-bar";
import { cn } from "@/lib/utils";
import { useLabNumber } from "./use-lab-format";
/**
* v1.37.34 — compact reference-range visualization for saved lab readings.
*
* The adapter keeps lab-specific data rules out of the shared target bar:
* qualitative readings are omitted, one-sided limits get a bounded visual
* scale, and invalid ranges remain text-only.
*/
export function LabReferenceRangeBar({
value,
referenceLow,
referenceHigh,
unit,
className,
}: {
value: number | null;
referenceLow: number | null;
referenceHigh: number | null;
unit: string;
/** Extra classes on the bar's wrapper; it caps itself at 12rem by default. */
className?: string;
}) {
const labNumber = useLabNumber();
const hasLow = referenceLow !== null && Number.isFinite(referenceLow);
const hasHigh = referenceHigh !== null && Number.isFinite(referenceHigh);
if (
value === null ||
!Number.isFinite(value) ||
(!hasLow && !hasHigh) ||
(hasLow && hasHigh && referenceLow! >= referenceHigh!)
) {
return null;
}
// A missing endpoint gets a synthetic opposite edge only for positioning;
// the visible label still shows the original one-sided limit.
const scale = Math.max(Math.abs(referenceLow ?? referenceHigh!), 1);
const min = referenceLow ?? referenceHigh! - scale;
const max = referenceHigh ?? referenceLow! + scale;
const rangeLabel = !hasLow
? `≤${labNumber(referenceHigh!)} ${unit}`
: !hasHigh
? `≥${labNumber(referenceLow!)} ${unit}`
: `${labNumber(referenceLow!)}–${labNumber(referenceHigh!)} ${unit}`;
return (
<div
data-slot="lab-reference-range-bar"
className={cn("w-full max-w-48 shrink-0", className)}
aria-label={rangeLabel}
>
<RangeBar
value={value}
min={min}
max={max}
unit={unit}
compact
tone="lab"
formatValue={labNumber}
minLabel={referenceLow === null ? null : undefined}
maxLabel={referenceHigh === null ? null : undefined}
/>
</div>
);
}