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
main
Bhaumik Maan 2 years ago committed by GitHub
parent 62dcb536ac
commit 62082f38e9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -48,8 +48,20 @@ const SolutionSection = ({
content: React.ReactNode
isLoading: boolean
currentLanguage: string
}) => (
<div className="space-y-2">
}) => {
const [copied, setCopied] = useState(false)
const copyToClipboard = () => {
if (typeof content === "string") {
navigator.clipboard.writeText(content).then(() => {
setCopied(true)
setTimeout(() => setCopied(false), 2000)
})
}
}
return (
<div className="space-y-2 relative">
<h2 className="text-[13px] font-medium text-white tracking-wide">
{title}
</h2>
@ -62,7 +74,13 @@ const SolutionSection = ({
</div>
</div>
) : (
<div className="w-full">
<div className="w-full relative">
<button
onClick={copyToClipboard}
className="absolute top-2 right-2 text-xs text-white bg-white/10 hover:bg-white/20 rounded px-2 py-1 transition"
>
{copied ? "Copied!" : "Copy"}
</button>
<SyntaxHighlighter
showLineNumbers
language={currentLanguage == "golang" ? "go" : currentLanguage}
@ -82,7 +100,8 @@ const SolutionSection = ({
</div>
)}
</div>
)
)
}
export const ComplexitySection = ({
timeComplexity,

Loading…
Cancel
Save