CodeEditor

Lightweight code editor — a native textarea overlaid on a syntax-highlighted layer, with line numbers and Tab indent.

Category: inputs · WCAG 2.1-AA · editor, code, syntax-highlighting, textarea, inputs

States

Props

PropTypeDefaultDescription
valuestring—Controlled value
defaultValuestring—Initial value for uncontrolled use
onValueChange(value: string) => void—Called with the new text on every edit
languagestringplaintextGrammar name (plaintext/json/javascript/typescript/css/html/markdown/bash)
lineNumbersbooleantrueShow the line-number gutter
tabSizenumber2Spaces per tab stop
insertSpacesbooleantrueInsert spaces vs a literal tab on Tab
wrapbooleanfalseSoft-wrap long lines instead of scrolling horizontally
readOnlybooleanfalseWhen true, the value is shown but cannot be edited.
disabledbooleanfalseWhen true, disables the control and removes it from the tab order.
placeholderstring—Placeholder text shown when the field is empty.
ariaLabelstring—Alias of `label` — the same invisible accessible name under the catalog spelling. Neither is deprecated.
labelstring—Accessible label (defaults to the i18n "Code editor")
onSave(value: string) => void—Called on Mod-S; the browser save dialog is suppressed
bracketMatchingbooleanfalseHighlight the bracket matching the one adjacent to the caret
themeEditorTheme—Per-instance --cascivo-editor-* overrides; swapping it re-themes live
keymapKeyMap—Extra key bindings merged over the built-ins (user wins on a chord)
decorationsDecoration[] | ((value: string) => Decoration[])—Extra offset-range → CSS class decorations
commandsSlashCommand[]—Slash-command entries; typing "/" opens a filtered menu. Omit to disable.
refRef<CodeEditorHandle>—Imperative handle: applyEdit / getSelection / focus / undo / redo / openFind / openCommandMenu
classNamestring—Additional CSS class names merged onto the root element.
virtualizeboolean—Render only the visible lines for large documents.

Design tokens

When to use

When not to use

Examples

Basic editor

import { CodeEditor } from '@cascivo/editor'
import '@cascivo/editor/styles.css'

<CodeEditor language="typescript" lineNumbers defaultValue={'const x = 1\n'} />

Controlled

<CodeEditor language="json" value={value} onValueChange={setValue} />

Notes editing — find, save, brackets

<CodeEditor
  language="markdown"
  value={doc}
  onValueChange={setDoc}
  onSave={save} // Mod-S
  bracketMatching
/> // Mod-F to search

Slash commands

Type "/" to open a filtered command menu; arrows + Enter insert.

const commands = [
  { id: 'fence', label: 'Code block', keywords: ['code'], insert: '\u0060\u0060\u0060\n\n\u0060\u0060\u0060' },
  { id: 'todo', label: 'TODO', insert: '// TODO: ' },
  { id: 'date', label: 'Date', run: (e) => e.applyEdit(e.getSelection(), new Date().toISOString()) },
]

<CodeEditor language="markdown" commands={commands} />

Related components

← Back to docs