CodeEditor
Lightweight code-editing container — textarea + line numbers + Tab indentation. Reach for Monaco / CodeMirror when you need full syntax / completion.
Basic usage
It’s positioned as “visual container + light interactions”: line numbers, Tab indentation, end-of-line preservation, and full ARIA labeling — but no built-in syntax highlighting. For highlighting, wrap an overlay around it on the consumer side (see the overlay technique used in VariableAwareInput).
12345678910
<CfCodeEditor v-model="code" language="typescript" :rows="12" /> <CfCodeEditor value={code} onChange={setCode} language="typescript" rows={12} /> readOnly / wrap / no line numbers
A handful of state combinations: read-only doc samples, soft-wrapped long text, and a no-line-number compact mode.
1234567
1
<CfCodeEditor v-model="code" read-only />
<CfCodeEditor v-model="text" wrap />
<CfCodeEditor v-model="snip" :show-line-numbers="false" /> <CfCodeEditor value={code} onChange={set} readOnly />
<CfCodeEditor value={text} onChange={set} wrap />
<CfCodeEditor value={snip} onChange={set} showLineNumbers={false} /> API
| Prop | Type | Default | Description |
|---|---|---|---|
modelValue / value | string | '' | Code content |
language | string | 'plaintext' | Forwarded as data-language only; not used for rendering |
size | 'sm' | 'md' | 'lg' | 'md' | |
showLineNumbers | boolean | true | |
readOnly | boolean | false | |
rows | number | 12 | Visible rows |
wrap | boolean | false | Soft-wrap long lines |
tabSize | number | 2 | Number of spaces inserted by Tab; 0 makes Tab move focus |
反馈与讨论
CodeEditor · Discussion