import type { Severity, SeverityCounts } from "@/shared/types"; import { SEV_ORDER, severityLabel, totalFindings } from "../shared/lib/format"; /** NVD four tiers — dark-console spectrum, red → orange → amber. */ const BAR: Record = { critical: "#E5484D", high: "#F2604F", medium: "#FF8A3C", low: "#F0C43A", }; const DOT: Record = { critical: "bg-sev-critical-bar", high: "bg-sev-high-bar", medium: "bg-sev-medium-bar", low: "bg-sev-low-bar", }; export function SeverityBar({ counts, widthClass = "w-40", heightClass = "h-1.5", showLegend = true, legendClass = "text-[12px]", }: { counts: SeverityCounts; widthClass?: string; heightClass?: string; showLegend?: boolean; legendClass?: string; }) { const total = totalFindings(counts); const segs = SEV_ORDER.filter((s) => (counts[s] ?? 0) > 0).map((s) => ({ level: s, pct: total === 0 ? 0 : (counts[s] / total) * 100, count: counts[s], })); return (
{segs.map((s) => (
))}
{showLegend && (
{SEV_ORDER.map((s) => ( {counts[s] ?? 0} {severityLabel(s)} ))}
)}
); }