61 lines
2.1 KiB
TypeScript
61 lines
2.1 KiB
TypeScript
import type { ReactNode } from 'react'
|
|
import { cx } from './cx'
|
|
|
|
export type StatusHue = 'amber' | 'blue' | 'violet' | 'orange' | 'indigo' | 'green' | 'grey' | 'red'
|
|
|
|
const HUES: Record<string, StatusHue> = {
|
|
reported: 'amber', triaged: 'blue', investigating: 'violet', capa_pending: 'orange',
|
|
verification: 'indigo', closed: 'green',
|
|
open: 'grey', in_progress: 'blue', overdue: 'red', pending_verification: 'indigo',
|
|
verified: 'green', reopened: 'red',
|
|
critical: 'red', high: 'orange', med: 'amber', medium: 'amber', low: 'grey', active: 'green',
|
|
}
|
|
|
|
const LABELS: Record<string, string> = {
|
|
capa_pending: 'CAPA pending', pending_verification: 'Verification', in_progress: 'In progress', med: 'Medium',
|
|
}
|
|
|
|
// Full literal class strings so Tailwind can see them.
|
|
const HUE_CLASS: Record<StatusHue, string> = {
|
|
amber: 'bg-st-amber-bg text-st-amber-fg',
|
|
blue: 'bg-st-blue-bg text-st-blue-fg',
|
|
violet: 'bg-st-violet-bg text-st-violet-fg',
|
|
orange: 'bg-st-orange-bg text-st-orange-fg',
|
|
indigo: 'bg-st-indigo-bg text-st-indigo-fg',
|
|
green: 'bg-st-green-bg text-st-green-fg',
|
|
grey: 'bg-st-grey-bg text-st-grey-fg',
|
|
red: 'bg-st-red-bg text-st-red-fg',
|
|
}
|
|
|
|
export function statusHue(key: string): StatusHue {
|
|
return HUES[key] ?? 'grey'
|
|
}
|
|
|
|
function label(key: string): string {
|
|
if (LABELS[key]) return LABELS[key]
|
|
const words = key.split('_').join(' ')
|
|
return words.charAt(0).toUpperCase() + words.slice(1)
|
|
}
|
|
|
|
function Pill({ hue, className, children }: { hue: StatusHue; className?: string; children: ReactNode }) {
|
|
return (
|
|
<span
|
|
className={cx(
|
|
'inline-flex items-center px-2 py-0.5 rounded-md text-xs font-[550] whitespace-nowrap',
|
|
HUE_CLASS[hue],
|
|
className,
|
|
)}
|
|
>
|
|
{children}
|
|
</span>
|
|
)
|
|
}
|
|
|
|
export function StatusTag({ status, children }: { status: string; children?: ReactNode }) {
|
|
return <Pill hue={statusHue(status)}>{children ?? label(status)}</Pill>
|
|
}
|
|
|
|
export function PriorityTag({ priority, children }: { priority: string; children?: ReactNode }) {
|
|
return <Pill hue={statusHue(priority)}>{children ?? label(priority)}</Pill>
|
|
}
|