import * as React from "react"; import { ExternalLinkIcon, type LucideIcon } from "lucide-react"; import { Badge, type BadgeProps } from "./badge"; import { Button } from "./button"; import { NewTabHint } from "./component-labels"; import { cn } from "../lib/cn"; import { UiLink } from "./link"; // The design system's components take a slot as an element or as plain data: // an action as { label, variant, icon }, a badge as { tone, label }, a link as // { label, href, external }. The data keeps the design system's names; this // file turns it into the primitives. Where the design system names an icon of // its own set, the dashboard passes the Lucide component. /** A Lucide component, or an element that draws the icon itself. */ export type IconSlot = LucideIcon | React.ReactNode; /** What a page writes in a list to withhold an entry: `canEdit && { … }`. * Every list these components take skips such an entry. */ export type Falsy = false | null | undefined; // The boards' markup names an icon ("plus", "alert-triangle"), and nothing in // this app's types stops a page from copying that. Drawn as it is, the name // would be a word inside the button, and in its accessible name. function reportIconName(name: string) { if (process.env.NODE_ENV !== "production") { console.error( `An icon is a Lucide component here, not the design system's icon name ("${name}"): import it from lucide-react and pass the component.`, ); } } function isComponent(icon: unknown): icon is LucideIcon { // `typeof null` is "object", and `in` throws on null. if (icon == null) return false; if (typeof icon === "function") return true; return ( typeof icon === "object" && !React.isValidElement(icon) && "$$typeof" in icon ); } /** A component is drawn as decoration; an element is left as it is. */ export function renderIcon(icon: IconSlot, className?: string) { if (icon == null || icon === false) return null; if (typeof icon === "string") { reportIconName(icon); return null; } if (!isComponent(icon)) return icon; const Icon = icon; return