From 62082f38e92ddef74e6c3e387921136df955f8f1 Mon Sep 17 00:00:00 2001 From: Bhaumik Maan <82998871+bhaumikmaan@users.noreply.github.com> Date: Mon, 7 Apr 2025 17:23:48 +0530 Subject: [PATCH] Added copy functionality in solutions page (#32) Added copy button to solution code blocks - Implement copy to clipboard functionality in SolutionSection component - Add visual feedback when code is copied ("Copy" changes to "Copied!") - Auto-reset copy state after 2 seconds - Position button in top-right corner with hover effects - Maintain existing component functionality credits to @bhaumikmaan --- src/_pages/Solutions.tsx | 87 ++++++++++++++++++++++++---------------- 1 file changed, 53 insertions(+), 34 deletions(-) diff --git a/src/_pages/Solutions.tsx b/src/_pages/Solutions.tsx index 019bf6f..ac71900 100644 --- a/src/_pages/Solutions.tsx +++ b/src/_pages/Solutions.tsx @@ -48,41 +48,60 @@ const SolutionSection = ({ content: React.ReactNode isLoading: boolean currentLanguage: string -}) => ( -
- Loading solutions... -
+}) => { + const [copied, setCopied] = useState(false) + + const copyToClipboard = () => { + if (typeof content === "string") { + navigator.clipboard.writeText(content).then(() => { + setCopied(true) + setTimeout(() => setCopied(false), 2000) + }) + } + } + + return ( ++ Loading solutions... +
+