support content slot

This commit is contained in:
Georges KABBOUCHI
2021-01-10 16:19:02 +02:00
parent 98303fa17f
commit 50caf61c2c
2 changed files with 27 additions and 2 deletions
+17
View File
@@ -8,6 +8,23 @@
</tippy>
</div>
<div class="mt-6">
<span class="font-semibold mr-4">Tippy Component with content slot:</span>
<tippy interactive>
<button class="text-sm py-2 px-3 bg-gray-900 text-white rounded-lg">Hi</button>
<template #content>
<button
class="text-sm py-2 px-3 bg-gray-100 text-black rounded-lg"
@click="counter++"
>
Counter {{ counter }} (click to increase)
</button>
</template>
</tippy>
</div>
<div class="mt-6">
<span class="font-semibold mr-4">useTippy + callbacks(console.log):</span>
<button
+10 -2
View File
@@ -51,9 +51,17 @@ Object.keys(tippy.defaultProps).forEach((prop: string) => {
const TippyComponent = defineComponent({
props,
setup(props) {
setup(props, { slots }) {
const elem = ref<Element>()
const tippy = useTippy(elem, props)
let options = { ...props } as TippyOptions
if (slots.content != null && typeof slots.content != 'undefined') {
options.content = {
render: () => slots.content!(),
}
}
const tippy = useTippy(elem, options)
return { elem, ...tippy }
},
render() {