# Code Editor A composable code editor built on CodeMirror, with a controlled document, toolbar, status bar and extension declarations. ## Installation ```bash npx shadcn@latest add litingyes/blocove/code-editor ``` This example also uses: `code-editor-shiki`, `code-editor-languages`, `code-editor-line-numbers`. ```bash npx shadcn@latest add litingyes/blocove/code-editor-shiki litingyes/blocove/code-editor-languages litingyes/blocove/code-editor-line-numbers ``` ## Usage ### Controlled ```tsx import { useState } from "react" import { CodeEditor, CodeEditorContent, CodeEditorStatusBar, CodeEditorToolbar } from "@/components/blocove/code-editor/editor" import { CodeEditorShiki } from "@/components/blocove/code-editor/shiki" export function Example() { const [code, setCode] = useState('const answer = 42') return ( ) } ``` ## API Reference ### CodeEditor Editor root. Registers the extensions declared by its children and owns the controlled document. | Prop | Type | Default | | --- | --- | --- | | `value` | `string` | - | | `defaultValue` | `string` | - | | `onChange` | `(value: string) => void` | - | | `language` | `string` | - | | `placeholder` | `string` | `Type some code…` | | `editable` | `boolean` | `true` | | `readOnly` | `boolean` | `false` | | `autoFocus` | `boolean` | `false` | | `lineWrapping` | `boolean` | `false` | | `onLineWrappingChange` | `(lineWrapping: boolean) => void` | - | | `extensions` | `Extension` | - | | `onReady` | `(view: EditorView) => void` | - | | `className` | `string` | - | | `children` | `ReactNode` | - | ### CodeEditorContent The editable surface. Creates the CodeMirror view, or hands the container to the surface a declaration asked for — the split diff renders two editors there. | Prop | Type | Default | | --- | --- | --- | | `className` | `string` | - | ### CodeEditorToolbar Toolbar with the history controls, the line wrapping toggle and a copy action. Item controls can be passed as children. | Prop | Type | Default | | --- | --- | --- | | `className` | `string` | - | | `children` | `ReactNode` | - | ### CodeEditorStatusBar Cursor position, selection length and the language set on the root. | Prop | Type | Default | | --- | --- | --- | | `className` | `string` | - | ### useCodeEditor Returns the editor context: the view, the resolved configuration and the wrapping state. Use `useCodeEditorState` to re-render a control when the editor state changes. ## Registry dependencies - `litingyes/blocove/code-editor-extension` - `button` - `toggle` - `tooltip` Namespace: `npx shadcn@latest add @blocove/code-editor`