Vue Tippy

VueTippy is a Vue 3 wrapper for the Tippy.js library, which allows you to use the tooltips as a Vue component and as a directive.

Getting Started

Installation

Run the command below to install the Vue Tippy package.

npm install vue-tippy@v6

Create Plugin

Create a plugin to add Vue Tippy globally to your Nuxt application.

Here I added some configurations to the plugin, like the default animation, delay, trigger, and touch.

Feel free to change these configurations to fit your needs.

import VueTippy from "vue-tippy";
import type { TippyPluginOptions } from "vue-tippy";

import "tippy.js/animations/scale.css";
import "tippy.js/animations/shift-away.css";
import "tippy.js/animations/shift-toward.css";
import "tippy.js/animations/perspective.css";

export default defineNuxtPlugin((nuxtApp) => {
  nuxtApp.vueApp.use(VueTippy, {
    component: "Tippy",
    directive: "tippy",
    defaultProps: {
      animation: "shift-away",
      delay: [200, 100],
      trigger: "mouseenter",
      touch: ["hold", 500],
      arrow: false,
    },
  } satisfies TippyPluginOptions);
});

Add CSS

Create a new CSS file and add the following code to it.

[data-tippy-root] {
  .tippy-box {
    @apply rounded-md bg-background px-2 py-1 text-foreground shadow ring-1 ring-border;
    .tippy-content {
      @apply text-[13px];
    }
  }

  .tippy-box[data-theme~="error"] {
    @apply bg-destructive text-destructive-foreground ring-destructive;
  }
}

Usage

There are three(3) ways in which you can use Vue Tippy:

Directive

We can add the v-tippy directive to any element to show a tooltip.

The directive accepts a string with the content of the tooltip OR an object with the content and the options.

Check out the Directive Docs to learn more.

Component

We can use the <Tippy/> component to show a tooltip.

You can visit the Component Docs to see some more examples of how this component can be used.

Building a Design System with Nuxt and Tailwind CSS

Learn how to build a comprehensive design system using Tailwind CSS, including component architecture, and theme customization.

8 min read Updated 2 days ago

Additional Props

Do note that these additional props can be added to the component

PropTypeDefaultDescription
tagString"span"Trigger wrapper tag
content-tagString"span"Content wrapper tag
content-classStringnullContent wrapper class
toElement or StringnullTarget selector

Composition API

We can import nd use the useTippy composable to show a tooltip.

This is a low-level, flexible composition, ideal for building tooltips with complex interactions.

You can visit the Composition API Docs to see some more examples of how this composition can be used.

Vue Tippy Examples

Here are some examples taken from the Vue Tippy documentation.

Follow Mouse

This example shows how to create a tooltip that follows the mouse.

Context Menu

This example shows how to create a context menu using Vue Tippy.

Right Click Anywhere

Trigger Target

This example shows how to create a tooltip that is triggered by another element.

All the magic is here!

Origin UI Examples

These are some examples that I found today over here Origin Ui. I think they are cool.

To use these examples you will have to copy the code and adjust it for your own use.

Title

Tooltip with title

Tooltips are made to be highly customizable, with features like dynamic placement, rich content, and a robust API. You can even use them as a full-featured dropdown menu by setting the trigger prop to click.

Icon

Tooltip with title and icon

Tooltips are made to be highly customizable, with features like dynamic placement, rich content, and a robust API.

Image

Content image

Tooltip with title and icon

Tooltips are made to be highly customizable, with features like dynamic placement, rich content, and a robust API.

Pan

Stats

  • StatusCompleted
  • Code Coverage94.3%
  • Last DeployToday at 15:42
  • Performance Score98/100

Chart

Tuesday, Aug 13
Sales $40
Revenue $74
Costs $410