| 1 | import Link from "next/link"; |
| 2 | import { SourceLink } from "@/components/source-link"; |
| 3 | import type { ChangeEvent } from "@/lib/feed"; |
| 4 | |
| 5 | |
| 6 | const CHANGE_COLOR: Record<string, string> = { |
| 7 | added: "var(--dk-yea)", |
| 8 | updated: "var(--dk-hold)", |
| 9 | removed: "var(--dk-nay)", |
| 10 | }; |
| 11 | |
| 12 | export function ChangesFeed({ |
| 13 | items, |
| 14 | limit, |
| 15 | }: { |
| 16 | items: ChangeEvent[]; |
| 17 | limit?: number; |
| 18 | }) { |
| 19 | const shown = limit ? items.slice(0, limit) : items; |
| 20 | if (shown.length === 0) { |
| 21 | return ( |
| 22 | <p className="font-mono text-[13px] text-ash-2"> |
| 23 | No recent changes on record. |
| 24 | </p> |
| 25 | ); |
| 26 | } |
| 27 | return ( |
| 28 | <ul className="divide-y divide-[color:var(--dk-line)]"> |
| 29 | {shown.map((c) => { |
| 30 | const color = CHANGE_COLOR[c.change] ?? "var(--dk-ash)"; |
| 31 | const text = c.summary || `${c.change} ${c.refType}`; |
| 32 | return ( |
| 33 | <li key={c.id} className="py-2.5"> |
| 34 | <div className="flex items-start gap-2.5"> |
| 35 | <span |
| 36 | className="pill mt-0.5 shrink-0" |
| 37 | style={{ |
| 38 | color, |
| 39 | borderColor: `color-mix(in srgb, ${color} 40%, transparent)`, |
| 40 | }} |
| 41 | > |
| 42 | {c.change} |
| 43 | </span> |
| 44 | <div className="min-w-0 flex-1"> |
| 45 | <p className="font-mono text-[12px] leading-relaxed text-paper"> |
| 46 | {c.href ? ( |
| 47 | <Link |
| 48 | href={c.href} |
| 49 | className="focus-ring rounded-sm underline underline-offset-4 hover:text-paper" |
| 50 | > |
| 51 | {text} |
| 52 | </Link> |
| 53 | ) : ( |
| 54 | text |
| 55 | )} |
| 56 | </p> |
| 57 | <p className="label mt-0.5 text-ash-2"> |
| 58 | {c.source} |
| 59 | {c.refId ? ` · ${c.refId}` : ""} |
| 60 | </p> |
| 61 | </div> |
| 62 | <SourceLink url={c.sourceUrl} className="shrink-0" /> |
| 63 | </div> |
| 64 | </li> |
| 65 | ); |
| 66 | })} |
| 67 | </ul> |
| 68 | ); |
| 69 | } |