add menus example

This commit is contained in:
Philipp Kühn
2021-04-01 16:56:56 +02:00
parent 17726770d2
commit 136f6e47a9
11 changed files with 77 additions and 24 deletions

View File

@@ -0,0 +1,89 @@
<template>
<div style="position: relative">
<bubble-menu :editor="editor" v-if="editor">
<button @click="editor.chain().focus().toggleBold().run()" :class="{ 'is-active': editor.isActive('bold') }">
bold
</button>
<button @click="editor.chain().focus().toggleItalic().run()" :class="{ 'is-active': editor.isActive('italic') }">
italic
</button>
<button @click="editor.chain().focus().toggleCode().run()" :class="{ 'is-active': editor.isActive('code') }">
code
</button>
</bubble-menu>
<floating-menu :editor="editor" v-if="editor">
<button @click="editor.chain().focus().toggleHeading({ level: 1 }).run()" :class="{ 'is-active': editor.isActive('heading', { level: 1 }) }">
h1
</button>
<button @click="editor.chain().focus().toggleHeading({ level: 2 }).run()" :class="{ 'is-active': editor.isActive('heading', { level: 2 }) }">
h2
</button>
<button @click="editor.chain().focus().toggleBulletList().run()" :class="{ 'is-active': editor.isActive('bulletList') }">
bullet list
</button>
</floating-menu>
<editor-content :editor="editor" />
</div>
</template>
<script>
import {
Editor,
EditorContent,
BubbleMenu,
FloatingMenu,
} from '@tiptap/vue-2'
import { defaultExtensions } from '@tiptap/starter-kit'
export default {
components: {
EditorContent,
BubbleMenu,
FloatingMenu,
},
data() {
return {
editor: null,
}
},
mounted() {
this.editor = new Editor({
extensions: [
...defaultExtensions(),
],
content: `
<p>
Hey, try to select some text here. Youll see a formatting menu pop up. And as always, you are in full control about content and styling of this menu.
</p>
`,
})
},
beforeDestroy() {
this.editor.destroy()
},
}
</script>
<style lang="scss">
/* Basic editor styles */
.ProseMirror {
> * + * {
margin-top: 0.75em;
}
ul,
ol {
padding: 0 1rem;
}
blockquote {
padding-left: 1rem;
border-left: 2px solid rgba(#0D0D0D, 0.1);
}
}
</style>