Code Editor
A composable code editor built on CodeMirror, with a controlled document, toolbar, status bar and extension declarations.
Preview
Installation
Add the item with the shadcn CLI, or copy the source manually.
pnpm dlx shadcn@latest add litingyes/blocove/code-editorRequires a shadcn/ui project set up with Base UI primitives. Blocove is developed against the b0 preset, but it installs no base config or theme tokens: your own preset, fonts and colors stay in place.
Or install from the namespace after adding the registry: npx shadcn@latest add @blocove/code-editor
This example also uses: code-editor-shikicode-editor-languagescode-editor-line-numbers
pnpm dlx shadcn@latest add litingyes/blocove/code-editor-shiki litingyes/blocove/code-editor-languages litingyes/blocove/code-editor-line-numbersUsage
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 ( <CodeEditor value={code} onChange={setCode} language="tsx" className="h-72" > <CodeEditorShiki /> <CodeEditorToolbar /> <CodeEditorContent /> <CodeEditorStatusBar /> </CodeEditor> )}API Reference
Props accepted by the exported components.
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.
This component accepts no custom props.