-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeBlock.tsx
More file actions
41 lines (39 loc) · 1.13 KB
/
CodeBlock.tsx
File metadata and controls
41 lines (39 loc) · 1.13 KB
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
32
33
34
35
36
37
38
39
40
41
import {Highlight, themes} from 'prism-react-renderer';
export function CodeBlock({
code,
language = 'tsx',
title,
compact = false,
}: {
code: string;
language?: string;
title?: string;
compact?: boolean;
}) {
const trimmed = code.trim();
return (
<div className="rounded-lg overflow-hidden border border-zinc-800 bg-zinc-950">
{title && (
<div className="px-3 py-1.5 bg-zinc-900 border-b border-zinc-800 text-xs text-zinc-400 font-mono">
{title}
</div>
)}
<Highlight theme={themes.nightOwl} code={trimmed} language={language}>
{({tokens, getLineProps, getTokenProps}) => (
<pre
className={`overflow-x-auto font-mono text-xs leading-relaxed ${compact ? 'p-3' : 'p-4'}`}
style={{background: 'transparent'}}
>
{tokens.map((line, i) => (
<div key={i} {...getLineProps({line})}>
{line.map((token, key) => (
<span key={key} {...getTokenProps({token})} />
))}
</div>
))}
</pre>
)}
</Highlight>
</div>
);
}