({ code })
| 15 | } |
| 16 | |
| 17 | export const CodeBlock: React.FC<Props> = ({ code }) => { |
| 18 | const [label, setLabel] = useState<string>("Copy code"); |
| 19 | const copyToClipboard = (text: string) => { |
| 20 | const el = document.createElement("textarea"); |
| 21 | el.value = text; |
| 22 | document.body.appendChild(el); |
| 23 | el.select(); |
| 24 | document.execCommand("copy"); |
| 25 | document.body.removeChild(el); |
| 26 | }; |
| 27 | |
| 28 | const handleCopyClick = () => { |
| 29 | copyToClipboard(code); |
| 30 | setLabel("Copied!"); |
| 31 | |
| 32 | setTimeout(() => { |
| 33 | setLabel("Copy code"); |
| 34 | }, 1000); |
| 35 | }; |
| 36 | |
| 37 | return ( |
| 38 | <pre> |
| 39 | <div className="bg-black rounded-md mb-4"> |
| 40 | <div className="flex items-center relative text-gray-200 bg-gray-800 px-4 py-2 text-xs font-sans justify-between rounded-t-md"> |
| 41 | <div className="flex"> |
| 42 | <span>mermaid</span> |
| 43 | <HoverCard> |
| 44 | <HoverCardTrigger> |
| 45 | <HelpCircle className="mx-2 h-4 w-4 cursor-pointer" /> |
| 46 | </HoverCardTrigger> |
| 47 | <HoverCardContent> |
| 48 | <div className="space-y-2"> |
| 49 | <p className="text-xs text-slate-500"> |
| 50 | Learn more about{" "} |
| 51 | <Link |
| 52 | href="https://mermaid.js.org/config/Tutorials.html" |
| 53 | target="_blank" |
| 54 | rel="noreferrer" |
| 55 | className="underline" |
| 56 | > |
| 57 | Mermaid.JS |
| 58 | </Link> |
| 59 | . |
| 60 | </p> |
| 61 | </div> |
| 62 | </HoverCardContent> |
| 63 | </HoverCard> |
| 64 | </div> |
| 65 | <div className="flex"> |
| 66 | <Link |
| 67 | href={`https://mermaid.live/edit#pako:${serializeCode(code)}`} |
| 68 | target="_blank" |
| 69 | rel="noreferrer" |
| 70 | className="flex ml-auto gap-1 mr-4" |
| 71 | > |
| 72 | <Edit className="h-4 w-4" /> Edit |
| 73 | </Link> |
| 74 | <button className="flex ml-auto gap-1" onClick={handleCopyClick}> |
nothing calls this directly
no test coverage detected