Componenteditors2.95 KB gzipZero dependencies
Code Block
Code snippet block with filename tab, language badge and copy button.
Preview
Live Preview
Installation
Tokens guide →Add to your project via CLI (zero dependencies, code you own):
npx bigbullui add code-blockOr install the full npm package:
npm install bigbulluiUsage
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 helpersZero 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 />| Prop | Type | Description |
|---|---|---|
| code | string | The code string to display |
| language | string | Programming language or format (e.g. 'tsx', 'bash', 'json', 'rust') |
| filename | string | Filename or terminal title shown in the header tab |
| showLineNumbers | boolean | Whether to show line numbers initially (default: true) |
| allowToggleLineNumbers | boolean | Whether user can click to toggle line numbers on/off (default: true) |
| highlightLines | number[] | Specific 1-indexed line numbers to highlight |
| variant | CodeBlockVariant | Visual variant: 'default' | 'terminal' | 'ticket' |
| wordWrap | boolean | Whether to wrap lines instead of horizontal scroll (default: false) |
| allowToggleWordWrap | boolean | Whether user can click to toggle word wrap (default: true) |
| copyTimeout | number | Milliseconds before copied feedback reverts (default: 2000) |
| maxHeight | string | number | Optional max height for code content (e.g. '400px') |
| showNotches | boolean | Whether to render ticket punch notches on the perforation edge (default: true) |
| serial | string | Ticket stub serial or reference label |
| onCopy | (code: string) => void | Callback triggered when code is successfully copied |