KABBOUCHI / vue-tippy

VueJS Tooltip powered by Tippy.js
https://vue-tippy.netlify.app
MIT License
722 stars 86 forks source link

Simplify the Composition API and avoid passing a ref #298

Open edimitchel opened 10 months ago

edimitchel commented 10 months ago

I take a look on the way tippy is used in Composition API, and I wondering if it could be simplified ?

Instead of creating and passing a target ref like:

<template>
  <button ref="btn">Tippy!</button>
</template>

<script setup>
import { useTippy } from 'vue-tippy'
import Counter from '@components/Counter.vue'

const btn = ref()

useTippy(btn, {
  content: h(Counter, { initialCount: 42 }),
  arrow: true,
})
</script>

... take the target returned by the composable and pass it to the dom:

<template>
  <button ref="btn">Tippy!</button>
</template>

<script setup>
import { useTippy } from 'vue-tippy'
import Counter from '@components/Counter.vue'

const { target: btn } = useTippy({
  content: h(Counter, { initialCount: 42 }),
  arrow: true,
})
</script>

The composable would be responsible to create the ref, then reassigned by Vue on mounting.

What do you think?

KABBOUCHI commented 10 months ago

maybe like this?

const { target: btn } = useTippy({
  content: h(Counter, { initialCount: 42 }),
  arrow: true,
})
edimitchel commented 10 months ago

Yes sorry, I forgot to remove the btn param