// ============================================================ // LabsList — dynamic (date, values) rows. Port of hc-labs-container // / cr-labs-container in the vanilla hospital.html / chart.html // components. Pure controlled component — parent owns the array. // ============================================================ export interface LabRow { date: string; values: string } interface Props { value: LabRow[]; onChange: (next: LabRow[]) => void; placeholder?: string; testIdPrefix?: string; } const input = 'rounded-md border border-input bg-background px-2 py-1 text-sm'; const btn = 'inline-flex items-center gap-1 rounded-md border border-border bg-background px-3 py-1.5 text-xs font-medium hover:bg-muted'; export function emptyLab(): LabRow { return { date: '', values: '' }; } export default function LabsList({ value, onChange, placeholder, testIdPrefix = 'labs' }: Props) { function patch(i: number, next: Partial) { onChange(value.map((r, idx) => (idx === i ? { ...r, ...next } : r))); } function add() { onChange([...value, emptyLab()]); } function remove(i: number) { onChange(value.filter((_, idx) => idx !== i)); } return (
{value.length === 0 && (
No labs added.
)} {value.map((row, i) => (
patch(i, { date: e.target.value })} className={input + ' w-40 shrink-0'} />