import React, { useEffect, useState } from 'react'; import './index.css'; import hljs from 'highlight.js'; import '../../style/atom-one-dark.css'; import copyIcon from '../../assets/copyIcon.svg'; import copyIconActive from '../../assets/copyIconActive.svg'; const copy = (props: any) => { const [copyShow, setCopyShow] = useState(false) const copyValue = () => { let Url = props?.children[0]; let oInput = document.createElement("textarea"); oInput.value = Url ?? ""; document.body.appendChild(oInput); oInput.select(); document.execCommand("Copy"); oInput.className = "oInput"; oInput.style.display = "none"; document.body.removeChild(oInput); }; useEffect(() => { const codes = document?.querySelectorAll('.copyCode') hljs.configure({ // 忽略警告 ignoreUnescapedHTML: true }) if (codes && codes.length > 0) { codes.forEach(el => { // 让每个 code 内容实现代码高亮 hljs?.highlightElement(el) }) return } // 直接找到所有的 pre 标签 const pres = document?.querySelectorAll('.copyCode') if (pres && pres.length > 0) { pres.forEach(el => { hljs.highlightElement(el) }) } }, [props?.children]); return (
          
            {props?.children[0]}
          
        
{props?.children[0] &&
{copyShow ? setCopyShow(true)} onMouseLeave={() => setCopyShow(false)} >
复制
: setCopyShow(true)} onMouseLeave={() => setCopyShow(false)} > }
}
); }; export default copy;