-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreusable-code.tsx
31 lines (26 loc) · 892 Bytes
/
reusable-code.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"use client";
import { Copy } from "lucide-react";
import { useState } from "react";
import { highlight } from "sugar-high";
import { cn } from "./lib/utils";
// This file allows you to provide custom React components
// to be used in MDX files. You can import and use any
export default function Code({ children, ...props }: any) {
const [copied, setCopied] = useState(false);
const handleCopy = () => {
navigator.clipboard.writeText(children);
setCopied(true);
setTimeout(() => setCopied(false), 2000);
};
const codeHTML = highlight(children);
return (
<div className="relative group border-2 p-4 rounded-md leading-tight">
<code
dangerouslySetInnerHTML={{ __html: codeHTML }}
className="hljs" // Ensure the highlight.js class is added
style={{}} // Adjust the line-height as needed
{...props}
/>
</div>
);
}