Add CharacterCount demo for React

This commit is contained in:
Sven Adlung
2021-11-15 17:01:03 +01:00
parent 62e41b6a7d
commit 40624e7500
3 changed files with 67 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body>
<div id="app"></div>
<script type="module">
import setup from "../../../../setup/react.ts";
import source from "@source";
setup("Extensions/CharacterCount", source);
</script>
</body>
</html>

View File

@@ -0,0 +1,41 @@
import React from 'react'
import { useEditor, EditorContent } from '@tiptap/react'
import Document from '@tiptap/extension-document'
import Paragraph from '@tiptap/extension-paragraph'
import Text from '@tiptap/extension-text'
import CharacterCount from '@tiptap/extension-character-count'
import './styles.scss'
const limit = 280
export default () => {
const editor = useEditor({
extensions: [
Document,
Paragraph,
Text,
CharacterCount.configure({
limit,
}),
],
content: `
<p>
Lets make sure people cant write more than 280 characters. I bet you could build one of the biggest social networks on that idea.
</p>
`,
})
if (!editor) {
return null
}
return (
<div>
<EditorContent editor={editor} />
<div className="character-count">
{editor.getCharacterCount()}/{limit} characters
</div>
</div>
)
}

View File

@@ -0,0 +1,11 @@
/* Basic editor styles */
.ProseMirror {
> * + * {
margin-top: 0.75em;
}
}
.character-count {
color: #868e96;
margin-top: 1rem;
}