|
@@ -1,5 +1,8 @@
|
|
|
import React, { useRef, useState } from "react";
|
|
|
|
|
|
+const tooltipClass = "click-to-copy__tooltip";
|
|
|
+const tooltipVisClass = `${tooltipClass}--visible`;
|
|
|
+
|
|
|
export default ({ text }) => {
|
|
|
const textareaRef = useRef(null);
|
|
|
const [hovered, setHovered] = useState(false);
|
|
@@ -10,43 +13,24 @@ export default ({ text }) => {
|
|
|
setCopied(true);
|
|
|
};
|
|
|
|
|
|
+ const hoveredClass = hovered ? tooltipVisClass : "";
|
|
|
+
|
|
|
return (
|
|
|
- <div
|
|
|
- style={{
|
|
|
- position: "relative",
|
|
|
- display: "flex",
|
|
|
- justifyContent: "center",
|
|
|
- }}
|
|
|
- >
|
|
|
+ <div className="click-to-copy">
|
|
|
<span
|
|
|
- style={{ borderBottom: "1px dotted black" }}
|
|
|
+ className="click-to-copy__text"
|
|
|
onClick={copyText}
|
|
|
- onMouseOver={() => setHovered(true)}
|
|
|
- onMouseOut={() => {setHovered(false); setCopied(false)}}
|
|
|
+ onMouseOver={() => {setCopied(false); setHovered(true)}}
|
|
|
+ onMouseOut={() => setHovered(false)}
|
|
|
>
|
|
|
{text}
|
|
|
</span>
|
|
|
- <span
|
|
|
- style={{
|
|
|
- display: hovered ? "block" : "none",
|
|
|
- visibility: hovered ? "visible" : "hidden",
|
|
|
- backgroundColor: "black",
|
|
|
- color: "#fff",
|
|
|
- textAlign: "center",
|
|
|
- padding: "2px 8px",
|
|
|
- borderRadius: "8px",
|
|
|
- position: "absolute",
|
|
|
- zIndex: 1,
|
|
|
- top: "-115%",
|
|
|
- whiteSpace: "nowrap",
|
|
|
- opacity: ".85",
|
|
|
- }}
|
|
|
- >
|
|
|
+ <span className={`${tooltipClass} ${hoveredClass}`}>
|
|
|
{copied ? "Copied!" : "Click to Copy"}
|
|
|
</span>
|
|
|
<textarea
|
|
|
ref={textareaRef}
|
|
|
- style={{ position: "absolute", top: "-1000px" }}
|
|
|
+ className="click-to-copy__textarea"
|
|
|
value={text}
|
|
|
readOnly
|
|
|
/>
|