File tree Expand file tree Collapse file tree 1 file changed +1
-27
lines changed
src/components/CopyCodeButton Expand file tree Collapse file tree 1 file changed +1
-27
lines changed Original file line number Diff line number Diff line change 1- import React , { useState } from 'react ' ;
1+ import { useState } from 'preact/hooks ' ;
22import CircleButton from "../CircleButton" ;
33
44interface CopyCodeButtonProps {
@@ -12,32 +12,6 @@ export const CopyCodeButton = ({ textToCopy }: CopyCodeButtonProps) => {
1212 console . log ( 'Copy button clicked' ) ;
1313 console . log ( 'Text to copy:' , textToCopy ) ;
1414
15- if ( ! navigator . clipboard ) {
16- console . log ( 'Clipboard API not available, using fallback' ) ;
17- // Fallback for older browsers
18- const textArea = document . createElement ( "textarea" ) ;
19- textArea . value = textToCopy ;
20- textArea . style . position = "fixed" ;
21- document . body . appendChild ( textArea ) ;
22- textArea . focus ( ) ;
23- textArea . select ( ) ;
24-
25- try {
26- const result = document . execCommand ( 'copy' ) ;
27- console . log ( 'Fallback copy result:' , result ) ;
28- setIsCopied ( true ) ;
29- setTimeout ( ( ) => {
30- setIsCopied ( false ) ;
31- console . log ( 'Copy state reset' ) ;
32- } , 2000 ) ;
33- } catch ( err ) {
34- console . error ( 'Fallback copy failed:' , err ) ;
35- }
36-
37- document . body . removeChild ( textArea ) ;
38- return ;
39- }
40-
4115 try {
4216 console . log ( 'Using Clipboard API' ) ;
4317 await navigator . clipboard . writeText ( textToCopy ) ;
You can’t perform that action at this time.
0 commit comments