import cn from 'clsx' import type { ComponentProps, ReactElement } from 'react' import { useCallback, useRef } from 'react' import { WordWrapIcon } from './word-wrap' import { Button } from './button' import { CopyToClipboard } from './copy-to-clipboard' import React from 'react' export const Pre = ({ children, className, hasCopyCode = true, filename, ...props }: ComponentProps<'pre'> & { filename?: string hasCopyCode?: boolean }): ReactElement => { const preRef = useRef(null); const toggleWordWrap = useCallback(() => { const htmlDataset = document.documentElement.dataset; const hasWordWrap = 'nextraWordWrap' in htmlDataset; if (hasWordWrap) { delete htmlDataset.nextraWordWrap; } else { htmlDataset.nextraWordWrap = ''; } }, []); const renderChildren = () => { if (React.isValidElement(children) && children.type === 'code') { return children.props.children; } return children; }; return (
{filename && (
{filename}
)}
        {renderChildren()}
      
&]:nx-opacity-100 focus-within:nx-opacity-100', 'nx-flex nx-gap-1 nx-absolute nx-m-[11px] nx-right-0', filename ? 'nx-top-8' : 'nx-top-0' )} > {hasCopyCode && ( preRef.current?.querySelector('code')?.textContent || '' } /> )}
); }