Add Blockquote demo for React

This commit is contained in:
Sven Adlung
2021-11-16 14:22:00 +01:00
parent ecd7483278
commit f4c7f54f46
4 changed files with 159 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
import React from 'react'
import { useEditor, EditorContent } from '@tiptap/react'
import Document from '@tiptap/extension-document'
import Paragraph from '@tiptap/extension-paragraph'
import Text from '@tiptap/extension-text'
import Blockquote from '@tiptap/extension-blockquote'
import './styles.scss'
export default () => {
const editor = useEditor({
extensions: [Document, Paragraph, Text, Blockquote],
content: `
<blockquote>
Nothing is impossible, the word itself says “Im possible!”
</blockquote>
<p>Audrey Hepburn</p>
`,
})
if (!editor) {
return null
}
return (
<div>
<button
onClick={() => editor.chain().focus().toggleBlockquote().run()}
className={editor.isActive('blockquote') ? 'is-active' : ''}
>
toggleBlockquote
</button>
<button
onClick={() => editor.chain().focus().setBlockquote().run()}
disabled={editor.isActive('blockquote')}
>
setBlockquote
</button>
<button
onClick={() => editor.chain().focus().unsetBlockquote().run()}
disabled={!editor.isActive('blockquote')}
>
unsetBlockquote
</button>
<EditorContent editor={editor} />
</div>
)
}