73 lines
1.8 KiB
TypeScript
73 lines
1.8 KiB
TypeScript
import type { ReactNode } from 'react'
|
|
import {
|
|
AlarmClock,
|
|
BadgeCheck,
|
|
Circle,
|
|
CircleAlert,
|
|
CircleCheck,
|
|
ClipboardList,
|
|
ListChecks,
|
|
Loader,
|
|
RotateCcw,
|
|
Search,
|
|
type LucideIcon,
|
|
} from 'lucide-react'
|
|
import { Tag, type TagVariant } from './tag'
|
|
|
|
const TONES: Record<string, TagVariant> = {
|
|
reported: 'accent',
|
|
triaged: 'outline',
|
|
investigating: 'outline',
|
|
capa_pending: 'outline',
|
|
verification: 'outline',
|
|
closed: 'neutral',
|
|
open: 'accent',
|
|
in_progress: 'outline',
|
|
overdue: 'accent',
|
|
pending_verification: 'outline',
|
|
verified: 'neutral',
|
|
reopened: 'accent',
|
|
}
|
|
|
|
const ICONS: Record<string, LucideIcon> = {
|
|
reported: CircleAlert,
|
|
triaged: ListChecks,
|
|
investigating: Search,
|
|
capa_pending: ClipboardList,
|
|
verification: BadgeCheck,
|
|
closed: CircleCheck,
|
|
open: Circle,
|
|
in_progress: Loader,
|
|
overdue: AlarmClock,
|
|
pending_verification: BadgeCheck,
|
|
verified: CircleCheck,
|
|
reopened: RotateCcw,
|
|
}
|
|
|
|
export function statusTone(status: string): TagVariant {
|
|
return TONES[status] ?? 'neutral'
|
|
}
|
|
|
|
function humanize(value: string): string {
|
|
return value
|
|
.split('_')
|
|
.map(w => (w === 'capa' ? 'CAPA' : w.charAt(0).toUpperCase() + w.slice(1)))
|
|
.join(' ')
|
|
}
|
|
|
|
export function StatusTag({ status, children }: { status: string; children?: ReactNode }) {
|
|
const Icon = ICONS[status]
|
|
return (
|
|
<Tag variant={statusTone(status)}>
|
|
{Icon && <Icon size={12} strokeWidth={2} aria-hidden />}
|
|
{children ?? humanize(status)}
|
|
</Tag>
|
|
)
|
|
}
|
|
|
|
const PRIORITY_TONES: Record<string, TagVariant> = { high: 'accent', med: 'outline', low: 'neutral' }
|
|
|
|
export function PriorityTag({ priority, children }: { priority: string; children?: ReactNode }) {
|
|
return <Tag variant={PRIORITY_TONES[priority] ?? 'neutral'}>{children ?? humanize(priority)}</Tag>
|
|
}
|