import React, { FC, useCallback, useEffect, useRef, useState } from 'react' import { CopyOutlined, CheckOutlined } from '@ant-design/icons' import { copyToClipboard, getClassnames } from '../../utils' import './style.less' import { useTranslation } from 'react-i18next' export interface CopyTextProps extends React.HTMLAttributes {} export const CopyAbleText: FC = ({ children, className }) => { const { t } = useTranslation() const divRef = useRef(null) const [copied, setCopied] = useState(false) const timer = useRef(-1) const startTimer = useCallback(() => { setCopied(true) clearTimeout(timer.current) timer.current = (setTimeout( () => setCopied(false), 3000 ) as unknown) as number }, [timer]) useEffect(() => { return () => clearTimeout(timer.current) }, []) const handleCopy = () => { copyToClipboard(divRef.current!.innerText) startTimer() } return (
{children} {copied ? ( ) : ( )}
) }