Files
tiptap/docs/src/demos/Extensions/CharacterCount/index.vue
2021-01-25 23:40:15 +01:00

81 lines
1.5 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<div>
<editor-content :editor="editor" />
<div :class="{'character-limit': true, 'character-limit--warning': characters === limit}">
{{ characters }}/{{ limit }} characters
</div>
</div>
</template>
<script>
import { Editor, EditorContent } from '@tiptap/vue-starter-kit'
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'
export default {
components: {
EditorContent,
},
data() {
return {
editor: null,
limit: 280,
}
},
mounted() {
this.editor = new Editor({
extensions: [
Document,
Paragraph,
Text,
CharacterCount.configure({
limit: this.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>
`,
})
},
computed: {
characters() {
if (this.editor) {
return this.editor.state.doc.content.size - 2
}
return null
},
},
beforeDestroy() {
this.editor.destroy()
},
}
</script>
<style lang="scss">
/* Basic editor styles */
.ProseMirror {
> * + * {
margin-top: 0.75em;
}
}
.character-limit {
margin-top: 1rem;
color: #868e96;
&--warning {
color: #f03e3e;
}
}
</style>