Skip to content

Commit 9e4ce02

Browse files
committed
feat: use tiptap editor
1 parent 9ed4619 commit 9e4ce02

File tree

6 files changed

+82
-1
lines changed

6 files changed

+82
-1
lines changed

components/Editor.tsx

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { memo } from "react";
2+
import { Tiptap } from "./Tiptap";
3+
4+
interface EditorProps {
5+
account: string
6+
}
7+
8+
// eslint-disable-next-line react/display-name
9+
export const Editor = memo<EditorProps>(({ account}) => {
10+
return (
11+
<div style={{width: '720px'}}>
12+
<input placeholder="Give a title" type="text" className="border-0 outline-0 text-5xl"/>
13+
<div className="my-4">
14+
Account: {account}
15+
</div>
16+
<Tiptap />
17+
</div>
18+
)
19+
})

components/Layout.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const Layout = () => {
2+
3+
}

components/Tiptap.tsx

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { useEditor, EditorContent } from '@tiptap/react'
2+
import StarterKit from '@tiptap/starter-kit'
3+
import {Paragraph} from "@tiptap/extension-paragraph";
4+
import Placeholder from '@tiptap/extension-placeholder'
5+
import { Heading} from '@tiptap/extension-heading';
6+
7+
export const Tiptap = () => {
8+
const editor = useEditor({
9+
extensions: [
10+
StarterKit,
11+
Paragraph.configure({
12+
HTMLAttributes: {
13+
class: 'text-neutral-800 text-lg min-h-full',
14+
},
15+
}),
16+
Placeholder.configure({
17+
placeholder: 'Write something …',
18+
}),
19+
Heading.configure({
20+
levels: [1, 2, 3],
21+
})
22+
],
23+
content: '',
24+
editorProps: {
25+
attributes: {
26+
class: 'focus:outline-none text-lg',
27+
},
28+
},
29+
})
30+
31+
return (
32+
<EditorContent editor={editor} />
33+
)
34+
}

package.json

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
"@openzeppelin/contracts": "^4.4.1",
1616
"@react-hookz/web": "^12.0.4",
1717
"@textile/eth-storage": "^1.0.0",
18+
"@tiptap/extension-heading": "^2.0.0-beta.25",
19+
"@tiptap/extension-paragraph": "^2.0.0-beta.23",
20+
"@tiptap/extension-placeholder": "^2.0.0-beta.46",
21+
"@tiptap/react": "^2.0.0-beta.104",
22+
"@tiptap/starter-kit": "^2.0.0-beta.168",
1823
"axios": "^0.24.0",
1924
"ethers": "^5.5.2",
2025
"graphql-tag": "^2.12.6",

pages/create-draft.tsx

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import {Editor} from "../components/Editor";
2+
3+
export default function CreateDraft() {
4+
const account = 'testaccout'
5+
return (
6+
<div className="flex justify-center py-16 min-h-screen">
7+
<Editor account={account} />
8+
</div>
9+
)
10+
}

styles/globals.css

+11-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,14 @@
66
.current {
77
text-decoration: underline #FF3028;
88
font-weight: bold;
9-
}
9+
}
10+
11+
h1 {
12+
@apply text-4xl;
13+
}
14+
h2 {
15+
@apply text-3xl;
16+
}
17+
h3 {
18+
@apply text-2xl;
19+
}

0 commit comments

Comments
 (0)