chore: include @popperjs/core

This commit is contained in:
Benjamin Canac
2021-11-17 18:18:30 +01:00
parent 53de429e09
commit 915aa62d93
4 changed files with 34 additions and 0 deletions

26
src/utils/popper.ts Normal file
View File

@@ -0,0 +1,26 @@
import { ref, onMounted, watchEffect } from 'vue'
import { createPopper } from '@popperjs/core'
export function usePopper (options: object) {
const reference = ref(null)
const popper = ref(null)
onMounted(() => {
watchEffect((onInvalidate) => {
if (!popper.value) { return }
if (!reference.value) { return }
const popperEl = popper.value.el || popper.value
const referenceEl = reference.value.el || reference.value
if (!(referenceEl instanceof HTMLElement)) { return }
if (!(popperEl instanceof HTMLElement)) { return }
const { destroy } = createPopper(referenceEl, popperEl, options)
onInvalidate(destroy)
})
})
return [reference, popper]
}