import React from 'react'; import ReactTooltip from 'react-tooltip'; import { CopyAreaStyled, CopyAreaTextInput } from './CopyArea.styled'; type CopyAreaProps = { value: string; }; enum CopyState { NotCopied = 0, Copied = 1, } export const CopyArea = (props: CopyAreaProps) => { const [copied, setCopied] = React.useState(CopyState.NotCopied); const inputRef = React.useRef(null); const handleClick = () => { inputRef.current?.setSelectionRange(0, 99999); if (navigator.clipboard) { navigator.clipboard.writeText(props.value); setCopied(CopyState.Copied); } }; const strings = { [CopyState.NotCopied]: `Press ⌘/Ctrl+C to copy`, [CopyState.Copied]: 'Copied to clipboard!', }; return ( setCopied(CopyState.NotCopied)} copied={copied === CopyState.Copied} data-tip={strings[copied]} data-for={'copy-area'} /> ); };