import { useState, type ReactNode } from "react"; import { Check, Copy } from "lucide-react"; import { cx } from "../../lib/cx.js"; import { linkHandler } from "../../router.js"; import { Button } from "./button.js"; import { useToast } from "./toast.js"; export function Link({ to, className, children, ...rest }: { to: string; className?: string; children: ReactNode; "aria-current"?: "page" }) { return ( {children} ); } export function publicUrl(path: string): string { return `${location.origin}${path}`; } export function CopyButton({ value, label, size = "icon-sm" }: { value: string; label?: string; size?: "icon-sm" | "sm" }) { const [copied, setCopied] = useState(false); const toast = useToast(); const copy = async () => { try { await navigator.clipboard.writeText(value); setCopied(true); setTimeout(() => setCopied(false), 1500); } catch { toast("Couldn't access the clipboard", true); } }; return ( ); } // Website favicon placeholder: the first letter of the destination's hostname. export function DomainIcon({ url, className }: { url: string | null; className?: string }) { let host = ""; try { host = url ? new URL(url).hostname.replace(/^www\./, "") : ""; } catch { // Keep the placeholder. } return ( {host.charAt(0) || "?"} ); } export function Tabs({ tabs, active }: { tabs: { id: string; label: string; to: string; icon?: ReactNode }[]; active: string }) { return ( ); } export function Stat({ label, value, icon, hint }: { label: string; value: ReactNode; icon?: ReactNode; hint?: ReactNode }) { return (
{label} {icon}
{value}
{hint &&
{hint}
}
); }