How can I customize toolbar buttons? #144
-
Hi, import type { CodeBlockEditorDescriptor } from "@mdxeditor/editor"
import "@mdxeditor/editor/style.css"
const {
MDXEditor,
codeBlockPlugin,
headingsPlugin,
listsPlugin,
linkPlugin,
quotePlugin,
markdownShortcutPlugin,
useCodeBlockEditorContext,
SingleChoiceToggleGroup,
toolbarPlugin,
} = await import("@mdxeditor/editor")
const PlainTextCodeEditorDescriptor: CodeBlockEditorDescriptor = {
match: () => true,
priority: 0,
Editor: (props) => {
const cb = useCodeBlockEditorContext()
return (
<div onKeyDown={(e) => e.nativeEvent.stopImmediatePropagation()}>
<textarea rows={3} cols={20} defaultValue={props.code} onChange={(e) => cb.setCode(e.target.value)} />
</div>
)
},
}
const Editor = () => {
return (
<MDXEditor
onChange={console.log}
markdown={"Hello world!"}
plugins={[
codeBlockPlugin({ codeBlockEditorDescriptors: [PlainTextCodeEditorDescriptor] }),
headingsPlugin(),
listsPlugin(),
linkPlugin(),
quotePlugin(),
markdownShortcutPlugin(),
toolbarPlugin({
toolbarContents: () => {
return (
<div>
<SingleChoiceToggleGroup
value="bullet"
items={[{ title: "Bullet List", contents: <span>Bullet list</span>, value: "bullet" }]}
onChange={(e) => {
// ???
}}
/>
</div>
)
},
}),
]}
/>
)
}
export default Editor it would be awesome if you can tell me how I can create single button as well in the toolbar? thanks, |
Beta Was this translation helpful? Give feedback.
Answered by
petyosi
Oct 26, 2023
Replies: 1 comment
-
The best way to figure this out is to browse the source code of the built-in tools. You will need to move this into a separate component, so that you can access the hooks. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
danishsjjd
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The best way to figure this out is to browse the source code of the built-in tools. You will need to move this into a separate component, so that you can access the hooks.