UNPKG

vue-tippy

Version:

[![npm](https://img.shields.io/npm/v/vue-tippy/latest.svg)](https://www.npmjs.com/package/vue-tippy) [![vue2](https://img.shields.io/badge/vue-3.x-brightgreen.svg)](https://vuejs.org/) [![download](https://img.shields.io/npm/dt/vue-tippy.svg)](https://www

45 lines (39 loc) 1.06 kB
import { TippyInstance, TippyInstances } from '../types' import { createSingleton, CreateSingletonProps, Instance, Props, } from 'tippy.js' import { onMounted, ref } from 'vue' export function useSingleton( instances: TippyInstances, optionalProps?: Partial<CreateSingletonProps<Props>> ) { const singleton = ref<ReturnType<typeof createSingleton>>() onMounted(() => { const pendingTippyInstances: TippyInstance[] = Array.isArray(instances) ? instances.map(i => i.value) : typeof instances === 'function' ? instances() : instances.value const tippyInstances: Instance<any>[] = pendingTippyInstances .map((instance: TippyInstance) => { if (instance instanceof Element) { //@ts-ignore return instance._tippy } return instance }) .filter(Boolean) singleton.value = createSingleton( tippyInstances, optionalProps ? { allowHTML: true, ...optionalProps } : { allowHTML: true } ) }) return { singleton, } }