"use client"; import { ChevronRight } from "lucide-react"; import { useEffect, useRef, useState } from "react"; import PackageIcon from "./Icons"; const CodeContainer = () => { const [isOpen, setIsOpen] = useState(false); const [selectedPM, setSelectedPM] = useState<"npm" | "yarn" | "pnpm" | "bun">( "npm", ); const [copied, setCopied] = useState(false); const menuRef = useRef(null); useEffect(() => { const handleClickOutside = (event: MouseEvent) => { if (menuRef.current && !menuRef.current.contains(event.target as Node)) { setIsOpen(false); } }; document.addEventListener("mousedown", handleClickOutside); return () => document.removeEventListener("mousedown", handleClickOutside); }, []); const commands = { npm: "npx create-better-t-stack@latest", yarn: "yarn dlx create better-t-stack", pnpm: "pnpm dlx create better-t-stack", bun: "bunx create-better-t-stack", }; const copyToClipboard = async (pm: "npm" | "yarn" | "pnpm" | "bun") => { await navigator.clipboard.writeText(commands[pm]); setSelectedPM(pm); setCopied(true); setIsOpen(false); setTimeout(() => setCopied(false), 2000); }; return (
{commands[selectedPM]}
{isOpen && (
{(["npm", "yarn", "pnpm", "bun"] as const).map((pm) => ( ))}
)}
); }; const CopyIcon = ({ className = "" }) => ( copy ); const CheckIcon = ({ className = "" }) => ( check ); export default CodeContainer;