Skip to content

Commit 81fc410

Browse files
committed
feat: enhance codeblock component with improved styling and additional language support
1 parent b1992a7 commit 81fc410

3 files changed

Lines changed: 22 additions & 16 deletions

File tree

src/components/codeblock/copyToClipboard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const CopyToClipboardBtn = (props: CopyToClipboardBtnProps) => {
3535
onMouseEnter={() => controls.start("animate")}
3636
onMouseLeave={() => controls.start("normal")}
3737
onClick={() => handleCopy()}
38-
className="text-neutral-500 transition-colors hover:text-black focus:outline-none dark:text-neutral-400 dark:hover:text-white"
38+
className="text-neutral-500 cursor-pointer transition-colors hover:text-black focus:outline-none dark:text-neutral-400 dark:hover:text-white"
3939
>
4040
<svg
4141
xmlns="http://www.w3.org/2000/svg"

src/components/codeblock/mdx.tsx

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
"use client";
2-
3-
import { type HTMLProps } from "react";
4-
1+
import type { HTMLProps } from "react";
52
import { FileIcon } from "lucide-react";
3+
64
import CopyToClipboardBtn from "./copyToClipboard";
75
import { Languages } from "./settings";
86

@@ -19,11 +17,14 @@ const CodeblockMDX = (props: PreProps) => {
1917
} = props;
2018
const selectedLanguage = Languages.find((lang) => lang.name === dataLanguage);
2119
return (
22-
<div className="relative">
23-
<div className="flex items-center justify-between rounded-t-md border-t border-r border-l border-neutral-200 px-1.5 py-1 dark:border-neutral-800 dark:bg-neutral-800/40">
20+
<section className="not-prose pb-2">
21+
<div className="flex items-center justify-between rounded-t-md border-t border-r border-l border-neutral-200 px-1.5 py-1 dark:border-neutral-800 dark:bg-neutral-800/40 bg-neutral-200/40">
2422
<div className="flex items-center space-x-2 text-neutral-500 dark:text-neutral-400">
2523
{selectedLanguage?.icon ? (
26-
<selectedLanguage.icon className="h-[18px] w-[18px]" />
24+
<selectedLanguage.icon
25+
className="h-[18px] w-[18px]"
26+
aria-description={dataLanguage}
27+
/>
2728
) : (
2829
<FileIcon size={14} />
2930
)}
@@ -33,13 +34,10 @@ const CodeblockMDX = (props: PreProps) => {
3334
</div>
3435
<CopyToClipboardBtn content={rawstring || ""} />
3536
</div>
36-
<pre
37-
className="overflow-x-auto rounded-t-none bg-transparent"
38-
{...props}
39-
>
40-
{children}
41-
</pre>
42-
</div>
37+
<div className="max-h-64 overflow-y-auto rounded-b-md border border-neutral-200 p-3 dark:border-neutral-800">
38+
<pre {...props}>{children}</pre>
39+
</div>
40+
</section>
4341
);
4442
};
4543

src/components/codeblock/settings.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
import { Js, Reactts, Reactjs, Shell, TypeScript } from "@react-symbols/icons";
1+
import { Js, Reactts, Reactjs, Shell, TypeScript, BracketsBlue } from "@react-symbols/icons";
22

33
export const Languages = [
44
{
55
name: "bash",
66
icon: Shell,
77
},
8+
{
9+
name: "shell",
10+
icon: Shell,
11+
},
812
{
913
name: "jsx",
1014
icon: Reactjs,
@@ -21,4 +25,8 @@ export const Languages = [
2125
name: "js",
2226
icon: Js,
2327
},
28+
{
29+
name: "css",
30+
icon: BracketsBlue
31+
}
2432
];

0 commit comments

Comments
 (0)