'use client'; import { CheckIcon, ClipboardIcon, TerminalIcon } from 'lucide-react'; import * as React from 'react'; import { copyToClipboardWithMeta } from '@/components/copy-button'; import { Button } from '@/components/ui/button'; import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'; import { useConfig } from '@/hooks/use-config'; import { cn } from '@/lib/utils'; import type { NpmCommands } from '@/types/unist'; export function CodeBlockCommand({ __bunCommand__, __npmCommand__, __pnpmCommand__, __yarnCommand__, className, ...props }: React.HTMLAttributes & NpmCommands & { 'data-language'?: string; 'data-theme'?: string; }) { const [config, setConfig] = useConfig(); const [hasCopied, setHasCopied] = React.useState(false); React.useEffect(() => { if (hasCopied) { const timer = setTimeout(() => { setHasCopied(false); }, 2000); return () => { clearTimeout(timer); }; } return undefined; }, [hasCopied]); const packageManager = config.packageManager || 'pnpm'; const tabs = { pnpm: __pnpmCommand__, npm: __npmCommand__, yarn: __yarnCommand__, bun: __bunCommand__, }; const copyCommand = async () => { const command = tabs[packageManager]; if (!command) { return; } const innerHasCopied = await copyToClipboardWithMeta(command, { name: 'copy_npm_command', properties: { command, pm: packageManager, }, }); if (innerHasCopied) { setHasCopied(true); } }; return (
{ setConfig({ ...config, packageManager: value as 'bun' | 'npm' | 'pnpm' | 'yarn', }); }} >
{Object.entries(tabs).map(([key]) => ( {key} ))}
{Object.entries(tabs).map(([key, value]) => (
                
                  {value}
                
              
))}
); }