mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-24 00:52:24 +00:00
The customStyle background only reaches the <pre>, so the prism theme's own background stayed on the inner <code>. In dark mode that left a white card with a dark box hugging every line. Let the block inherit the themed surface from its wrapper instead.
50 lines
1.5 KiB
TypeScript
50 lines
1.5 KiB
TypeScript
import { useState } from "react";
|
|
import { CheckIcon, ClipboardIcon } from "lucide-react";
|
|
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
|
|
import { oneLight } from "react-syntax-highlighter/dist/esm/styles/prism";
|
|
|
|
import { useSyntaxTheme } from "@/hooks/useSyntaxTheme";
|
|
|
|
interface CodeBlockProps {
|
|
code: string;
|
|
language: string;
|
|
}
|
|
|
|
const CodeBlock = ({ code, language }: CodeBlockProps) => {
|
|
const syntaxTheme = useSyntaxTheme(oneLight);
|
|
const [copied, setCopied] = useState(false);
|
|
const copyToClipboard = () => {
|
|
navigator.clipboard.writeText(code);
|
|
setCopied(true);
|
|
setTimeout(() => setCopied(false), 2000);
|
|
};
|
|
|
|
return (
|
|
<div className="relative rounded-lg border border-border bg-muted overflow-hidden">
|
|
<button
|
|
onClick={copyToClipboard}
|
|
className="absolute top-3 right-3 p-2 rounded-md border border-border bg-background text-muted-foreground hover:bg-accent hover:text-foreground z-raised"
|
|
aria-label="Copy code"
|
|
>
|
|
{copied ? <CheckIcon size={16} /> : <ClipboardIcon size={16} />}
|
|
</button>
|
|
<SyntaxHighlighter
|
|
language={language}
|
|
style={syntaxTheme}
|
|
customStyle={{
|
|
margin: 0,
|
|
padding: "1.5rem",
|
|
borderRadius: "0.5rem",
|
|
fontSize: "0.9rem",
|
|
background: "transparent",
|
|
}}
|
|
codeTagProps={{ style: { background: "transparent" } }}
|
|
showLineNumbers
|
|
>
|
|
{code}
|
|
</SyntaxHighlighter>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default CodeBlock;
|