({ code }: { code: string })
| 62 | } |
| 63 | |
| 64 | function CopyButton({ code }: { code: string }) { |
| 65 | let [copyCount, setCopyCount] = useState(0); |
| 66 | let copied = copyCount > 0; |
| 67 | |
| 68 | useEffect(() => { |
| 69 | if (copyCount > 0) { |
| 70 | let timeout = setTimeout(() => setCopyCount(0), 1000); |
| 71 | return () => { |
| 72 | clearTimeout(timeout); |
| 73 | }; |
| 74 | } |
| 75 | }, [copyCount]); |
| 76 | |
| 77 | return ( |
| 78 | <button |
| 79 | type="button" |
| 80 | className={clsx( |
| 81 | 'group/button absolute right-4 top-3.5 overflow-hidden rounded-full py-1 pl-2 pr-3 text-2xs font-medium opacity-0 backdrop-blur transition focus:opacity-100 group-hover:opacity-100', |
| 82 | copied |
| 83 | ? 'bg-[#19182E]/10 ring-1 ring-inset ring-[#1E1E3F]/20' |
| 84 | : 'bg-white/5 hover:bg-white/7.5 dark:bg-white/2.5 dark:hover:bg-white/5' |
| 85 | )} |
| 86 | onClick={() => { |
| 87 | window.navigator.clipboard.writeText(code).then(() => { |
| 88 | setCopyCount(count => count + 1); |
| 89 | }); |
| 90 | }} |
| 91 | > |
| 92 | <span |
| 93 | aria-hidden={copied} |
| 94 | className={clsx( |
| 95 | 'pointer-events-none flex items-center gap-0.5 text-zinc-400 transition duration-300', |
| 96 | copied && '-translate-y-1.5 opacity-0' |
| 97 | )} |
| 98 | > |
| 99 | <ClipboardIcon className="h-5 w-5 fill-zinc-500/20 stroke-zinc-500 transition-colors group-hover/button:stroke-zinc-400" /> |
| 100 | Copy |
| 101 | </span> |
| 102 | <span |
| 103 | aria-hidden={!copied} |
| 104 | className={clsx( |
| 105 | 'pointer-events-none absolute inset-0 flex items-center justify-center text-[#fad000] transition duration-300', |
| 106 | !copied && 'translate-y-1.5 opacity-0' |
| 107 | )} |
| 108 | > |
| 109 | Copied! |
| 110 | </span> |
| 111 | </button> |
| 112 | ); |
| 113 | } |
| 114 | |
| 115 | function CodePanelHeader({ tag, label }: { tag?: string; label?: string }) { |
| 116 | if (!tag && !label) { |
nothing calls this directly
no outgoing calls
no test coverage detected