()
| 5 | import React, { useEffect, useState } from 'react' |
| 6 | |
| 7 | const CopyPasteButton = () => { |
| 8 | const [copied, setCopied] = useState(false) |
| 9 | const variants = { |
| 10 | hidden: { opacity: 0, scale: 0.5 }, |
| 11 | visible: { opacity: 1, scale: 1 }, |
| 12 | } |
| 13 | |
| 14 | useEffect(() => { |
| 15 | if (copied) { |
| 16 | setTimeout(() => { |
| 17 | setCopied(false) |
| 18 | }, 1000) |
| 19 | } |
| 20 | }, [copied]) |
| 21 | |
| 22 | return ( |
| 23 | <motion.button |
| 24 | whileTap={{ scale: 0.9, opacity: 0.8 }} |
| 25 | onClick={() => setCopied(!copied)} |
| 26 | className="rounded-lg border border-gray-100 bg-red-500 p-3 text-white" |
| 27 | > |
| 28 | <AnimatePresence mode="wait" initial={false}> |
| 29 | {copied ? ( |
| 30 | <motion.span |
| 31 | key="checkmark" |
| 32 | variants={variants} |
| 33 | initial="hidden" |
| 34 | animate="visible" |
| 35 | exit="hidden" |
| 36 | > |
| 37 | <Check size={16} /> |
| 38 | </motion.span> |
| 39 | ) : ( |
| 40 | <motion.span |
| 41 | key="copy" |
| 42 | variants={variants} |
| 43 | initial="hidden" |
| 44 | animate="visible" |
| 45 | exit="hidden" |
| 46 | > |
| 47 | <Copy size={16} /> |
| 48 | </motion.span> |
| 49 | )} |
| 50 | </AnimatePresence> |
| 51 | </motion.button> |
| 52 | ) |
| 53 | } |
| 54 | |
| 55 | export default CopyPasteButton |
nothing calls this directly
no outgoing calls
no test coverage detected