1
- import { useEditor , EditorContent } from '@tiptap/react'
1
+ import { useEditor , EditorContent , BubbleMenu , Editor } from '@tiptap/react'
2
2
import StarterKit from '@tiptap/starter-kit'
3
- import { Paragraph } from "@tiptap/extension-paragraph" ;
3
+ import { Paragraph } from "@tiptap/extension-paragraph"
4
4
import Placeholder from '@tiptap/extension-placeholder'
5
- import { Heading } from '@tiptap/extension-heading' ;
5
+ import { Heading } from '@tiptap/extension-heading'
6
6
7
7
export const Tiptap = ( ) => {
8
8
const editor = useEditor ( {
@@ -18,7 +18,7 @@ export const Tiptap = () => {
18
18
} ) ,
19
19
Heading . configure ( {
20
20
levels : [ 1 , 2 , 3 ] ,
21
- } )
21
+ } ) ,
22
22
] ,
23
23
content : '' ,
24
24
editorProps : {
@@ -29,6 +29,51 @@ export const Tiptap = () => {
29
29
} )
30
30
31
31
return (
32
- < EditorContent editor = { editor } />
32
+ < >
33
+ { editor && < BubbleMenu editor = { editor } pluginKey = { 'menu' } >
34
+ < MenuUI editor = { editor } />
35
+ </ BubbleMenu > }
36
+ < EditorContent editor = { editor } />
37
+ </ >
38
+ )
39
+ }
40
+
41
+ const MenuUI = ( { editor } : { editor : Editor } ) => {
42
+ return (
43
+ < div className = "bg-amber-400 rounded flex px-2" >
44
+ < div className = "p-2 text-teal-50" >
45
+ < button
46
+ onClick = { ( ) => editor . chain ( ) . focus ( ) . toggleHeading ( { level : 1 } ) . run ( ) }
47
+ className = { editor . isActive ( 'h-1' ) ? 'is-active' : '' }
48
+ >
49
+ h1
50
+ </ button >
51
+ </ div >
52
+ < div className = "p-2 text-teal-50" >
53
+ < button
54
+ onClick = { ( ) => editor . chain ( ) . focus ( ) . toggleBold ( ) . run ( ) }
55
+ className = { editor . isActive ( 'bold' ) ? 'is-active' : '' }
56
+ >
57
+ bold
58
+ </ button >
59
+ </ div >
60
+ < div className = "p-2 text-teal-50" >
61
+ < button
62
+ onClick = { ( ) => editor . chain ( ) . focus ( ) . toggleItalic ( ) . run ( ) }
63
+ className = { editor . isActive ( 'italic' ) ? 'is-active' : '' }
64
+ >
65
+ italic
66
+ </ button >
67
+ </ div >
68
+
69
+ < div className = "p-2 text-teal-50" >
70
+ < button
71
+ onClick = { ( ) => editor . chain ( ) . focus ( ) . toggleStrike ( ) . run ( ) }
72
+ className = { editor . isActive ( 'strike' ) ? 'is-active' : '' }
73
+ >
74
+ strike
75
+ </ button >
76
+ </ div >
77
+ </ div >
33
78
)
34
79
}
0 commit comments