'use client'; import type { ComponentProps } from 'react'; import { useRef, useState } from 'react'; import { CheckIcon, CopyIcon } from './icons'; import { useInTabs } from './tabs.client'; type PreProps = ComponentProps<'pre'> & { 'data-filename'?: string; }; export function Pre({ children, className, 'data-filename': filename, ...props }: PreProps) { const preRef = useRef(null); const [copied, setCopied] = useState(false); const inTabs = useInTabs(); // Inside a Tabs shell (e.g. npm2yarn), render bare so the surrounding // code-block box owns the chrome (tab bar + copy button). if (inTabs) { return (
        {children}
      
); } async function copy() { const text = preRef.current?.textContent ?? ''; await navigator.clipboard.writeText(text); setCopied(true); setTimeout(() => setCopied(false), 2000); } return (
{filename && (
{filename}
)}
        {children}
      
); }