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
Copy file name to clipboardExpand all lines: docs/how-to-customize-toolbars.md
+63-6Lines changed: 63 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,34 @@
2
2
3
3
## How to customize toolbars
4
4
5
+
### Understanding Presets
6
+
7
+
> **Important:** The editor uses two independent types of presets:
8
+
9
+
1.**Editor Preset** (`MarkdownEditorPreset`) - Defines the set of extensions and functionality available in the WYSIWYG editor. Configured via the `preset` property when initializing the editor.
10
+
- Available values: `'zero'`, `'commonmark'`, `'default'`, `'yfm'`, `'full'`
The editor currently provides six types of toolbars:
@@ -19,14 +47,16 @@ More details can be found in [issue #508](https://github.com/gravity-ui/markdown
19
47
20
48
Starting from `@gravity-ui/[email protected]`, all toolbars—except the selection-based and slash-triggered toolbars—are configured using a shared dictionary of items and arrays defining the order of those items.
21
49
22
-
Base toolbar configurations are available in the `gravity-ui/markdown-editor` repository:
50
+
Built-in **toolbar presets** are available in the `gravity-ui/markdown-editor` repository:
> **Note:** These toolbar presets have the same names as editor presets for convenience. When you don't specify `toolbarsPreset`, the editor automatically selects the toolbar preset matching your editor preset name.
59
+
30
60
### Configuration Details
31
61
32
62
1. The `items` key contains a shared dictionary used across the four main toolbars.
@@ -36,23 +66,27 @@ Base toolbar configurations are available in the `gravity-ui/markdown-editor` re
36
66
37
67
### Example Configuration
38
68
39
-
The `default` preset defines a shared `items` dictionary, specifies the display order in `orders`, and connects the corresponding extensions in the `extensions` section.
69
+
The `default`**editor preset** defines a set of extensions, while the `default`**toolbar preset** defines the toolbar configuration:
The library provides a set of predefined presets that cannot be overridden directly. If none of the built-in presets suit your needs, you can define a custom toolbar configuration. Below is an example of how to do that:
80
+
The library provides a set of predefined toolbar presets that cannot be overridden directly. If none of the built-in toolbar presets suit your needs, you can define a custom toolbar configuration. Below is an example of how to do that:
// Initialize editor with an editor preset (defines functionality)
134
+
const editor =useMarkdownEditor({
135
+
preset: 'default', // or 'zero', 'commonmark', 'yfm', 'full'
136
+
});
137
+
138
+
return (
139
+
<MarkdownEditorView
140
+
editor={editor}
141
+
toolbarsPreset={toolbarPresets.custom} // Override with custom toolbar preset
142
+
/>
143
+
);
144
+
}
145
+
```
146
+
147
+
> **Key point:** By providing `toolbarsPreset`, you override the default toolbar configuration. Without it, the editor would use the built-in `'default'` toolbar preset (matching the editor preset name).
148
+
92
149
### Conditional Toolbar Items
93
150
94
151
Sometimes you may want to display different sets of toolbar items depending on certain conditions—for example, user permissions. In such cases, you can implement a getter function that returns the appropriate toolbar configuration based on parameters. Example:
0 commit comments