shadimage
slide-cn
componentcode-blocksource: ok · hit

Code block

A code block component with syntax highlighting

npx shadcn add "https://slide-cn.com/r/code-block.json"
free

Visual style

terminal-mono

Tags auto-generated by rules on 9/24/2026 — empty means no evidence, not lack of support.

Dependencies

Bundle weight · light
react-syntax-highlighter@types/react-syntax-highlighter

Files1 · source cached 10/14/2026, 11:28:58 AM

components/ui/slide-cn/code-block.tsx
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter"
import { vscDarkPlus } from "react-syntax-highlighter/dist/esm/styles/prism"


/**
 * CodeBlock
 *
 * Presentational component for rendering syntax-highlighted code snippets.
 *
 * Responsibilities:
 * - Renders static code content with syntax highlighting
 * - Handles language selection and optional line numbers
 *
 * Usage:
 * ```tsx
 * <CodeBlock
 *   code={`const x = 42`}
 *   language="typescript"
 * />
 * ```
 *
 * Notes:
 * - Intended for display only (not editable)
 * - Does not handle copy-to-clipboard or live execution
 */


interface CodeBlockProps {
	code: string
	language?: string
	showLineNumbers?: boolean
}

export function CodeBlock({
	code,
	language = "javascript",
	showLineNumbers = true,
}: CodeBlockProps) {
	return (
		<div className="w-full text-sm">
			<SyntaxHighlighter
				language={language}
				style={vscDarkPlus}
				showLineNumbers={showLineNumbers}
				customStyle={{
					margin: 0,
					borderRadius: "0.5rem",
					padding: "1.5rem",
				}}
			>
				{code}
			</SyntaxHighlighter>
		</div>
	)
}

More from slide-cn

Browse all components in this library →