import { ChevronDown, Ellipsis, Play } from "lucide-react"; import type { ReactNode } from "react"; import { Button } from "./button.js"; import { Status, type StatusTone } from "./status.js"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from "./dropdown-menu.js"; import { IconButton } from "./icon-button.js"; import { Tooltip, TooltipContent, TooltipTrigger } from "./tooltip.js"; /** One place in the content's path; `siblings` makes it a switcher. */ export type WindowCrumb = { id: string; label: string; /** Other places at this level, offered by a ▾ switcher on the crumb. */ siblings?: readonly { id: string; label: string }[]; }; /** A command the content offers in the header; the content owns its effect. */ export type WindowCommand = { id: string; label: string; /** Render a supported glyph alone; label remains the accessible name. */ icon?: "play"; /** Which Caps button a primary command wears; default `outline`. */ variant?: "primary" | "outline" | "ghost"; /** A menu item that removes or discards something. */ tone?: "destructive"; disabled?: boolean; }; /** A quiet fact about the view: muted text led by the Caps status bead. */ export type WindowStatus = { id: string; label: string; /** Hide only the visible label, retaining it for assistive technology. */ presentation?: "bead"; tone?: Extract< StatusTone, "neutral" | "info" | "warning" | "success" | "error" >; }; /** The longest path shown whole; longer paths fold the middle into "…". */ const CRUMBS_SHOWN = 4; function Separator() { return ( ); } function Crumb({ crumb, current, popover, onCrumb, }: { crumb: WindowCrumb; current: boolean; popover?: HTMLElement | null | undefined; onCrumb?: ((crumbId: string, siblingId?: string) => void) | undefined; }) { const label = {crumb.label}; const common = { "data-caps-window-crumb": crumb.id, "aria-current": current ? ("page" as const) : undefined, }; if (crumb.siblings?.length) { return ( } aria-label={`${crumb.label}, switch`} > {label} {crumb.siblings.map((sibling) => ( { onCrumb?.(crumb.id, sibling.id); }} > {sibling.label} ))} ); } if (current || onCrumb === undefined) return ( {label} ); return ( ); } /** The path as a trail; on a phone only `‹ parent › current` remain. */ export function WindowCrumbs({ crumbs, popover, onCrumb, }: { crumbs: readonly WindowCrumb[]; popover?: HTMLElement | null | undefined; onCrumb?: ((crumbId: string, siblingId?: string) => void) | undefined; }) { const folded = crumbs.length > CRUMBS_SHOWN; const head = folded ? crumbs.slice(0, 1) : crumbs.slice(0, -1); const middle = folded ? crumbs.slice(1, -2) : []; const tail = folded ? crumbs.slice(-2) : crumbs.slice(-1); const last = crumbs.at(-1); const parts: ReactNode[] = []; const add = (crumb: WindowCrumb) => { parts.push( {parts.length > 0 ? : null} , ); }; for (const crumb of head) add(crumb); if (middle.length > 0) parts.push( } aria-label="More of the path" > {middle.map((crumb) => ( { onCrumb?.(crumb.id); }} > {crumb.label} ))} , ); for (const crumb of tail) add(crumb); return ( ); } /** Primary commands as buttons, the rest behind a ⋯ menu. */ export function WindowCommands({ primary, menu, popover, onAction, }: { primary?: readonly WindowCommand[] | undefined; menu?: readonly WindowCommand[] | undefined; popover?: HTMLElement | null | undefined; onAction?: ((id: string) => void) | undefined; }) { if (!primary?.length && !menu?.length) return null; return (
{primary?.map((command) => command.icon === "play" ? ( } aria-label={command.label} title={command.label} variant={command.variant ?? "ghost"} disabled={command.disabled === true} onClick={() => { onAction?.(command.id); }} /> ) : ( ), )} {menu?.length ? ( } aria-label="More" />} /> {menu.map((command) => ( { onAction?.(command.id); }} > {command.label} ))} ) : null}
); } /** Settled beads reveal their labels on hover/focus; other state stays visible. */ export function WindowStatuses({ status, }: { status: readonly WindowStatus[]; }) { if (status.length === 0) return null; return (
{status.map((item) => { const beadOnly = item.presentation === "bead"; const readout = ( {item.label} ) : ( item.label ) } tabIndex={beadOnly ? 0 : undefined} title={beadOnly ? undefined : item.label} className="caps-window-status" /> ); return beadOnly ? ( {readout} {item.label} ) : ( readout ); })}
); }