22 lines · 1.0 KBRaw
| 1 | import { cn } from "../ui/cn"; |
| 2 | |
| 3 | const INKS = ["var(--ochre)", "var(--sage)"]; |
| 4 | |
| 5 | function inkFor(name: string): string { |
| 6 | const hash = [...name].reduce((total, char) => (total * 31 + char.charCodeAt(0)) >>> 0, 7); |
| 7 | return INKS[hash % INKS.length]; |
| 8 | } |
| 9 | |
| 10 | /** A branch named as a line: a short segment in its line ink ending in a station dot. The base branch is the porcelain main line. */ |
| 11 | export function LineBadge({ name, main = false, className }: { name: string; main?: boolean; className?: string }) { |
| 12 | const ink = main ? "var(--porcelain)" : inkFor(name); |
| 13 | return ( |
| 14 | <span className={cn("inline-flex max-w-full items-center gap-1.5 align-middle font-mono text-xs text-ink", className)}> |
| 15 | <svg aria-hidden width="14" height="8" viewBox="0 0 14 8" className="shrink-0"> |
| 16 | <path d="M0 4H10" stroke={ink} strokeWidth="2.5" strokeLinecap="round" /> |
| 17 | <circle cx="10" cy="4" r="2.6" fill="var(--panel)" stroke={ink} strokeWidth="1.6" /> |
| 18 | </svg> |
| 19 | <span className="truncate">{name}</span> |
| 20 | </span> |
| 21 | ); |
| 22 | } |