Skip to content

Commit 8220c90

Browse files
committed
feat: show tooltip when user hover or clicks copy icon in code blocks; closes #59
1 parent 4d49a9d commit 8220c90

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

src/components/DatasetDetailPage/LoadDatasetTabs.tsx

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,23 +104,33 @@ const LoadDatasetTabs: React.FC<LoadDatasetTabsProps> = ({
104104
language = "python",
105105
}: {
106106
code: string;
107-
language?: string; // optional prop
107+
language?: string;
108108
}) => {
109-
const handleCopy = () => {
110-
navigator.clipboard.writeText(code);
109+
// const handleCopy = () => {
110+
// navigator.clipboard.writeText(code);
111+
// };
112+
const [copied, setCopied] = useState(false);
113+
const handleCopy = async () => {
114+
try {
115+
await navigator.clipboard.writeText(code);
116+
setCopied(true);
117+
setTimeout(() => setCopied(false), 3000); // reset after 3s
118+
} catch (err) {
119+
console.error("Failed to copy:", err);
120+
}
111121
};
112122

113123
return (
114124
<Box sx={{ position: "relative" }}>
115-
<IconButton
116-
onClick={handleCopy}
117-
size="small"
118-
sx={{ position: "absolute", top: 5, right: 5 }}
119-
>
120-
<Tooltip title="Copy to clipboard">
125+
<Tooltip title={copied ? "Copied!" : "Copy to clipboard"}>
126+
<IconButton
127+
onClick={handleCopy}
128+
size="small"
129+
sx={{ position: "absolute", top: 5, right: 5 }}
130+
>
121131
<ContentCopyIcon fontSize="small" sx={{ color: Colors.green }} />
122-
</Tooltip>
123-
</IconButton>
132+
</IconButton>
133+
</Tooltip>
124134
<Box
125135
sx={{
126136
padding: { xs: "25px 20px 16px 16px", sm: "25px 20px 16px 16px" },

0 commit comments

Comments
 (0)