Add CharacterCount demo for React
This commit is contained in:
15
demos/src/Extensions/CharacterCount/React/index.html
Normal file
15
demos/src/Extensions/CharacterCount/React/index.html
Normal 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>
|
||||
41
demos/src/Extensions/CharacterCount/React/index.jsx
Normal file
41
demos/src/Extensions/CharacterCount/React/index.jsx
Normal 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>
|
||||
Let‘s make sure people can’t 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>
|
||||
)
|
||||
}
|
||||
11
demos/src/Extensions/CharacterCount/React/styles.scss
Normal file
11
demos/src/Extensions/CharacterCount/React/styles.scss
Normal file
@@ -0,0 +1,11 @@
|
||||
/* Basic editor styles */
|
||||
.ProseMirror {
|
||||
> * + * {
|
||||
margin-top: 0.75em;
|
||||
}
|
||||
}
|
||||
|
||||
.character-count {
|
||||
color: #868e96;
|
||||
margin-top: 1rem;
|
||||
}
|
||||
Reference in New Issue
Block a user