forked from halo-sigs/richtext-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BubbleItem.vue
86 lines (82 loc) · 2.1 KB
/
BubbleItem.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<script lang="ts" setup>
import { VTooltip, Dropdown as VDropdown } from "floating-vue";
import type { Editor } from "@tiptap/core";
import { ref, type Component } from "vue";
const props = withDefaults(
defineProps<{
editor: Editor;
isActive: ({ editor }: { editor: Editor }) => boolean;
visible?: ({ editor }: { editor: Editor }) => boolean;
icon?: Component;
iconStyle?: string;
title?: string;
action?: ({ editor }: { editor: Editor }) => Component | void;
}>(),
{
isActive: () => false,
visible: () => true,
title: undefined,
action: undefined,
icon: undefined,
iconStyle: undefined,
}
);
const componentRef = ref<Component | void>();
const handleBubbleItemClick = (editor: Editor) => {
if (!props.action) {
return;
}
const callback = props.action?.({ editor });
if (typeof callback === "object") {
if (componentRef.value) {
componentRef.value = undefined;
} else {
componentRef.value = callback;
}
}
};
</script>
<template>
<VDropdown
class="inline-flex"
:triggers="[]"
:auto-hide="true"
:shown="componentRef"
:distance="10"
>
<button
v-if="visible({ editor })"
v-tooltip="{
content: title,
distance: 8,
delay: {
show: 0,
},
}"
:class="{ 'bg-gray-200 !text-black': isActive({ editor }) }"
:title="title"
class="text-gray-600 text-lg hover:bg-gray-100 p-2 rounded-md"
@click="handleBubbleItemClick(editor)"
>
<component :is="icon" :style="iconStyle" class="w-5 h-5" />
</button>
<template #popper>
<div
class="relative rounded-md bg-white overflow-hidden drop-shadow w-96 p-1 max-h-72 overflow-y-auto"
>
<KeepAlive>
<component :is="componentRef" v-bind="props"></component>
</KeepAlive>
</div>
</template>
</VDropdown>
</template>
<style>
.v-popper__popper.v-popper__popper--show-from .v-popper__wrapper {
transform: scale(0.9);
}
.v-popper__popper.v-popper__popper--show-to .v-popper__wrapper {
transform: none;
transition: transform 0.1s;
}
</style>