({ code })
| 53 | } |
| 54 | |
| 55 | function CopyButton({ code }) { |
| 56 | let [copyCount, setCopyCount] = useState(0) |
| 57 | let copied = copyCount > 0 |
| 58 | |
| 59 | useEffect(() => { |
| 60 | if (copyCount > 0) { |
| 61 | let timeout = setTimeout(() => setCopyCount(0), 1000) |
| 62 | return () => { |
| 63 | clearTimeout(timeout) |
| 64 | } |
| 65 | } |
| 66 | }, [copyCount]) |
| 67 | |
| 68 | return ( |
| 69 | <button |
| 70 | type="button" |
| 71 | className={clsx( |
| 72 | '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', |
| 73 | copied |
| 74 | ? 'bg-blue-400/10 ring-1 ring-inset ring-blue-400/20' |
| 75 | : 'bg-white/5 hover:bg-white/7.5 dark:bg-white/2.5 dark:hover:bg-white/5', |
| 76 | )} |
| 77 | onClick={() => { |
| 78 | window.navigator.clipboard.writeText(code).then(() => { |
| 79 | setCopyCount((count) => count + 1) |
| 80 | }) |
| 81 | }} |
| 82 | > |
| 83 | <span |
| 84 | aria-hidden={copied} |
| 85 | className={clsx( |
| 86 | 'pointer-events-none flex items-center gap-0.5 text-zinc-400 transition duration-300', |
| 87 | copied && '-translate-y-1.5 opacity-0', |
| 88 | )} |
| 89 | > |
| 90 | <ClipboardIcon className="h-5 w-5 fill-zinc-500/20 stroke-zinc-500 transition-colors group-hover/button:stroke-zinc-400" /> |
| 91 | Copy |
| 92 | </span> |
| 93 | <span |
| 94 | aria-hidden={!copied} |
| 95 | className={clsx( |
| 96 | 'pointer-events-none absolute inset-0 flex items-center justify-center text-blue-400 transition duration-300', |
| 97 | !copied && 'translate-y-1.5 opacity-0', |
| 98 | )} |
| 99 | > |
| 100 | Copied! |
| 101 | </span> |
| 102 | </button> |
| 103 | ) |
| 104 | } |
| 105 | |
| 106 | function CodePanelHeader({ tag, label }) { |
| 107 | if (!tag && !label) { |
nothing calls this directly
no outgoing calls
no test coverage detected