import React, { useState, useRef } from 'react' import Icon from './icon' import classes from '../styles/copy.module.sass' const CopyInput = ({ text, prefix }) => { const isClient = typeof window !== 'undefined' const supportsCopy = isClient && document.queryCommandSupported('copy') const textareaRef = useRef() const [copySuccess, setCopySuccess] = useState(false) function copyToClipboard() { if (textareaRef.current && isClient) { textareaRef.current.select() document.execCommand('copy') setCopySuccess(true) textareaRef.current.blur() setTimeout(() => setCopySuccess(false), 1000) } } function selectText() { if (textareaRef.current && isClient) { textareaRef.current.select() } } return (
{prefix && {prefix}}