npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue3-tooltip

v2.2.4

Published

Module for convenient work with tooltips in Vue3 (using a directive and a component)

Downloads

685

Readme

You can find a CodeSandBox containing the module, along with a demonstration of its functionality and the option to customize its styles, by following this link.

Installation

First, let's add a module to your project using npm:

npm install vue3-tooltip

Or you can install using yarn:

yarn add vue3-tooltip

Add dependencies to your main.ts:

import { createApp } from 'vue'
import { TooltipDirective, TooltipComponent } from 'vue3-tooltip';
import 'vue3-tooltip/tooltip.css';

const app = createApp({...})
app.directive('tooltip', TooltipDirective)
app.component('tooltip', TooltipComponent)
app.mount('#app')

Using a Directive

To use tooltip as a directive, simply write v-tooltip="..." on any block in HTML:

<p v-tooltip="`Tooltip text`">Some text</p>

You can also customize a directive using arguments and change its position using modifiers:

v-tooltip:bottom (default) - Change tooltip position to bottom

v-tooltip:top - Change tooltip position to top

v-tooltip:right - Change tooltip position to right

v-tooltip:left - Change tooltip position to left

Arguments for changing color (can be customized):

v-tooltip.primary (default)

v-tooltip.secondary

v-tooltip.accent

Example of using arguments and modifiers:

<p v-tooltip:top="My name is ${name}">My name</p>
<p v-tooltip:bottom.secondary="'I am' + years + 'years old'">My age</p>
<p v-tooltip.accent="`I love writing code`">More info</p>
<p v-tooltip:right.primary="secret">Secret info</p>

Using a Component

To use a component you just need to register it in your template:

<tooltip position="bottom">
    <template v-slot:text>
        <p>Point at me and find out the secret</p>
    </template>
    <template v-slot:tooltip>
        <strong>Watermelon is a berry</strong>
    </template>
</tooltip>

The component has the following props (default values are highlighted in bold):

position ('bottom' | 'top' | 'left' | 'right') - change tooltip position

disable (true | false) - make the tooltip and the text for calling the tooltip inactive

clickable (true | false) - do not hide the tooltip when hovering over it

Style customization

To customize styles, you need to paste your CSS file into main.ts after importing the basic tooltip styles (vue3-tooltip/tooltip.css):

import { TooltipDirective, TooltipComponent } from 'vue3-tooltip';
import 'vue3-tooltip/tooltip.css';
// After this line you need to do your import
import './assets/my-tooltip.scss';

To customize tooltip directive, you need to create a global style file using CSS or Sass. My example demonstrates this process:

.vue-tooltip {
  &::after {
    /*
    * font-size, line-height, max-width, padding, border-radius, box-shadow, transition
    */
  }
  &__primary::after {
    /*
    * background, color
    */
  }
  &__secondary::after {// ... //}
  &__accent::after {// ... //}
}

If you want to explore customization in more detail and change all the classes in the module, you should check them out at this link.

To customize the component, you can also override the standard styles:

.vue-tooltip {
  &.disable {
    // ... //
  }
  &--component {
    /*
    * font-size, line-height, max-width, padding, border-radius, box-shadow, transition
    */
  }
}

You can go deeper into component styles at this link.

Or, instead of redefining classes, you can use variables, on which the entire tooltip design is based. If you want to add new variables, you can write to Issues on GitHub.

:root {
  /* Directive Variables */
  --tooltip-d-transition-duration: 0.4s;
  --tooltip-d-border-radius: 4px;
  --tooltip-d-padding: 2px 4px;
  --tooltip-d-position-x: calc(100% + 10px);
  --tooltip-d-position-y: calc(100% + 2px);
  --tooltip-d-box-shadow: 0px 3.2px 7.2px 0px rgba(0, 0, 0, 0.14),
      0px 0.6px 1.8px 0px rgba(0, 0, 0, 0.1),
      0px -1.5px 6px 0px rgba(0, 0, 0, 0.06);
  --tooltip-d-z-index: 10;
  --tooltip-d-max-width: 200px;
  --tooltip-d-font-size: 14px;
  --tooltip-d-width: max-content;
  --tooltip-d-height: max-content;
  --tooltip-d-outline: none;
  --tooltip-d-border: none;

  /* Component Variables */
  --tooltip-c-transition-duration: 0.4s;
  --tooltip-c-border-radius: 4px;
  --tooltip-c-padding: 2px 4px;
  --tooltip-c-position-x: calc(100% + 10px);
  --tooltip-c-position-y: 100%;
  --tooltip-c-box-shadow: 0px 3.2px 7.2px 0px rgba(0, 0, 0, 0.14),
      0px 0.6px 1.8px 0px rgba(0, 0, 0, 0.1),
      0px -1.5px 6px 0px rgba(0, 0, 0, 0.06);
  --tooltip-c-z-index: 10;
  --tooltip-c-max-width: max-content;
  --tooltip-c-width: max-content;
  --tooltip-c-height: max-content;
  --tooltip-c-outline: none;
  --tooltip-c-border: none;

  /* Colors */
  --tooltip-primary-color: #212121;
  --tooltip-primary-background: #fff;
  --tooltip-seconary-color: #fff;
  --tooltip-seconary-background: #475DEB;
  --tooltip-accent-color: #fff;
  --tooltip-accent-background: #212121;
  
  --tooltip-component-color: #212121;
  --tooltip-component-background: #fff;
}

Contributing

I have a positive attitude towards PR and pull requests. Glad to see that people like the package.

License