support content slot
This commit is contained in:
@@ -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
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user