Skip to main content

Crate dioxus_code_editor

Crate dioxus_code_editor 

Source
Expand description

dioxus-code-editor

Syntax-highlighted code editor component for Dioxus.


A controlled, syntax-highlighted code editor for Dioxus. Pairs an editable input layer with the dioxus-code highlighter so user edits stay in sync with rendered tokens.

§Quick start

[dependencies]
dioxus-code-editor = "0.1.0"
use dioxus::prelude::*;
use dioxus_code::Theme;
use dioxus_code_editor::{CodeEditor, Language};

#[component]
fn Editor() -> Element {
    let mut source = use_signal(String::new);

    rsx! {
        CodeEditor {
            value: source(),
            language: Language::Rust,
            theme: Theme::TOKYO_NIGHT,
            oninput: move |value| source.set(value),
        }
    }
}

The component is controlled — drive CodeEditorProps::value from your own signal and update it inside CodeEditorProps::oninput.

§Props

propdescription
CodeEditorProps::valueCurrent editor contents.
CodeEditorProps::languageSyntax grammar selection. Pass a Language variant (for example Language::Rust) or use Language::from_slug for runtime slugs.
CodeEditorProps::themeSyntax theme selection shared with dioxus-code; accepts Theme or CodeTheme.
CodeEditorProps::line_numbersShow a one-based line gutter. Defaults to true.
CodeEditorProps::read_onlyDisable editing while preserving highlighting.
CodeEditorProps::spellcheckForward spellcheck to the input layer.
CodeEditorProps::aria_labelAccessible label for the editor textbox.
CodeEditorProps::placeholderShown only while CodeEditorProps::value is empty.
CodeEditorProps::classExtra class names appended to the editor root.
CodeEditorProps::oninputCalled with the full editor text after each input event.

§License

MIT.

Structs§

CodeEditorProps
Props for CodeEditor.

Enums§

Language
Tree-sitter grammar identifier.

Constants§

CODE_EDITOR_CSS
Base stylesheet injected by CodeEditor.

Functions§

CodeEditor
Editable syntax-highlighted code surface.