Merge pull request #205 from raymondmuller/string-support

feat: string support
This commit is contained in:
Georges KABBOUCHI
2021-10-02 02:07:10 +03:00
committed by GitHub
4 changed files with 17 additions and 3 deletions
+1
View File
@@ -48,6 +48,7 @@ app.mount('#app')
```html
<template>
<button v-tippy="{ content: 'Hi!' }">Tippy!</button>
<button v-tippy="'Hello!'">Tippy!</button>
</template>
<!--
+1
View File
@@ -10,6 +10,7 @@ position: 4
```html
<template>
<button v-tippy="{ content: 'Hi!' }">Tippy!</button>
<button v-tippy="'Hello!'">Tippy!</button>
</template>
<!--
+13 -1
View File
@@ -176,12 +176,24 @@
<div class="mt-6">
<span class="font-semibold mr-4">v-tippy:</span>
<button
class="text-sm py-2 px-3 bg-gray-900 text-white rounded-lg"
class="text-sm py-2 px-3 mr-4 bg-gray-900 text-white rounded-lg"
@tippyMount="() => log('v-tippy mounted')"
v-tippy="{ content: 'Hello ' + counter }"
>
Tippy directive
</button>
<button
class="text-sm py-2 px-3 mr-4 bg-gray-900 text-white rounded-lg"
v-tippy="'Passing in a string'"
>
Tippy directive with a string
</button>
<button
class="text-sm py-2 px-3 bg-gray-900 text-white rounded-lg"
v-tippy="`Hello ${counter}`"
>
Tippy directive with template literals
</button>
</div>
<div class="mt-6 space-x-2">
+2 -2
View File
@@ -3,7 +3,7 @@ import { Directive } from 'vue'
const directive: Directive = {
mounted(el, binding, vnode) {
const opts = binding.value || {}
const opts = typeof binding.value === "string" ? { content: binding.value } : binding.value || {}
if (vnode.props && vnode.props.onTippyShow) {
opts.onShow = function (...args: any[]) {
@@ -55,7 +55,7 @@ const directive: Directive = {
},
updated(el, binding) {
const opts = binding.value || {}
const opts = typeof binding.value === "string" ? { content: binding.value } : binding.value || {}
if (el.getAttribute('title') && !opts.content) {
opts.content = el.getAttribute('title')