Code Block

React code block with zero dependency syntax coloring, a language tag, optional filename and line numbers, and a copy button that confirms Copied.

src/registry/ui/code-block.tsx/r/code-block.json

Installation#

bash
npx shadcn@latest add @minidev/code-block

MiniDev UI is in the shadcn registry directory, so the short form works with no setup. Older CLI versions can use the full URL: npx shadcn@latest add https://ui.minidev.pro/r/code-block.json

Usage#

tsx
import { CodeBlock } from "@/components/ui/code-block"

export function Example() {
  return (
    <CodeBlock className="max-w-lg" code={demoCode} />
  )
}

API reference#

CodeBlock props
PropTypeDefault
codestringSAMPLE_CODE
languagestring"tsx"
filenamestring-
classNamestring-
showLineNumbersbooleanfalse

Dependencies#

npm

lucide-react

Built from

No other MiniDev files

Examples#

All Developer tool UI components for React

Learn more