Add a button to toggle block-level nodes
Toggle through block-level nodes like code blocks and blockquotes with the node button.
Installation
You can add the component via Tiptap CLI (for Vite or Next.js)
npx @tiptap/cli add node-button
Manual Integration
For frameworks other than Vite or Next.js, add the component manually from the open-source repository.
Import styles
This component requires you to import our styles which were added to styles/keyframe-animation.scss
and styles/_variables.scss
.
Usage
import { EditorContent, EditorContext, useEditor } from '@tiptap/react'
import { StarterKit } from '@tiptap/starter-kit'
import { NodeButton } from '@/components/tiptap-ui/node-button'
import '@/components/tiptap-node/code-block-node/code-block-node.scss'
import '@/components/tiptap-node/paragraph-node/paragraph-node.scss'
export default function MyEditor() {
const editor = useEditor({
immediatelyRender: false,
extensions: [StarterKit],
content: `
<blockquote>
<p>"The best way to predict the future is to invent it."</p><p>— Alan Kay</p>
</blockquote>
<pre><code>console.log('Hello, World!');</code></pre>
`,
})
return (
<EditorContext.Provider value={{ editor }}>
<div className="tiptap-button-group" data-orientation="horizontal">
<NodeButton type="blockquote" />
<NodeButton type="codeBlock" />
</div>
<EditorContent editor={editor} role="presentation" />
</EditorContext.Provider>
)
}
Props
Name | Type | Default | Description |
---|---|---|---|
editor | Editor | null | null | The Tiptap editor instance |
type | 'codeBlock' | 'blockquote' | required | The type of node to toggle |
hideWhenUnavailable | boolean | false | Whether the button should be hide if not available |
text | string | - | Text to display alongside the icon |
Requirements
Used reference components
use-tiptap-editor
(hook)tiptap-utils
(lib)button
(primitive)code-block-icon
(icon)block-quote-icon
(icon)