From c8d73053e1bd103906aa6381a70213163b17e248 Mon Sep 17 00:00:00 2001 From: Abdul Al-Hasany Date: Sun, 22 Oct 2023 12:01:49 +1100 Subject: [PATCH] feat: expose toggleTooltip function --- docs/guide/usage/composition-api.md | 4 +++- package.json | 3 +-- src/VuePopper.vue | 3 ++- src/composable.ts | 1 + 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/docs/guide/usage/composition-api.md b/docs/guide/usage/composition-api.md index 9964560..20c49c3 100644 --- a/docs/guide/usage/composition-api.md +++ b/docs/guide/usage/composition-api.md @@ -14,7 +14,8 @@ const VuePopperOptions = { const { popperInstance, triggerElement, - tooltipElement + tooltipElement, + toggleTooltip } = useVuePopper(VuePopperOptions); ``` @@ -23,6 +24,7 @@ As you notice, the `useVuePopper` returns an object with three properties: - `popperInstance`: The popper instance. It will give you access to the popper instance. - `triggerElement`: The trigger element. Use this to add the trigger element. - `tooltipElement`: The tooltip element. Use this to add the tooltip element. +- `toggleTooltip`: A function to toggle the tooltip visibility. Optionally pass a value of ('hide' or 'show') to force the tooltip to hide or show. We can use these in template to add the trigger and tooltip elements. Like this: diff --git a/package.json b/package.json index c378e28..84c1356 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@kalimahapps/vue-popper", "description": "vue3 tooltip component based on popperjs", - "version": "1.1.8", + "version": "1.1.9", "sideEffects": false, "repository": { "type": "git", @@ -29,7 +29,6 @@ "author": "khr2003", "license": "MIT", "dependencies": { - "@kalimahapps/vue-popper": "^1.1.7", "@popperjs/core": "^2.11.8", "@vueuse/core": "^10.4.1" }, diff --git a/src/VuePopper.vue b/src/VuePopper.vue index dc8829a..38eb22d 100644 --- a/src/VuePopper.vue +++ b/src/VuePopper.vue @@ -154,7 +154,7 @@ if (Object.keys(props.popperOptions).length > 0) { console.warn('@kalimahapps/vue-popper: popperOptions is deprecated. Use the individual props instead.'); } -const { popperInstance, triggerElement, tooltipElement, isOpened } = useVuePopper({ +const { popperInstance, triggerElement, tooltipElement, isOpened, toggleTooltip } = useVuePopper({ hover: props.hover, disableClickOutside: props.disableClickOutside, openDelay: props.openDelay, @@ -183,5 +183,6 @@ defineExpose({ isOpened: computed(() => { return isOpened.value; }), + toggleTooltip, }); diff --git a/src/composable.ts b/src/composable.ts index 6b6b42f..caefdb6 100644 --- a/src/composable.ts +++ b/src/composable.ts @@ -544,6 +544,7 @@ const useVuePopper = function (suppliedOptions: Options = {}) { triggerElement, tooltipElement, popperInstance, + toggleTooltip, isOpened: computed(() => { return isOpened.value; }), }; };