Componenteditors2.95 KB gzipZero dependencies

Code Block

Code snippet block with filename tab, language badge and copy button.

Preview

Live Preview
Open ↗

Installation

Tokens guide →

Add to your project via CLI (zero dependencies, code you own):

npx bigbullui add code-block

Or install the full npm package:

npm install bigbullui

Usage

tsx8 lines
import { CodeBlock } from "@/components/ui/code-block"; <CodeBlock  filename="server.ts"  language="typescript"  code={`import { createServer } from "node:http";\n\nconst server = createServer((req, res) => {\n  res.writeHead(200, { "Content-Type": "text/plain" });\n  res.end("Ticket Verified: ADMIT-01");\n});\n\nserver.listen(3000);`}  highlightLines={[4]}/>

Source code

code-block.tsx + 2 helpers

Zero third-party dependencies (3 local files shown in tabs below).

tsxcode-block.tsx438 lines
"use client"; import * as React from "react";import { cn } from "./lib/utils";import { useCopy } from "./lib/hooks"; export type CodeBlockVariant = "default" | "terminal" | "ticket"; export type CodeBlockProps = Omit<React.HTMLAttributes<HTMLDivElement>, "onCopy"> & {  /** The code string to display */  code: string;  /** Programming language or format (e.g. 'tsx', 'bash', 'json', 'rust') */  language?: string;  /** Filename or terminal title shown in the header tab */  filename?: string;  /** Whether to show line numbers initially (default: true) */  showLineNumbers?: boolean;  /** Whether user can click to toggle line numbers on/off (default: true) */

Props

Interactive Prop Playground

Tweak parsed AST props below to generate ready-to-paste JSX.

tsx3 lines
import { CodeBlock } from "@/components/ui/code-block"; <CodeBlock />
PropTypeDescription
codestringThe code string to display
languagestringProgramming language or format (e.g. 'tsx', 'bash', 'json', 'rust')
filenamestringFilename or terminal title shown in the header tab
showLineNumbersbooleanWhether to show line numbers initially (default: true)
allowToggleLineNumbersbooleanWhether user can click to toggle line numbers on/off (default: true)
highlightLinesnumber[]Specific 1-indexed line numbers to highlight
variantCodeBlockVariantVisual variant: 'default' | 'terminal' | 'ticket'
wordWrapbooleanWhether to wrap lines instead of horizontal scroll (default: false)
allowToggleWordWrapbooleanWhether user can click to toggle word wrap (default: true)
copyTimeoutnumberMilliseconds before copied feedback reverts (default: 2000)
maxHeightstring | numberOptional max height for code content (e.g. '400px')
showNotchesbooleanWhether to render ticket punch notches on the perforation edge (default: true)
serialstringTicket stub serial or reference label
onCopy(code: string) => voidCallback triggered when code is successfully copied