Files
tiptap/demos/src/Marks/Underline/React/index.jsx
Dominik 8c6751f0c6 add precommit hook for linting and automatic eslint fixes + update eslint packages (#2862)
* chore: add precommit hook for eslint fixes, fix linting issues
* chore: add eslint import sort plugin
2022-06-08 14:10:25 +02:00

47 lines
1.2 KiB
JavaScript

import Document from '@tiptap/extension-document'
import Paragraph from '@tiptap/extension-paragraph'
import Text from '@tiptap/extension-text'
import Underline from '@tiptap/extension-underline'
import { EditorContent, useEditor } from '@tiptap/react'
import React from 'react'
export default () => {
const editor = useEditor({
extensions: [Document, Paragraph, Text, Underline],
content: `
<p>There is no underline here.</p>
<p><u>This is underlined though.</u></p>
<p style="text-decoration: underline">And this as well.</p>
`,
})
if (!editor) {
return null
}
return (
<>
<button
onClick={() => editor.chain().focus().toggleUnderline().run()}
className={editor.isActive('underline') ? 'is-active' : ''}
>
toggleUnderline
</button>
<button
onClick={() => editor.chain().focus().setUnderline().run()}
disabled={editor.isActive('underline')}
>
setUnderline
</button>
<button
onClick={() => editor.chain().focus().unsetUnderline().run()}
disabled={!editor.isActive('underline')}
>
unsetUnderline
</button>
<EditorContent editor={editor} />
</>
)
}