ExpressionEditor Atom
A controlled arithmetic text field with distinct variable, constant, operator and unknown-name styles. CodeMirror 6 owns the caret, text selection, composition and undo history. Tokenization is cosmetic: the caller validates grammar and evaluates the expression with its own trusted parser.
Usage
Supply the allowed variable and named constant lists. Unknown names receive a wavy underline as well
as a different color. Decimal constants such as 0.5 remain ordinary editable text. Set invalid
from caller validation and connect its visible message with describedBy.
Import ExpressionEditor from @ceebee/ui/client. The build keeps the editor runtime in its own
module so a consumer that defers the editor route can also defer CodeMirror.
Do
Validate expressions before saving or evaluating them.
Don't
Treat highlighting as proof that a formula or its physical units are correct.
Props
| Prop | Type | Default | Notes |
|---|---|---|---|
| value / onChange | string / (value: string) => void | — | Controlled plain text. External updates do not echo onChange. |
| variables / constants | readonly string[] | — | Allowed identifiers for cosmetic highlighting; constants defaults to an empty list. |
| label / id / describedBy | string | — | Accessible name, optional label target and description IDs. |
| required / invalid / disabled | boolean | — | Accessible field state. Disabled prevents editing. |
| maxLength | number | — | Oversized editing transactions are refused atomically. |
Keyboard
Normal CodeMirror text editing, selection, undo and redo apply. Enter inserts a line break. Tab leaves the field instead of inserting indentation. Escape is available to the surrounding dialog. The editor does not execute formulas, submit forms, provide autocomplete or implement spreadsheet references.
Tokens
Uses --cb-font-mono, --cb-text-md, --cb-leading-normal, --cb-space-3, --cb-radius-sm,
--cb-border-width, --cb-border-strong, --cb-fg, --cb-fg-muted, --cb-fg-link, --cb-surface,
--cb-tone-danger, --cb-brand-500 and the shared focus and control-height tokens.