@reactloom/code-editor
v1.3.0
Published
Accessible React code editor and diff viewer for ReactLoom on CodeMirror 6: labelled field, ReactLoom theme tokens, Tab not captured by default and server-rendered first paint.
Maintainers
Readme
@reactloom/code-editor
Accessible code fields for ReactLoom on CodeMirror 6: CodeEditor, a labelled source editor
themed with ReactLoom tokens, and DiffViewer, a side-by-side or unified diff.
pnpm add @reactloom/code-editor @reactloom/ui @reactloom/theme
# plus the CodeMirror languages you need, for example:
pnpm add @codemirror/lang-jsonimport '@reactloom/code-editor/styles.css';
import { CodeEditor } from '@reactloom/code-editor';
import { json } from '@codemirror/lang-json';
<CodeEditor
label="Webhook retry policy (JSON)"
description="Applied to every outgoing webhook."
value={value}
onValueChange={setValue}
extensions={[json()]}
error={error}
name="policy"
/>;- Keyboard-safe: Tab moves focus out of the editor by default, so keyboard users never get
trapped. Set
tabIndentsto indent instead; Escape then Tab still leaves. - Forms:
namesubmits the value with a hidden input;erroranddescriptionare announced like any ReactLoom field. - Server rendering: the first paint is plain, readable code; CodeMirror takes over in the browser.
- Diffs:
<DiffViewer title="config.ts" original={before} modified={after} />.
No languages are bundled, so the package stays small: pass any CodeMirror extension in
extensions.
Documentation and live examples: https://www.reactloom.dev/components/code-editor · https://www.reactloom.dev/components/diff-viewer
