import { Badge, Button, cn, DropdownMenu, Link, Popover, Tooltip } from "@cloudflare/kumo"; import { PencilSimple, Plus } from "@phosphor-icons/react"; /** A language version's state in a list row, or that the language has no version yet. */ export type LanguageChipState = "published" | "draft" | "outdated" | "review" | "missing"; export interface LanguageChipItem { /** The BCP 47 tag, shown on the chip. */ locale: string; state: LanguageChipState; /** The version's editor; absent when it is missing. */ href?: string; } export interface LanguageChipsLabels { /** The chip row's accessible name ("Languages"). */ group: string; /** "English: published" โ€” the chip's accessible name and tooltip. */ describe: (item: LanguageChipItem) => string; /** The collapsed cell ("2/6"), shown with more than `collapseAfter` languages. */ summary: string; /** The collapsed cell's accessible name ("2 of 6 languages"). */ summaryLabel: string; /** The missing chip's menu item that starts a new draft. */ writeByHand: string; } export interface LanguageChipsProps { items: readonly LanguageChipItem[]; labels: LanguageChipsLabels; /** A person may start a missing language; without it, missing chips are inert. */ onWriteByHand?: ((locale: string) => void) | undefined; /** The language whose draft is being created. */ busyLocale?: string | undefined; /** More languages than this collapse into a summary with a popover. */ collapseAfter?: number; } const VARIANT: Record< Exclude, "success" | "secondary" | "warning" | "info" > = { published: "success", draft: "secondary", outdated: "warning", review: "info", }; function Chip({ item, labels, onWriteByHand, busy, }: { item: LanguageChipItem; labels: LanguageChipsLabels; onWriteByHand?: ((locale: string) => void) | undefined; busy: boolean; }) { const name = labels.describe(item); if (item.state !== "missing" && item.href) return ( {item.locale} ); const trigger = ( ); return ( {onWriteByHand ? ( } /> onWriteByHand(item.locale)}> {labels.writeByHand} ) : ( }> {trigger} )} ); } /** * A list row's languages (an internal review (2026-10) ยง4a): one chip per site * language in the site's order โ€” published, draft, outdated or needs review, each opening that * version โ€” and a missing language that a person can start by hand. Past `collapseAfter` * languages the cell shows "2/6" with every chip in a popover. */ export function LanguageChips({ items, labels, onWriteByHand, busyLocale, collapseAfter = 4, }: LanguageChipsProps) { const collapsed = items.length > collapseAfter; // Inline, at most `collapseAfter` chips stay on one line; the popover wraps. const wrap = collapsed; const chips = ( // biome-ignore lint/a11y/useSemanticElements: a chip row, not a form control group
{items.map((item) => ( ))}
); if (!collapsed) return chips; return ( } > {labels.summary} {labels.group}
{chips}
); }