Componenteditors0.94 KB gzipZero dependencies
Code Editor
Code editor: line-number gutter, Tab insertion, scroll sync.
Preview
Live Preview
Installation
Tokens guide →Add to your project via CLI (zero dependencies, code you own):
npx bigbullui add code-editorOr install the full npm package:
npm install bigbulluiUsage
tsx3 lines
import { CodeEditor } from "@/components/ui/code-editor"; <CodeEditor />Source code
code-editor.tsx + 1 helperZero third-party dependencies (2 local files shown in tabs below).
tsxcode-editor.tsx75 lines
"use client"; import * as React from "react";import { cn } from "./lib/utils"; export interface CodeEditorProps extends React.HTMLAttributes<HTMLDivElement> { value?: string; defaultValue?: string; onValueChange?: (value: string) => void; language?: string; readonly?: boolean;} /** Code editor with line numbers: overlay textarea + gutter. */export function CodeEditor({ value, defaultValue = "", onValueChange, language = "ts", readonly, className, ...props }: CodeEditorProps) { const [internal, setInternal] = React.useState(defaultValue); const [focused, setFocused] = React.useState(false); const textRef = React.useRef<HTMLTextAreaElement>(null);Props
Interactive Prop Playground
Tweak parsed AST props below to generate ready-to-paste JSX.
tsx3 lines
import { CodeEditor } from "@/components/ui/code-editor"; <CodeEditor />| Prop | Type | Description |
|---|---|---|
| value | string | Controlled value. |
| defaultValue | string | Initial value when uncontrolled. (Default: "") |
| onValueChange | (value: string) => void | Callback invoked on value change. |
| language | string | Configures language. (Default: "ts") |
| readonly | boolean | Toggles readonly. |