From de5d21e349fc2e275493a6f13a2bece404e01ecb Mon Sep 17 00:00:00 2001 From: Matthew Lipski Date: Thu, 18 Jan 2024 18:14:55 +0100 Subject: [PATCH] Added code toggle formatting toolbar example --- packages/website/docs/.vitepress/config.ts | 4 + .../examples/formatting-toolbar-buttons.md | 104 ++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 packages/website/docs/examples/formatting-toolbar-buttons.md diff --git a/packages/website/docs/.vitepress/config.ts b/packages/website/docs/.vitepress/config.ts index e1cd8404f7..ae7e1f5a52 100644 --- a/packages/website/docs/.vitepress/config.ts +++ b/packages/website/docs/.vitepress/config.ts @@ -137,6 +137,10 @@ const EXAMPLES_SIDEBAR = [ text: "Changing Font", link: "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/examples/changing-font", }, + { + text: "Formatting Toolbar Buttons", + link: "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/examples/formatting-toolbar-buttons", + }, ], }, { diff --git a/packages/website/docs/examples/formatting-toolbar-buttons.md b/packages/website/docs/examples/formatting-toolbar-buttons.md new file mode 100644 index 0000000000..69576061e6 --- /dev/null +++ b/packages/website/docs/examples/formatting-toolbar-buttons.md @@ -0,0 +1,104 @@ +--- +title: Formatting Toolbar Buttons +description: In this example, we change add a code styles button to the formatting toolbar. +imageTitle: Formatting Toolbar Buttons +path: /examples/formatting-toolbar-buttons +--- + + + +# Formatting Toolbar Buttons + +In this example, we add a code style toggle button to the Formatting Toolbar. + +**Relevant Docs:** + +- [Custom Formatting Toolbar](/docs/formatting-toolbar#custom-formatting-toolbar) + +::: sandbox {template=react-ts} + +```typescript-vue /App.tsx +import { BlockNoteEditor } from "@blocknote/core"; +import { + BlockNoteView, + BlockTypeDropdown, + ColorStyleButton, + CreateLinkButton, + FormattingToolbarPositioner, + FormattingToolbarProps, + HyperlinkToolbarPositioner, + ImageCaptionButton, + ImageToolbarPositioner, + NestBlockButton, + ReplaceImageButton, + SideMenuPositioner, + SlashMenuPositioner, + TableHandlesPositioner, + TextAlignButton, + ToggledStyleButton, + Toolbar, + UnnestBlockButton, + useBlockNote, +} from "@blocknote/react"; +import "@blocknote/react/style.css"; + +// From https://github.com/TypeCellOS/BlockNote/blob/main/packages/react/src/components/FormattingToolbar/DefaultFormattingToolbar.tsx +function CustomFormattingToolbar(props: FormattingToolbarProps) { + return ( + + + + + + + + + + + {/* Added code toggle button */} + + + + + + + + + + + + + + ); +} + +export default function App() { + // Creates a new editor instance. + const editor: BlockNoteEditor = useBlockNote(); + + // Renders the editor instance using a React component. + return ( + + + + + + + + + ); +} + +``` + +```css-vue /styles.css [hidden] +{{ getStyles(isDark) }} +```