-
-
Notifications
You must be signed in to change notification settings - Fork 435
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added code toggle formatting toolbar example (#531)
- Loading branch information
1 parent
352c8e7
commit 6bb6271
Showing
2 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
packages/website/docs/examples/formatting-toolbar-buttons.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
--- | ||
|
||
<script setup> | ||
import { useData } from 'vitepress'; | ||
import { getTheme, getStyles } from "../demoUtils"; | ||
|
||
const { isDark } = useData(); | ||
</script> | ||
|
||
# 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 ( | ||
<Toolbar> | ||
<BlockTypeDropdown {...props} /> | ||
|
||
<ImageCaptionButton editor={props.editor} /> | ||
<ReplaceImageButton editor={props.editor} /> | ||
|
||
<ToggledStyleButton editor={props.editor} toggledStyle={"bold"} /> | ||
<ToggledStyleButton editor={props.editor} toggledStyle={"italic"} /> | ||
<ToggledStyleButton editor={props.editor} toggledStyle={"underline"} /> | ||
<ToggledStyleButton editor={props.editor} toggledStyle={"strike"} /> | ||
{/* Added code toggle button */} | ||
<ToggledStyleButton editor={props.editor} toggledStyle={"code"} /> | ||
|
||
<TextAlignButton editor={props.editor as any} textAlignment={"left"} /> | ||
<TextAlignButton editor={props.editor as any} textAlignment={"center"} /> | ||
<TextAlignButton editor={props.editor as any} textAlignment={"right"} /> | ||
|
||
<ColorStyleButton editor={props.editor} /> | ||
|
||
<NestBlockButton editor={props.editor} /> | ||
<UnnestBlockButton editor={props.editor} /> | ||
|
||
<CreateLinkButton editor={props.editor} /> | ||
</Toolbar> | ||
); | ||
} | ||
|
||
export default function App() { | ||
// Creates a new editor instance. | ||
const editor: BlockNoteEditor = useBlockNote(); | ||
|
||
// Renders the editor instance using a React component. | ||
return ( | ||
<BlockNoteView editor={editor} theme={"{{ getTheme(isDark) }}"}> | ||
<FormattingToolbarPositioner | ||
editor={editor} | ||
formattingToolbar={CustomFormattingToolbar} | ||
/> | ||
<HyperlinkToolbarPositioner editor={editor} /> | ||
<SlashMenuPositioner editor={editor} /> | ||
<SideMenuPositioner editor={editor} /> | ||
<ImageToolbarPositioner editor={editor} /> | ||
<TableHandlesPositioner editor={editor} /> | ||
</BlockNoteView> | ||
); | ||
} | ||
|
||
``` | ||
|
||
```css-vue /styles.css [hidden] | ||
{{ getStyles(isDark) }} | ||
``` |
6bb6271
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
blocknote-website – ./packages/website/
blocknote-website-git-main-typecell.vercel.app
block-note-website.vercel.app
blocknotejs.org
blocknotejs.com
www.blocknotejs.org
blocknote-website-typecell.vercel.app
www.blocknotejs.com
6bb6271
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
blocknote – ./
blocknote-main.vercel.app
blocknote-typecell.vercel.app
blocknote-git-main-typecell.vercel.app
playground.blocknotejs.org