You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A controlled, syntax-highlighted code editor for Dioxus. Pairs a `contenteditable` input layer with the [`dioxus-code`](https://crates.io/crates/dioxus-code) highlighter so user edits stay in sync with rendered tokens.
21
+
22
+
## Quick start
23
+
24
+
```toml
25
+
[dependencies]
26
+
dioxus-code-editor = "0.0.1"
27
+
```
28
+
29
+
```rust
30
+
usedioxus::prelude::*;
31
+
usedioxus_code::Theme;
32
+
usedioxus_code_editor::CodeEditor;
33
+
34
+
#[component]
35
+
fnEditor() ->Element {
36
+
letmutsource=use_signal(String::new);
37
+
38
+
rsx! {
39
+
CodeEditor {
40
+
value:source(),
41
+
language:"rust",
42
+
theme:Theme::TOKYO_NIGHT,
43
+
oninput:move|value|source.set(value),
44
+
}
45
+
}
46
+
}
47
+
```
48
+
49
+
The component is controlled — drive `value` from your own signal and update it inside `oninput`.
50
+
51
+
## Props
52
+
53
+
| prop | description |
54
+
|---|---|
55
+
|`value`| Current editor contents. |
56
+
|`language`| Arborium language hint, e.g. `"rust"`. |
57
+
|`name`| Filename used for language detection when `language` is empty. |
58
+
|`theme`| Syntax theme shared with `dioxus-code`. |
59
+
|`line_numbers`| Show a one-based line gutter. Defaults to `true`. |
60
+
|`read_only`| Disable editing while preserving highlighting. |
61
+
|`spellcheck`| Forward `spellcheck` to the input layer. |
62
+
|`aria_label`| Accessible label for the editor textbox. |
63
+
|`placeholder`| Shown only while `value` is empty. |
64
+
|`class`| Extra class names appended to the editor root. |
65
+
|`oninput`| Called with the full editor text after each input event. |
Implementation crate for the `code!` macro re-exported by [`dioxus-code`](https://crates.io/crates/dioxus-code) under its default `macro` feature. You usually depend on `dioxus-code` instead of pulling this in directly.
21
+
22
+
The macro reads a source file at compile time, parses it with [`arborium`](https://crates.io/crates/arborium), and expands to a static span tree. The runtime binary ships only the spans — no parser.
23
+
24
+
```rust
25
+
usedioxus_code::code;
26
+
27
+
lettree=code!("/snippets/demo.rs");
28
+
```
29
+
30
+
## Path resolution
31
+
32
+
Paths are resolved relative to the *consumer's*`CARGO_MANIFEST_DIR`. A leading `/` anchors to that directory; bare paths resolve from it as well. `concat!(...)` and `env!(...)` expressions are also accepted.
0 commit comments