mirror of
https://codeberg.org/Sevichecc/Seigwai.git
synced 2025-04-30 07:49:30 +08:00
Refactor BubbleMenu
This commit is contained in:
parent
4cf8033568
commit
d2f26c1f64
2 changed files with 65 additions and 52 deletions
59
src/components/Tiptap/BubbleMenu.vue
Normal file
59
src/components/Tiptap/BubbleMenu.vue
Normal file
|
@ -0,0 +1,59 @@
|
|||
<script setup lang="ts">
|
||||
import type { Editor
|
||||
} from '@tiptap/vue-3';
|
||||
|
||||
import { BubbleMenu } from '@tiptap/vue-3'
|
||||
|
||||
const { editor } = defineProps<{ editor: Editor }>()
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<BubbleMenu
|
||||
:editor="editor"
|
||||
:tippy-options="{ duration: 100 }"
|
||||
class="flex text-gray-700 bg-white grass rounded-md p-[2px] shadow-xl border-slate-100 border"
|
||||
>
|
||||
<button
|
||||
class="menu-btn"
|
||||
placement="bold"
|
||||
@click="editor.chain().focus().toggleBold().run()"
|
||||
>
|
||||
<span class="i-tabler-bold" />
|
||||
</button>
|
||||
<button
|
||||
class="menu-btn"
|
||||
@click="editor.chain().focus().toggleItalic().run()"
|
||||
>
|
||||
<span class="i-tabler-italic" />
|
||||
</button>
|
||||
<button
|
||||
class="menu-btn"
|
||||
@click="editor.chain().focus().toggleStrike().run()"
|
||||
>
|
||||
<span class="i-tabler-strikethrough" />
|
||||
</button>
|
||||
<button
|
||||
class="menu-btn"
|
||||
@click="editor.chain().focus().toggleCode().run()"
|
||||
>
|
||||
<span class="i-tabler-code" />
|
||||
</button>
|
||||
<button
|
||||
class="menu-btn"
|
||||
@click="editor.chain().focus().toggleBlockquote().run()"
|
||||
>
|
||||
<span class="i-tabler-quote" />
|
||||
</button>
|
||||
</BubbleMenu>
|
||||
</template>
|
||||
|
||||
<style lang="pcss">
|
||||
.menu-btn {
|
||||
@apply btn btn-ghost btn-sm hover:bg-slate-200 rounded-md p-2;
|
||||
}
|
||||
|
||||
.menu-btn > span {
|
||||
@apply w-4;
|
||||
}
|
||||
</style>
|
|
@ -1,7 +1,8 @@
|
|||
<script setup lang="ts">
|
||||
import { BubbleMenu, EditorContent, useEditor } from '@tiptap/vue-3'
|
||||
import { EditorContent, useEditor } from '@tiptap/vue-3'
|
||||
import StarterKit from '@tiptap/starter-kit'
|
||||
import Typography from '@tiptap/extension-typography'
|
||||
import BubbleMenu from './BubbleMenu.vue'
|
||||
|
||||
const editor = useEditor({
|
||||
content: '<p>I’m running Tiptap with Vue.js. 🎉</p>',
|
||||
|
@ -12,55 +13,8 @@ const editor = useEditor({
|
|||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<BubbleMenu
|
||||
v-if="editor"
|
||||
:editor="editor"
|
||||
:tippy-options="{ duration: 100 }"
|
||||
class="flex text-gray-700 bg-white grass rounded-md p-[2px] shadow-xl border-slate-100 border"
|
||||
>
|
||||
<button
|
||||
class="menu-btn"
|
||||
placement="bold"
|
||||
@click="editor?.chain().focus().toggleBold().run()"
|
||||
>
|
||||
<span class="i-tabler-bold" />
|
||||
</button>
|
||||
<button
|
||||
class="menu-btn"
|
||||
@click="editor?.chain().focus().toggleItalic().run()"
|
||||
>
|
||||
<span class="i-tabler-italic" />
|
||||
</button>
|
||||
<button
|
||||
class="menu-btn"
|
||||
@click="editor?.chain().focus().toggleStrike().run()"
|
||||
>
|
||||
<span class="i-tabler-strikethrough" />
|
||||
</button>
|
||||
<button
|
||||
class="menu-btn"
|
||||
@click="editor?.chain().focus().toggleCode().run()"
|
||||
>
|
||||
<span class="i-tabler-code" />
|
||||
</button>
|
||||
<button
|
||||
class="menu-btn"
|
||||
@click="editor?.chain().focus().toggleBlockquote().run()"
|
||||
>
|
||||
<span class="i-tabler-quote" />
|
||||
</button>
|
||||
</BubbleMenu>
|
||||
<EditorContent :editor="editor" />
|
||||
</div>
|
||||
<BubbleMenu
|
||||
v-if="editor"
|
||||
:editor="editor" />
|
||||
<EditorContent :editor="editor" />
|
||||
</template>
|
||||
|
||||
<style lang="pcss">
|
||||
.menu-btn {
|
||||
@apply btn btn-ghost btn-sm hover:bg-slate-200 rounded-md p-2;
|
||||
}
|
||||
|
||||
.menu-btn > span {
|
||||
@apply w-5;
|
||||
}
|
||||
</style>
|
||||
|
|
Loading…
Reference in a new issue