Getting Started
Components
Preview
Code
# Hello World in Pythondef main():print("Hello, World!")if __name__ == "__main__":main()
Installation
CLI
Manual
pnpm dlx shadcn@latest add https://deltacomponents.dev/r/code-block.jsonUsage
import { CodeBlock } from "@/components/ui/code-block"
export default function Example() {
return (
<CodeBlock
code={`print("Hello, World!")`}
language="python"
filename="hello.py"
showLineNumbers={true}
/>
)
}Features
- Dual Mode: Package manager commands or syntax-highlighted code
- Syntax Highlighting: Powered by Prism with custom themes
- Package Manager Tabs: Support for npm, yarn, pnpm, and bun
- Copy to Clipboard: One-click copy functionality with visual feedback
- Line Numbers: Optional line numbering for code blocks
- Custom Themes: Light/dark adaptive themes with hover effects
- Terminal Styling: Command-line interface appearance
- Responsive: Horizontal scrolling for long content
- Flexible: Shows only provided package managers or code content
Examples
Package Manager Commands
Preview
Code
npm install @radix-ui/react-dropdown-menu
Interactive Theme Demo
Preview
Code
hello.go
1package main23import "fmt"45func main() {6 fmt.Println("Hello, World!")7}
API Reference
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| Package Manager Props | |||
| npm | string | - | npm command to display |
| yarn | string | - | yarn command to display |
| pnpm | string | - | pnpm command to display |
| bun | string | - | bun command to display |
| defaultPackageManager | PackageManager | "npm" | Default selected package manager |
| Code Highlighting Props | |||
| code | string | - | Code content to highlight |
| language | string | "typescript" | Programming language for syntax highlighting |
| filename | string | - | Filename to display in header |
| showLineNumbers | boolean | true | Whether to show line numbers |
| theme | PrismTheme | - | Custom Prism theme object |
| adaptiveTheme | object | - | Object with light and dark theme variants |
| General Props | |||
| className | string | - | Additional CSS classes for styling |
Types
type PackageManager = "npm" | "yarn" | "pnpm" | "bun"
interface AdaptiveTheme {
light: PrismTheme
dark: PrismTheme
}Theme Structure
Custom themes follow the Prism theme structure:
const customTheme: PrismTheme = {
plain: {
color: "#e6e6fa",
backgroundColor: "#1a1a2e",
},
styles: [
{
types: ["comment"],
style: {
color: "#6a7b9a",
fontStyle: "italic",
},
},
// ... more styles
],
}Build Better User Experiences
Discover open source components that make the difference in your applications. Copy, paste, and customize to create exceptional user interfaces.
Browse components