Added tracking code form.

This commit is contained in:
Mike Cao 2020-08-07 20:36:57 -07:00
parent c4b75e4aec
commit 58a1be7a30
27 changed files with 100 additions and 42 deletions

View file

@ -0,0 +1,23 @@
import React, { useState } from 'react';
import Button from './Button';
const defaultText = 'Copy to clipboard';
export default function CopyButton({ element, ...props }) {
const [text, setText] = useState(defaultText);
function handleClick() {
if (element?.current) {
element.current.select();
document.execCommand('copy');
setText('Copied!');
window.getSelection().removeAllRanges();
}
}
return (
<Button {...props} onClick={handleClick}>
{text}
</Button>
);
}