import { CheckIcon, CopyIcon, InfoIcon, WarningCircleIcon } from "../icons"; import { useEffect, useRef, useState, type ComponentProps, type ReactNode } from "react"; import { SwapIcon } from "../components/swap-icon"; import { cn } from "./cn"; /** Muted line inks for user-chosen label colours: they mark a category, never a state. */ const LABEL_INK: Record = { blue: "#7e9ce6", green: "var(--sage)", orange: "#d08b4f", purple: "#a08fd0", red: "#d9726a", teal: "#62aaa4", neutral: "var(--faint)", }; /** The ink of a label colour, for a swatch outside a badge. */ export function labelInk(color: string): string { return LABEL_INK[color] ?? LABEL_INK.neutral; } const TONE: Record = { secondary: "bg-hover text-muted", outline: "text-muted shadow-[inset_0_0_0_1px_var(--line)]", primary: "bg-accent-tint text-accent-text", success: "bg-success-tint text-success", purple: "bg-success-tint text-success", warning: "bg-needs-tint text-needs-text", danger: "bg-danger-tint text-danger", red: "bg-danger-tint text-danger", }; export type BadgeVariant = keyof typeof TONE | keyof typeof LABEL_INK; /** A small chip. Status and role badges use tone; label colours show as a dot. */ export function Badge({ variant = "secondary", className, children, ...props }: { variant?: BadgeVariant | string } & ComponentProps<"span">) { const ink = !(variant in TONE) ? LABEL_INK[variant] : undefined; return ( {ink && } {children} ); } /** A message inside the page: information, or an error that names the problem and the recovery. */ export function Banner({ variant = "info", title, description, children, className }: { variant?: "info" | "error" | "success"; title?: ReactNode; description?: ReactNode; children?: ReactNode; className?: string }) { const error = variant === "error"; const Icon = error ? WarningCircleIcon : variant === "success" ? CheckIcon : InfoIcon; return (
{title &&

{title}

} {description &&
{description}
} {children}
); } /** The empty state of a list or page: a quiet icon, what is missing, and the next step. It enters in stages. */ export function Empty({ icon, title, description, contents, size = "base", className }: { icon?: ReactNode; title: ReactNode; description?: ReactNode; contents?: ReactNode; size?: "sm" | "base"; className?: string }) { return (
{icon &&
{icon}
}

{title}

{description &&

{description}

}
{contents &&
{contents}
}
); } /** A value to copy, such as a token or a link, with a copy control whose icon cross-fades to a check. */ export function ClipboardText({ text, size = "sm", className }: { text: string; size?: "sm" | "base"; className?: string }) { const [copied, setCopied] = useState(false); const timer = useRef>(undefined); useEffect(() => () => clearTimeout(timer.current), []); const copy = async () => { try { await navigator.clipboard.writeText(text); setCopied(true); clearTimeout(timer.current); timer.current = setTimeout(() => setCopied(false), 1600); } catch { setCopied(false); } }; return ( {text} {copied ? "Copied" : ""} ); }