tiptap/demos/src/Nodes/ListItem/React/index.jsx
Nick Perez 2c911d2f02
feat(list): add new extension-list package which packages all the list packages into a single package (#6048)
This maintains backwards-compatibility with the existing packages by making them into re-exports
2025-01-27 15:03:24 +01:00

81 lines
2.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import './styles.scss'
import Document from '@tiptap/extension-document'
import { BulletList, ListItem, OrderedList } from '@tiptap/extension-list'
import Paragraph from '@tiptap/extension-paragraph'
import Text from '@tiptap/extension-text'
import { EditorContent, useEditor } from '@tiptap/react'
import React from 'react'
export default () => {
const editor = useEditor({
extensions: [Document, Paragraph, Text, BulletList, OrderedList, ListItem],
content: `
<p>
I like lists. Lets add one:
</p>
<ul>
<li>This is a bullet list.</li>
<li>And it has three list items.</li>
<li>Here is the third one.</li>
</ul>
<p>
Do you want to see one more? I bet! Here is another one:
</p>
<ol>
<li>Thats a different list, actually its an ordered list.</li>
<li>It also has three list items.</li>
<li>And all of them are numbered.</li>
</ol>
<p>
Lists would be nothing without list items.
</p>
`,
})
if (!editor) {
return null
}
return (
<>
<div className="control-group">
<div className="button-group">
<button
onClick={() => editor.chain().focus().toggleBulletList().run()}
className={editor.isActive('bulletList') ? 'is-active' : ''}
>
Toggle bullet list
</button>
<button
onClick={() => editor.chain().focus().toggleOrderedList().run()}
className={editor.isActive('orderedList') ? 'is-active' : ''}
>
Toggle ordered list
</button>
<button
onClick={() => editor.chain().focus().splitListItem('listItem').run()}
disabled={!editor.can().splitListItem('listItem')}
>
Split list item
</button>
<button
onClick={() => editor.chain().focus().sinkListItem('listItem').run()}
disabled={!editor.can().sinkListItem('listItem')}
>
Sink list item
</button>
<button
onClick={() => editor.chain().focus().liftListItem('listItem').run()}
disabled={!editor.can().liftListItem('listItem')}
>
Lift list item
</button>
</div>
</div>
<EditorContent editor={editor} />
</>
)
}