-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcode-block.tsx
More file actions
113 lines (103 loc) · 2.15 KB
/
code-block.tsx
File metadata and controls
113 lines (103 loc) · 2.15 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import type { ComponentProps } from "react";
import { cn } from "@/utils/cn";
import { FileIcon } from "@react-symbols/icons/utils";
const CodeBlock = ({
children,
className,
...props
}: ComponentProps<"div">) => {
return (
<div
className={cn(
"not-prose",
"flex w-full flex-col overflow-clip rounded-lg shadow-xs",
"bg-neutral-200/40 dark:bg-neutral-800/70",
"border border-neutral-200 dark:border-neutral-800",
"text-neutral-950 dark:text-neutral-50",
className,
)}
{...props}
>
{children}
</div>
);
};
type CodeBlockHeaderProps = ComponentProps<"div">;
const CodeBlockHeader = ({
children,
className,
...props
}: CodeBlockHeaderProps) => {
return (
<div
className={cn(
"not-prose", // Disable Markdown Styles
"flex h-9 items-center justify-between px-2 py-1.5",
"text-sm text-neutral-600 dark:text-neutral-400",
className,
)}
{...props}
>
{children}
</div>
);
};
interface CodeBlockIconProps extends ComponentProps<"div"> {
language?: string;
}
const CodeBlockIcon = ({ language, className }: CodeBlockIconProps) => {
return (
<FileIcon
width={16}
height={16}
fileName={`.${language ?? ""}`}
autoAssign={true}
className={cn(className)}
/>
);
};
type CodeBlockGroupProps = ComponentProps<"div">;
const CodeBlockGroup = ({
children,
className,
...props
}: CodeBlockGroupProps) => {
return (
<div
className={cn(
"flex items-center space-x-2",
"text-sm text-neutral-600 dark:text-neutral-400",
className,
)}
{...props}
>
{children}
</div>
);
};
const CodeBlockContent = ({
className,
children,
...props
}: ComponentProps<"div">) => {
return (
<div
className={cn(
"max-h-96 overflow-y-auto",
"bg-white dark:bg-neutral-900",
"rounded-lg font-mono text-sm leading-5 whitespace-pre",
className,
)}
{...props}
>
{children}
</div>
);
};
export {
CodeBlock,
CodeBlockHeader,
CodeBlockIcon,
CodeBlockGroup,
CodeBlockContent,
};