11"use client" ;
22
3- import { useState } from ' react' ;
4- import { MdContentCopy , MdCheck } from ' react-icons/md' ;
5- import { Tooltip } from ' react-tooltip' ;
3+ import { useState } from " react" ;
4+ import { MdContentCopy , MdCheck } from " react-icons/md" ;
5+ import { Tooltip } from " react-tooltip" ;
66
77interface CopyButtonProps {
88 text : string ;
@@ -20,7 +20,12 @@ export default function CopyButton({ text, title = "Copy to clipboard", classNam
2020 await navigator . clipboard . writeText ( text ) ;
2121 setCopied ( true ) ;
2222 setTimeout ( ( ) => setCopied ( false ) , 2000 ) ;
23- } catch ( err ) {
23+ } catch ( err : unknown ) {
24+ if ( err instanceof Error ) {
25+ console . error ( err . message ) ;
26+ } else {
27+ console . error ( "An unknown error occurred" ) ;
28+ }
2429 // Fallback for older browsers
2530 const textArea = document . createElement ( "textarea" ) ;
2631 textArea . value = text ;
@@ -42,17 +47,9 @@ export default function CopyButton({ text, title = "Copy to clipboard", classNam
4247 data-tooltip-id = { buttonId }
4348 data-tooltip-content = { copied ? "Copied!" : title }
4449 >
45- { copied ? (
46- < MdCheck className = "w-4 h-4 text-green-600" />
47- ) : (
48- < MdContentCopy className = "w-4 h-4 text-gray-500" />
49- ) }
50+ { copied ? < MdCheck className = "w-4 h-4 text-green-600" /> : < MdContentCopy className = "w-4 h-4 text-gray-500" /> }
5051 </ button >
51- < Tooltip
52- id = { buttonId }
53- place = "top"
54- className = { copied ? "!bg-green-600" : "" }
55- />
52+ < Tooltip id = { buttonId } place = "top" className = { copied ? "!bg-green-600" : "" } />
5653 </ >
5754 ) ;
58- }
55+ }
0 commit comments