| 1 | import { clsx } from "@/lib/cx"; |
| 2 | |
| 3 | export type StatusVariant = "passed" | "failed" | "held" | "pending" | "neutral"; |
| 4 | |
| 5 | const VARIANT_TOKEN: Record<StatusVariant, { color: string; label?: string }> = { |
| 6 | passed: { color: "var(--dk-yea)" }, |
| 7 | failed: { color: "var(--dk-nay)" }, |
| 8 | held: { color: "var(--dk-hold)" }, |
| 9 | pending: { color: "var(--dk-hold)" }, |
| 10 | neutral: { color: "var(--dk-ash)" }, |
| 11 | }; |
| 12 | |
| 13 | |
| 14 | export function StatusPill({ |
| 15 | variant = "neutral", |
| 16 | children, |
| 17 | className, |
| 18 | dot = false, |
| 19 | }: { |
| 20 | variant?: StatusVariant; |
| 21 | children: React.ReactNode; |
| 22 | className?: string; |
| 23 | dot?: boolean; |
| 24 | }) { |
| 25 | const { color } = VARIANT_TOKEN[variant]; |
| 26 | return ( |
| 27 | <span |
| 28 | className={clsx("pill", className)} |
| 29 | style={{ color, borderColor: `color-mix(in srgb, ${color} 38%, transparent)` }} |
| 30 | > |
| 31 | {dot ? ( |
| 32 | <span |
| 33 | aria-hidden="true" |
| 34 | className="inline-block h-1.5 w-1.5 rounded-full" |
| 35 | style={{ backgroundColor: color }} |
| 36 | /> |
| 37 | ) : null} |
| 38 | {children} |
| 39 | </span> |
| 40 | ); |
| 41 | } |
| 42 | |
| 43 | export function classifyStatus(raw: string): StatusVariant { |
| 44 | const s = raw.toLowerCase(); |
| 45 | if (/\b(pass|passed|signed|enacted|became law|cloture ok|agreed)\b/.test(s)) |
| 46 | return "passed"; |
| 47 | if (/\b(fail|failed|rejected|veto|not passed|cloture fail)\b/.test(s)) |
| 48 | return "failed"; |
| 49 | if (/\b(stall|held|in committee|referred|table)\b/.test(s)) return "held"; |
| 50 | if (/\b(pending|scheduled|introduced|await)\b/.test(s)) return "pending"; |
| 51 | return "neutral"; |
| 52 | } |