Skip to content

Commit

Permalink
Add custom paragraph example
Browse files Browse the repository at this point in the history
  • Loading branch information
ruipserra committed Oct 24, 2022
1 parent c602f72 commit bff992a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
Empty file.
46 changes: 46 additions & 0 deletions demos/src/Examples/CustomParagraph/React/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import './styles.scss'

import {
Paragraph as TTParagraph,
} from '@tiptap/extension-paragraph'
import {
EditorContent,
NodeViewContent,
NodeViewWrapper,
ReactNodeViewRenderer, useEditor,
} from '@tiptap/react'
import StarterKit from '@tiptap/starter-kit'

const ParagraphComponent = () => (
<NodeViewWrapper className="paragraph">
<NodeViewContent className="content" as="p" />
</NodeViewWrapper>
)

export const Paragraph = TTParagraph.extend({
addNodeView() {
return ReactNodeViewRenderer(ParagraphComponent)
},
})

const Tiptap = () => {
const editor = useEditor({
extensions: [
StarterKit.configure({
paragraph: false,
}),
Paragraph,
],
content: '<p>Hello World!</p>',
})

return <EditorContent editor={editor} />
}

export default function App() {
return (
<div className="App">
<Tiptap />
</div>
)
}
6 changes: 6 additions & 0 deletions demos/src/Examples/CustomParagraph/React/styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* Basic editor styles */
.ProseMirror {
> * + * {
margin-top: 0.75em;
}
}

0 comments on commit bff992a

Please sign in to comment.