Skip to content

Commit c251659

Browse files
committed
ww
1 parent b4b7159 commit c251659

File tree

4 files changed

+56
-3
lines changed

4 files changed

+56
-3
lines changed

www/next.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ const nextConfig = {
7878
const opts = {
7979
components: { code: "Code" },
8080
syntaxHighlighting: {
81-
theme: "github-dark",
81+
theme: "github-dark-dimmed",
8282
},
8383
lineNumbers: false,
8484
showCopyButton: true,

www/src/app/globals.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,16 @@ body {
108108
@apply m-0 text-sm;
109109
}
110110
}
111+
112+
/* add the code bellow */
113+
@layer utilities {
114+
/* Hide scrollbar for Chrome, Safari and Opera */
115+
.no-scrollbar::-webkit-scrollbar {
116+
display: none;
117+
}
118+
/* Hide scrollbar for IE, Edge and Firefox */
119+
.no-scrollbar {
120+
-ms-overflow-style: none; /* IE and Edge */
121+
scrollbar-width: none; /* Firefox */
122+
}
123+
}

www/src/components/code.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
import {Pre, RawCode, highlight} from 'codehike/code';
22

3+
import {CopyButton} from './copy-button';
4+
35
export async function Code({codeblock}: {codeblock: RawCode}) {
4-
const highlighted = await highlight(codeblock, 'github-dark');
6+
const highlighted = await highlight(codeblock, 'github-dark-dimmed');
57
return (
6-
<Pre code={highlighted} handlers={[]} className="border border-zinc-800" />
8+
<div className="relative not-prose mb-3">
9+
<CopyButton
10+
text={highlighted.code}
11+
className="absolute right-px top-px bg-black p-2 rounded-lg"
12+
/>
13+
14+
<Pre
15+
code={highlighted}
16+
handlers={[]}
17+
className="border pl-3 pr-12 py-2 rounded-lg overflow-auto bg-black text-sm no-scrollbar"
18+
/>
19+
</div>
720
);
821
}

www/src/components/copy-button.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'use client';
2+
3+
import {ComponentProps, useState} from 'react';
4+
5+
import {Copy, Check} from 'lucide-react';
6+
7+
export type CopyButtonProps = ComponentProps<'button'> & {
8+
text: string;
9+
};
10+
11+
export function CopyButton(props: CopyButtonProps) {
12+
const {text, ...buttonProps} = props;
13+
const [copied, setCopied] = useState(false);
14+
15+
return (
16+
<button
17+
{...buttonProps}
18+
aria-label="Copy to clipboard"
19+
onClick={() => {
20+
navigator.clipboard.writeText(text);
21+
setCopied(true);
22+
setTimeout(() => setCopied(false), 1200);
23+
}}>
24+
{copied ? <Check size={16} /> : <Copy size={16} />}
25+
</button>
26+
);
27+
}

0 commit comments

Comments
 (0)