Add some initial code for the popover service

This commit is contained in:
Ramon Wenger 2024-01-03 23:01:11 +01:00
parent 2953ea4c8e
commit 109ab958fc
2 changed files with 49 additions and 0 deletions

View File

@ -0,0 +1,12 @@
<template>
<div class="highlight-popover">
<h1>Hello</h1>
<button @click="emit('confirm')">Confirm</button>
<button @click="emit('close')">Close</button>
</div>
</template>
<script setup lang="ts">
console.log('hi');
const emit = defineEmits(['close', 'confirm']);
</script>

View File

@ -0,0 +1,37 @@
import HighlightPopover from '@/components/highlights/HighlightPopover.vue';
import { createApp } from 'vue';
type ResolveReject = (v?: unknown) => void;
export default {
show() {
const mountEl = document.createElement('div');
document.body.appendChild(mountEl);
let _resolve: ResolveReject, _reject: ResolveReject;
const promise = new Promise((resolve, reject) => {
_resolve = resolve;
_reject = reject;
});
const cleanUp = () => {
mountEl?.parentNode?.removeChild(mountEl);
popover.unmount();
};
const popover = createApp(HighlightPopover, {
onConfirm() {
cleanUp();
_resolve();
},
onClose() {
cleanUp();
_reject();
},
});
popover.mount(mountEl);
return promise;
},
};