Skip to content

Commit 2264654

Browse files
committed
fest: add text style menu
1 parent 82a5262 commit 2264654

File tree

2 files changed

+51
-5
lines changed

2 files changed

+51
-5
lines changed

components/Tiptap.tsx

+50-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { useEditor, EditorContent } from '@tiptap/react'
1+
import { useEditor, EditorContent, BubbleMenu, Editor } from '@tiptap/react'
22
import StarterKit from '@tiptap/starter-kit'
3-
import {Paragraph} from "@tiptap/extension-paragraph";
3+
import { Paragraph } from "@tiptap/extension-paragraph"
44
import Placeholder from '@tiptap/extension-placeholder'
5-
import { Heading} from '@tiptap/extension-heading';
5+
import { Heading } from '@tiptap/extension-heading'
66

77
export const Tiptap = () => {
88
const editor = useEditor({
@@ -18,7 +18,7 @@ export const Tiptap = () => {
1818
}),
1919
Heading.configure({
2020
levels: [1, 2, 3],
21-
})
21+
}),
2222
],
2323
content: '',
2424
editorProps: {
@@ -29,6 +29,51 @@ export const Tiptap = () => {
2929
})
3030

3131
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>
3378
)
3479
}

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"@openzeppelin/contracts": "^4.4.1",
1616
"@react-hookz/web": "^12.0.4",
1717
"@textile/eth-storage": "^1.0.0",
18+
"@tiptap/extension-bubble-menu": "^2.0.0-beta.54",
1819
"@tiptap/extension-heading": "^2.0.0-beta.25",
1920
"@tiptap/extension-paragraph": "^2.0.0-beta.23",
2021
"@tiptap/extension-placeholder": "^2.0.0-beta.46",

0 commit comments

Comments
 (0)