"use client"; import { Check, Copy } from "lucide-react"; import { useState } from "react"; import { Tab, TabList, TabPanel, Tabs } from "@/components/ui/tabs"; const LANGS = [ { key: "curl", label: "curl" }, { key: "js", label: "JavaScript" }, { key: "python", label: "Python" }, ] as const; /** curl / JS / Python example tabs with a copy button; the pre scrolls inside its box, never the page. */ export function CodeTabs({ example, id }: { example: { curl: string; js: string; python: string }; id: string }) { const [tab, setTab] = useState("curl"); const [copied, setCopied] = useState(false); const text = example[tab as keyof typeof example] ?? example.curl; const copy = async () => { try { await navigator.clipboard.writeText(text); setCopied(true); setTimeout(() => setCopied(false), 1800); } catch { window.prompt("Copy", text); } }; return (
{LANGS.map((l) => ( {l.label} ))}
{LANGS.map((l) => (
{example[l.key]}
))}
); }