Skip to content

neluckoff/vue3-tooltip

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

32 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
Vue3 Tooltip

โœจ Smart, Elegant Tooltips for Vue 3 โœจ

Auto-positioning โ€ข Touch Support โ€ข Lightweight โ€ข TypeScript

NPM Version Downloads Bundle Size CI Status License

Quick Start โ€ข Features โ€ข Examples โ€ข Full Docs โ€ข Live Demo


npm install vue3-tooltip

or

yarn add vue3-tooltip

โšก Highlights

<!-- Simple as this ๐Ÿ‘‡ -->
<button v-tooltip.auto.touch.primary:top="'Hello World! ๐Ÿ‘‹'">
  Hover or tap me
</button>

3 seconds to install โ€ข Auto-positioning โ€ข Touch support โ€ข Full TypeScript โ€ข 3.9 KB only


โœจ Features

Why developers love Vue3 Tooltip


๐ŸŽฏ

Smart Auto-Positioning

Automatically adjusts position to stay within viewport.
Never goes off-screen!



๐Ÿ“ฑ

Touch Device Support

Perfect on mobile & tablets.
Tap to show, tap outside to hide.



โšก

Lightweight

Only ~3.9 KB gzipped.
Zero dependencies!



๐ŸŽจ

Fully Customizable

All styles via CSS variables.
Match any design system easily.



๐Ÿ”ง

TypeScript First

Full TypeScript support.
Exported types & utilities.



๐Ÿš€

Easy to Use

Simple directive or component.
Works out of the box!



๐Ÿš€ Quick Start

Get up and running in 60 seconds!

๐Ÿ“ฆ Step 1: Install

Choose your favorite package manager:

npm install vue3-tooltip
# or
yarn add vue3-tooltip
# or
pnpm add vue3-tooltip

โš™๏ธ Step 2: Register Plugin

Add to your Vue app (usually main.ts or main.js):

import { createApp } from 'vue';
import VueTooltip from 'vue3-tooltip';
import 'vue3-tooltip/tooltip.css';  // ๐Ÿ‘ˆ Don't forget styles!

const app = createApp(App);
app.use(VueTooltip);  // ๐Ÿ‘ˆ Registers directive & component
app.mount('#app');

๐ŸŽฏ Step 3: Use It!

Option A: As a directive (simplest way)

<button v-tooltip="'Hello World!'">
  Hover me ๐Ÿ‘‹
</button>

Option B: As a component (more control)

<Tooltip>
  <template #text>Hover me ๐Ÿ‘‹</template>
  <template #tooltip>Hello World!</template>
</Tooltip>

That's it! ๐ŸŽ‰ You're ready to go!


๐Ÿ’ก Examples

๐ŸŽฏ Smart Auto-Positioning

The tooltip automatically flips to stay visible in viewport:

<button v-tooltip.auto:bottom="'I adjust my position smartly!'">
  Near screen edge ๐ŸŽฏ
</button>

๐Ÿ’ก Perfect for dropdowns near screen edges - no more cut-off tooltips!

๐Ÿ“ฑ Touch Device Support

Works seamlessly on mobile and tablets:

<button v-tooltip.touch="'Tap me on mobile! ๐Ÿ“ฑ'">
  Mobile & Desktop Ready
</button>

๐Ÿ’ก Automatically detects touch devices and adapts behavior

๐ŸŽจ Color Variants

Choose from three beautiful built-in themes:

<button v-tooltip.primary="'Clean & modern'">Primary</button>
<button v-tooltip.secondary="'Subtle & elegant'">Secondary</button>
<button v-tooltip.accent="'Bold & bright'">Accent</button>

๐Ÿงญ Position Control

Place tooltips exactly where you want them:

<button v-tooltip:top="'โ†‘ Top'">Top</button>
<button v-tooltip:bottom="'โ†“ Bottom'">Bottom</button>
<button v-tooltip:left="'โ† Left'">Left</button>
<button v-tooltip:right="'โ†’ Right'">Right</button>

๐ŸŽญ Combine Modifiers

Mix and match modifiers for powerful tooltips:

<!-- Auto-positioning + Touch + Custom color -->
<button v-tooltip.auto.touch.secondary:top="'The ultimate tooltip! ๐Ÿš€'">
  All Features Combined
</button>

๐Ÿ’ก Pro tip: Chain modifiers like .auto.touch.primary for maximum functionality!


๐Ÿงฉ Component API

For more complex scenarios, use the <Tooltip> component:

Props Reference

Prop Type Default Description
position 'top' | 'bottom' | 'left' | 'right' 'bottom' Tooltip placement
autoPosition boolean false ๐Ÿ†• Auto-adjust to viewport
adaptiveTouch boolean false ๐Ÿ†• Enable touch support
clickable boolean false Keep open on hover
disable boolean false Disable tooltip

Rich Content Example

Perfect for complex HTML content:

<template>
  <Tooltip 
    position="top"
    :auto-position="true"
    :adaptive-touch="true"
  >
    <template #text>
      <button class="my-button">
        ๐Ÿ“Š View Stats
      </button>
    </template>
    
    <template #tooltip>
      <div class="rich-tooltip">
        <h4>๐Ÿ“ˆ User Statistics</h4>
        <p>Active users: <strong>1,234</strong></p>
        <p>Growth: <strong style="color: #10b981">+15%</strong></p>
      </div>
    </template>
  </Tooltip>
</template>

<style scoped>
.rich-tooltip {
  min-width: 200px;
  text-align: left;
}
.rich-tooltip h4 {
  margin: 0 0 8px;
  font-size: 14px;
}
.rich-tooltip p {
  margin: 4px 0;
  font-size: 12px;
}
</style>

๐ŸŽจ Customization

Match your design system effortlessly with CSS variables!

๐ŸŽจ Quick Theme Override

/* In your global CSS */
:root {
  /* Make tooltips match your brand */
  --tooltip-primary-background: #2563eb;
  --tooltip-primary-color: white;
  --tooltip-d-border-radius: 12px;
  --tooltip-d-padding: 8px 16px;
}

๐Ÿ“‹ All Available Variables

๐Ÿ‘‰ Click to see all CSS variables
:root {
  /* ๐Ÿ“ Layout & Positioning */
  --tooltip-d-z-index: 9999;
  --tooltip-d-z-index-hover: 9998;
  --tooltip-d-offset: 10px;
  
  /* ๐ŸŽจ Appearance */
  --tooltip-d-padding: 6px 12px;
  --tooltip-d-border-radius: 6px;
  --tooltip-d-font-size: 14px;
  --tooltip-d-font-weight: 500;
  --tooltip-d-line-height: 1.4;
  
  /* ๐ŸŽฏ Primary Theme */
  --tooltip-primary-background: #ffffff;
  --tooltip-primary-color: #1a1a1a;
  --tooltip-primary-border: 1px solid #e5e5e5;
  --tooltip-primary-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  
  /* ๐ŸŽจ Secondary Theme */
  --tooltip-secondary-background: #f3f4f6;
  --tooltip-secondary-color: #374151;
  
  /* โœจ Accent Theme */
  --tooltip-accent-background: #10b981;
  --tooltip-accent-color: #ffffff;
  
  /* โฑ๏ธ Animations */
  --tooltip-d-transition-duration: 0.3s;
  --tooltip-d-transition-timing: cubic-bezier(0.4, 0, 0.2, 1);
}

๐Ÿ’ก Examples

Dark theme:

:root {
  --tooltip-primary-background: #1f2937;
  --tooltip-primary-color: #f9fafb;
  --tooltip-primary-border: 1px solid #374151;
}

Glassmorphism:

:root {
  --tooltip-primary-background: rgba(255, 255, 255, 0.8);
  --tooltip-primary-backdrop-filter: blur(10px);
  --tooltip-primary-border: 1px solid rgba(255, 255, 255, 0.3);
}

๐Ÿ“– Full documentation: See DOCS.md for complete customization guide


๐Ÿ“š Advanced Usage

๐Ÿ”ง TypeScript Support

Full type safety with exported types and utilities:

import type { Position, Rect, TooltipOptions } from 'vue3-tooltip';
import { getBestPosition, isTouchDevice } from 'vue3-tooltip';

// โœ… Type-safe position
const position: Position = 'bottom';

// โœ… Detect touch devices
const isTouch = isTouchDevice();

// โœ… Smart positioning for custom tooltips
const bestPos = getBestPosition(
  triggerRect,
  tooltipRect,
  'bottom'
);

๐Ÿ› ๏ธ Utility Functions

Build custom tooltip solutions with our utilities:

import {
  getBestPosition,    // ๐ŸŽฏ Find optimal position
  checkPosition,      // โœ… Validate position fits
  isTouchDevice,      // ๐Ÿ“ฑ Detect touch support
  getRect,           // ๐Ÿ“ Get element bounds
  checkOverflow      // ๐Ÿ” Check viewport overflow
} from 'vue3-tooltip';

Example - Custom tooltip positioning:

import { getBestPosition, getRect } from 'vue3-tooltip';

// Get element rectangles
const triggerRect = getRect(buttonElement);
const tooltipRect = getRect(tooltipElement);

// Find best position automatically
const bestPosition = getBestPosition(
  triggerRect, 
  tooltipRect, 
  'top'  // preferred position
);

console.log(bestPosition); // 'top' or alternative if top doesn't fit

๐ŸŽฏ Why Vue3 Tooltip?

Comparison with other popular tooltip libraries:

Feature Vue3 Tooltip Others
๐ŸŽฏ Auto-positioning โœ… Built-in โŒ Manual
๐Ÿ“ฑ Touch support โœ… Adaptive โŒ Desktop only
๐Ÿ”ง TypeScript โœ… Full support โš ๏ธ Partial
๐Ÿ“ฆ Bundle size โœ… 3.9 KB โŒ 10-20 KB
๐ŸŽจ CSS Variables โœ… Fully customizable โš ๏ธ Limited
๐Ÿ“ฆ Dependencies โœ… Zero โŒ Multiple
๐ŸŒณ Tree-shakeable โœ… Yes โš ๏ธ Partial
โšก Vue 3 native โœ… Built for Vue 3 โš ๏ธ Vue 2 ports

๐ŸŒ Browser Support

Works everywhere modern Vue 3 works:

Chrome
Chrome
Firefox
Firefox
Safari
Safari
Edge
Edge
iOS Safari
iOS Safari
Samsung
Samsung
90+ 88+ 14+ 90+ 14+ โœ…

๐Ÿ“– Documentation


๐Ÿ“š Complete Documentation

Full API reference, examples, and guides


๐Ÿ“ Changelog

Version history and migration guides


๐ŸŽฎ Live Demo

Try it in an interactive playground


๐Ÿค Contributing

We welcome contributions! Help us make tooltips better for everyone.

๐Ÿš€ Quick Start for Contributors

# 1๏ธโƒฃ Clone the repository
git clone https://github.com/neluckoff/vue3-tooltip.git
cd vue3-tooltip

# 2๏ธโƒฃ Install dependencies
npm install

# 3๏ธโƒฃ Run tests (watch mode)
npm test

# 4๏ธโƒฃ Build the library
npm run build

# 5๏ธโƒฃ Test locally in your project
npm link

๐Ÿ’ก Ways to Contribute

  • ๐Ÿ› Report bugs - Open an issue
  • โœจ Suggest features - Request a feature
  • ๐Ÿ“– Improve docs - Fix typos, add examples
  • ๐Ÿงช Add tests - Increase coverage
  • ๐ŸŽจ Design - Suggest UX improvements
  • ๐Ÿ’ป Code - Submit pull requests
  • ๐Ÿ›ก๏ธ Security - Report vulnerabilities privately

๐Ÿ“‹ Please read our Contributing Guide before submitting PRs

๐Ÿค By participating, you agree to our Code of Conduct

๐Ÿ”’ Found a security issue? See our Security Policy


๐Ÿ“ License

Released under the MIT License

Copyright ยฉ 2025 Dmitrii Lukianenko



Made with โค๏ธ for the Vue community

Created by @neluckoff

GitHub โ€ข NPM โ€ข Share on Twitter



If you find a bug or have a feature request, please open an issue ๐Ÿ™

About

๐ŸŽฏ Module for convenient work with tooltips in Vue3

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Sponsor this project