"use client"; import Link from "next/link"; import { useEffect, useRef, useState } from "react"; import { Button, Field, IconButton, Popover, Switcher, Tooltip } from "@unlocalhosted/metalui"; import { ChevronDownIcon, CodeIcon, MorphIcon, TerminalIcon } from "./icons"; /** * Copies `text`: a ghost icon key whose glyph morphs from duplicate to a check once the text is on the * clipboard, and back after a moment. */ export function CopyButton({ text, label = "Copy" }: { text: string; label?: string }) { const [copied, setCopied] = useState(false); const timer = useRef>(undefined); useEffect(() => () => clearTimeout(timer.current), []); return ( } className={copied ? "text-green-deep hover:text-green-deep" : ""} onClick={async () => { await navigator.clipboard.writeText(text); setCopied(true); clearTimeout(timer.current); timer.current = setTimeout(() => setCopied(false), 1500); }} /> ); } /** A read-only mono field (a URL, a command) with its copy key. */ export function CopyField({ value, label, copyLabel }: { value: string; label: string; copyLabel: string }) { return ( e.target.select()} /> ); } export type CloneUrls = { https: string; ssh: string }; type Protocol = keyof CloneUrls; /** The clone URL: HTTPS or SSH on a switcher, the URL in a read-only well with its copy key. */ export function CloneUrlTabs({ urls }: { urls: CloneUrls }) { const [protocol, setProtocol] = useState("https"); const url = urls[protocol]; return (
aria-label="Clone protocol" size="compact" value={protocol} onValueChange={setProtocol} options={[ { value: "https", label: "HTTPS" }, { value: "ssh", label: "SSH" }, ]} className="self-start" />

{protocol === "https" ? ( <> Private repos and pushes need an{" "} API token {" "} as the password. ) : ( <> Uses an{" "} SSH key {" "} from your account. )}

); } /** The repository's "Code" key: a popover with the clone URL. */ export function CloneButton({ urls }: { urls: CloneUrls }) { return ( Clone this repository ); }