Markdown editor
A textarea with a formatting toolbar and Write / Preview tabs. Toolbar buttons and shortcuts wrap or prefix the selection, and toggle off when it is already formatted.
Standup
Shipped the export fix. Next: pricing page.
- Review PR
- Write release notes
104 characters
Usage
use hydroxy_leptos::markdown_editor::MarkdownEditor;
use leptos::prelude::*;
pub fn demo() -> AnyView {
let (notes, set_notes) = signal(String::from(
"## Standup\n\nShipped the **export** fix. Next: _pricing_ page.\n\n- [x] Review PR\n- [ ] Write release notes",
));
view! {
<div style="display: grid; gap: var(--space-4); max-width: 560px;">
<MarkdownEditor
label="Notes"
value=notes
on_input=move |v| set_notes.set(v)
placeholder="Write in markdown"
/>
<p style="margin: 0; font: var(--text-xs); color: var(--text-3);">
{move || format!("{} characters", notes.get().chars().count())}
</p>
</div>
}
.into_any()
}use dioxus::prelude::*;
use hydroxy_dioxus::markdown_editor::MarkdownEditor;
#[component]
pub fn MarkdownEditorDemo() -> Element {
let mut notes = use_signal(|| {
String::from(
"## Standup\n\nShipped the **export** fix. Next: _pricing_ page.\n\n- [x] Review PR\n- [ ] Write release notes",
)
});
rsx! {
div { style: "display: grid; gap: var(--space-4); max-width: 560px;",
MarkdownEditor {
label: "Notes",
value: notes(),
on_input: move |v| notes.set(v),
placeholder: "Write in markdown",
}
p { style: "margin: 0; font: var(--text-xs); color: var(--text-3);",
"{notes().chars().count()} characters"
}
}
}
}
Anatomy
| Component | data-part | Renders |
|---|---|---|
MarkdownEditor | root | Wrapper |
| label | <label for> the textarea |
| bar | Tabs list and toolbar row |
| toolbar | role=toolbar of action buttons. Hidden in Preview |
| action | One formatting button. data-format names it |
| control | The native <textarea> |
| preview | Rendered Markdown of the current text |
Keyboard
| Key | Does |
|---|---|
Cmd/Ctrl + B | Bold |
Cmd/Ctrl + I | Italic |
Cmd/Ctrl + K | Link, with the url selected |
Props
| Prop | Type | Notes |
|---|---|---|
label | String | Required. Visible label |
value | Option<String> | Controlled value. Pair with on_input |
default_value | String | Initial value when uncontrolled |
on_input | Callback<String> | Called on every change, typed or from the toolbar |
placeholder | String | Placeholder text |
name | String | Form field name |
rows | u32 | Visible text rows. Default 8 |