Rename signature to be more generic (and less wrong); Make copyable accept children

This commit is contained in:
Nick Brown
2020-04-17 22:58:56 -07:00
committed by Michael Vines
parent 0cef795107
commit 459b4d06fe
5 changed files with 46 additions and 37 deletions

View File

@@ -0,0 +1,36 @@
import React, { useState, ReactNode } from "react";
type CopyableProps = {
text: string
children: ReactNode
}
const popover = (
<div className="popover fade bs-popover-right show">
<div className="arrow" />
<div className="popover-body">Copied!</div>
</div>
);
function Copyable({ text, children }: CopyableProps) {
const [showPopover, setShowPopover] = useState(false);
const copyToClipboard = () => navigator.clipboard.writeText(text);
const handleClick = () =>
copyToClipboard()
.then(() => {
setShowPopover(true);
setTimeout(setShowPopover.bind(null, false), 2500);
});
return (
<div className="copyable">
<div onClick={handleClick}>
{children}
</div>
{showPopover && popover}
</div>
);
}
export default Copyable;