import type { ReviewDomain } from "../types"; interface DomainOption { value: ReviewDomain; label: string; } interface DomainMultiSelectProps { options: DomainOption[]; value: ReviewDomain[]; onChange: (value: ReviewDomain[]) => void; } /** Checkbox panel for choosing one or more review domains. Selected values are * always kept in the order of the options, so the same choice never looks like * a change just because it was ticked in a different order. */ export function DomainMultiSelect({ options, value, onChange }: DomainMultiSelectProps) { const allSelected = options.length > 0 && value.length === options.length; function commit(next: ReviewDomain[]) { onChange(options.filter((o) => next.includes(o.value)).map((o) => o.value)); } function toggle(domain: ReviewDomain) { commit(value.includes(domain) ? value.filter((v) => v !== domain) : [...value, domain]); } const summary = value.length === 0 ? "Choose review domain(s)" : allSelected ? "All domains selected" : `${value.length} selected`; const chosenLabels = options.filter((o) => value.includes(o.value)).map((o) => o.label); return (
{summary}
{options.map((o) => ( ))}
{chosenLabels.length > 0 && !allSelected && (
{chosenLabels.join(", ")}
)}
); }