Code Editor

A composable code editor built on CodeMirror, with a controlled document, toolbar, status bar and extension declarations.

UIcode-editorView JSON

Preview

Ln 1, Col 1tsx
Ln 1, Col 1Read onlytsx

Installation

Add the item with the shadcn CLI, or copy the source manually.

pnpm dlx shadcn@latest add litingyes/blocove/code-editor

Requires 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-numbers

Usage

Controlled
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.

PropTypeDefault
valuestring-
defaultValuestring-
onChange(value: string) => void-
languagestring-
placeholderstringType some code…
editablebooleantrue
readOnlybooleanfalse
autoFocusbooleanfalse
lineWrappingbooleanfalse
onLineWrappingChange(lineWrapping: boolean) => void-
extensionsExtension-
onReady(view: EditorView) => void-
classNamestring-
childrenReactNode-

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.

PropTypeDefault
classNamestring-

CodeEditorToolbar

Toolbar with the history controls, the line wrapping toggle and a copy action. Item controls can be passed as children.

PropTypeDefault
classNamestring-
childrenReactNode-

CodeEditorStatusBar

Cursor position, selection length and the language set on the root.

PropTypeDefault
classNamestring-

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.