@vingy/vueltip 0.2.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +128 -0
- package/dist/index.d.mts +31 -5
- package/dist/index.mjs +16 -9
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# Vueltip
|
|
2
|
+
|
|
3
|
+
A headless tooltip component for Vue.js.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Dynamic Visibility**: The tooltip does not display when the tooltip text is identical to the element's content, unless the content is truncated.
|
|
8
|
+
- **Single Tooltip Instance**: A single tooltip is used, which is repositioned within the window as needed.
|
|
9
|
+
- **Headless Design**: Fully customizable; bring your own component(s) for rendering.
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
To install Vueltip, use npm or yarn:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pnpm add vueltip
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Register the tooltip in your app:
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import Vueltip from 'vueltip'
|
|
23
|
+
|
|
24
|
+
createApp(App).use(Vueltip)
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
### 1. Create a Tooltip Component
|
|
30
|
+
|
|
31
|
+
First, create a tooltip component using the \`useTooltip\` composable:
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
<!-- Tooltip.vue -->
|
|
35
|
+
<template>
|
|
36
|
+
<div
|
|
37
|
+
ref="tooltipElement"
|
|
38
|
+
v-show="show"
|
|
39
|
+
:style="tooltipStyles"
|
|
40
|
+
class="tooltip"
|
|
41
|
+
>
|
|
42
|
+
{{ content }}
|
|
43
|
+
<div
|
|
44
|
+
ref="arrowElement"
|
|
45
|
+
:style="arrowStyles"
|
|
46
|
+
class="tooltip-arrow"
|
|
47
|
+
/>
|
|
48
|
+
</div>
|
|
49
|
+
</template>
|
|
50
|
+
|
|
51
|
+
<script setup>
|
|
52
|
+
import { ref } from 'vue'
|
|
53
|
+
import { useTooltip } from 'vueltip'
|
|
54
|
+
|
|
55
|
+
const tooltipElement = ref()
|
|
56
|
+
const arrowElement = ref()
|
|
57
|
+
|
|
58
|
+
const { tooltipStyles, arrowStyles, show, content } =
|
|
59
|
+
useTooltip({
|
|
60
|
+
tooltipElement,
|
|
61
|
+
arrowElement,
|
|
62
|
+
offset: 8,
|
|
63
|
+
padding: 8,
|
|
64
|
+
arrowSize: 10,
|
|
65
|
+
})
|
|
66
|
+
</script>
|
|
67
|
+
|
|
68
|
+
<style scoped>
|
|
69
|
+
.tooltip {
|
|
70
|
+
background: #333;
|
|
71
|
+
color: white;
|
|
72
|
+
padding: 8px 12px;
|
|
73
|
+
border-radius: 4px;
|
|
74
|
+
font-size: 14px;
|
|
75
|
+
z-index: 9999;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.tooltip-arrow {
|
|
79
|
+
background: #333;
|
|
80
|
+
}
|
|
81
|
+
</style>
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### 2. Register in Your App
|
|
85
|
+
|
|
86
|
+
Import and register the tooltip component and plugin in your app's entry point:
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
// main.ts
|
|
90
|
+
import { createApp } from 'vue'
|
|
91
|
+
import App from './App.vue'
|
|
92
|
+
import Vueltip from 'vueltip'
|
|
93
|
+
import Tooltip from './components/Tooltip.vue'
|
|
94
|
+
|
|
95
|
+
const app = createApp(App)
|
|
96
|
+
|
|
97
|
+
app.use(Vueltip, {
|
|
98
|
+
component: Tooltip,
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
app.mount('#app')
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### 3. Use the Directive
|
|
105
|
+
|
|
106
|
+
Now you can use the `v-tooltip` directive on any element:
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
<template>
|
|
110
|
+
<div>
|
|
111
|
+
<button v-tooltip="{ text: 'Click me to submit' }">
|
|
112
|
+
Submit
|
|
113
|
+
</button>
|
|
114
|
+
|
|
115
|
+
<input
|
|
116
|
+
v-tooltip="{ text: 'Enter your email address' }"
|
|
117
|
+
type="email"
|
|
118
|
+
placeholder="Email"
|
|
119
|
+
/>
|
|
120
|
+
|
|
121
|
+
<span v-tooltip="{ text: 'This is a helpful tooltip' }">
|
|
122
|
+
Hover over me
|
|
123
|
+
</span>
|
|
124
|
+
</div>
|
|
125
|
+
</template>
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
See the demo app in [demo/](../../demo/).
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as __reExport, t as __exportAll } from "./chunk-CtajNgzt.mjs";
|
|
2
2
|
import * as Vue from "vue";
|
|
3
|
-
import { ShallowRef, StyleValue } from "vue";
|
|
3
|
+
import { App, Component, Directive, ShallowRef, StyleValue } from "vue";
|
|
4
4
|
|
|
5
5
|
//#region ../../node_modules/.pnpm/@floating-ui+utils@0.2.10/node_modules/@floating-ui/utils/dist/floating-ui.utils.d.mts
|
|
6
6
|
declare type AlignedPlacement = `${Side}-${Alignment}`;
|
|
@@ -248,6 +248,11 @@ declare type UseFloatingOptions<T extends ReferenceElement = ReferenceElement> =
|
|
|
248
248
|
interface Content {
|
|
249
249
|
text: string;
|
|
250
250
|
}
|
|
251
|
+
type Binding = string | {
|
|
252
|
+
content: string | Content;
|
|
253
|
+
placement: Placement;
|
|
254
|
+
};
|
|
255
|
+
type TooltipDirective = Directive<HTMLElement, Binding>;
|
|
251
256
|
type Options = {
|
|
252
257
|
/** @default 'tooltip-placement' */placementAttribute: string; /** @default 'tooltip-key' */
|
|
253
258
|
keyAttribute: string; /** @default 0 */
|
|
@@ -263,9 +268,18 @@ type UseTooltipOptions = {
|
|
|
263
268
|
arrowSize?: number;
|
|
264
269
|
floatingOptions?: UseFloatingOptions<HTMLElement>;
|
|
265
270
|
};
|
|
271
|
+
declare module 'vue' {
|
|
272
|
+
interface GlobalDirectives {
|
|
273
|
+
vTooltip: TooltipDirective;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
//#endregion
|
|
277
|
+
//#region ../shared/dist/types.d.mts
|
|
278
|
+
//#region src/types.d.ts
|
|
279
|
+
type Maybe<T> = T | null | undefined; //#endregion
|
|
266
280
|
//#endregion
|
|
267
281
|
//#region src/composables.d.ts
|
|
268
|
-
declare const
|
|
282
|
+
declare const useVueltip: ({
|
|
269
283
|
tooltipElement,
|
|
270
284
|
arrowElement,
|
|
271
285
|
offset: _offset,
|
|
@@ -291,9 +305,21 @@ declare const useTooltip: ({
|
|
|
291
305
|
content: Vue.Ref<Maybe<Content>, Maybe<Content>>;
|
|
292
306
|
};
|
|
293
307
|
//#endregion
|
|
308
|
+
//#region src/directive.d.ts
|
|
309
|
+
declare const vueltipDirective: {
|
|
310
|
+
updated: (el: HTMLElement, binding: Vue.DirectiveBinding<Binding, string, any>) => void;
|
|
311
|
+
created: (el: HTMLElement, binding: Vue.DirectiveBinding<Binding, string, any>) => void;
|
|
312
|
+
beforeUnmount: (el: HTMLElement) => void;
|
|
313
|
+
};
|
|
314
|
+
//#endregion
|
|
315
|
+
//#region src/options.d.ts
|
|
316
|
+
declare const setOptions: (opts?: Partial<Options>) => void;
|
|
317
|
+
//#endregion
|
|
294
318
|
//#region src/plugin.d.ts
|
|
295
|
-
declare const
|
|
296
|
-
install: (app:
|
|
319
|
+
declare const vueltipPlugin: {
|
|
320
|
+
install: (app: App, options: Partial<Options & {
|
|
321
|
+
component: Component;
|
|
322
|
+
}>) => void;
|
|
297
323
|
};
|
|
298
324
|
//#endregion
|
|
299
|
-
export { type Content,
|
|
325
|
+
export { type Content, setOptions, useVueltip, vueltipDirective, vueltipPlugin };
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as __reExport, t as __exportAll } from "./chunk-CtajNgzt.mjs";
|
|
2
2
|
import * as Vue from "vue";
|
|
3
|
-
import { computed, onMounted, ref, watch } from "vue";
|
|
3
|
+
import { computed, createApp, onMounted, ref, watch } from "vue";
|
|
4
4
|
|
|
5
5
|
//#region ../../node_modules/.pnpm/@floating-ui+utils@0.2.10/node_modules/@floating-ui/utils/dist/floating-ui.utils.mjs
|
|
6
6
|
const min = Math.min;
|
|
@@ -1390,8 +1390,8 @@ function useFloating(reference, floating, options) {
|
|
|
1390
1390
|
//#endregion
|
|
1391
1391
|
//#region src/options.ts
|
|
1392
1392
|
let options = {
|
|
1393
|
-
placementAttribute: "
|
|
1394
|
-
keyAttribute: "
|
|
1393
|
+
placementAttribute: "vueltip-placement",
|
|
1394
|
+
keyAttribute: "vueltip-key",
|
|
1395
1395
|
showDelay: 0,
|
|
1396
1396
|
hideDelay: 200,
|
|
1397
1397
|
handleDialogModals: false
|
|
@@ -1441,7 +1441,7 @@ const sideMap = {
|
|
|
1441
1441
|
bottom: "top",
|
|
1442
1442
|
left: "right"
|
|
1443
1443
|
};
|
|
1444
|
-
const
|
|
1444
|
+
const useVueltip = ({ tooltipElement, arrowElement, offset: _offset, padding, arrowSize, floatingOptions }) => {
|
|
1445
1445
|
let initialParent;
|
|
1446
1446
|
onMounted(() => {
|
|
1447
1447
|
initialParent = tooltipElement.value?.parentElement;
|
|
@@ -1547,7 +1547,7 @@ const onMouseout = ensureEventTarget((target) => {
|
|
|
1547
1547
|
//#region src/directive.ts
|
|
1548
1548
|
const toContent = (value) => typeof value === "string" ? { text: value } : typeof value.content === "string" ? { text: value.content } : value.content;
|
|
1549
1549
|
const extractPlacement = (value) => typeof value === "string" ? "top" : value.placement;
|
|
1550
|
-
const
|
|
1550
|
+
const vueltipDirective = {
|
|
1551
1551
|
updated: (el, binding) => {
|
|
1552
1552
|
ensureKey(el, (key) => setContent(key, toContent(binding.value)));
|
|
1553
1553
|
},
|
|
@@ -1572,10 +1572,17 @@ const tooltipDirective = {
|
|
|
1572
1572
|
|
|
1573
1573
|
//#endregion
|
|
1574
1574
|
//#region src/plugin.ts
|
|
1575
|
-
const
|
|
1576
|
-
|
|
1577
|
-
|
|
1575
|
+
const vueltipPlugin = { install: (app, options) => {
|
|
1576
|
+
const { component, ...rest } = options;
|
|
1577
|
+
setOptions(rest);
|
|
1578
|
+
if (!component) return;
|
|
1579
|
+
const container = document.createElement("div");
|
|
1580
|
+
container.id = "__vueltip_root__";
|
|
1581
|
+
document.body.appendChild(container);
|
|
1582
|
+
const tooltipApp = createApp(component);
|
|
1583
|
+
tooltipApp._context = app._context;
|
|
1584
|
+
tooltipApp.mount(container);
|
|
1578
1585
|
} };
|
|
1579
1586
|
|
|
1580
1587
|
//#endregion
|
|
1581
|
-
export {
|
|
1588
|
+
export { setOptions, useVueltip, vueltipDirective, vueltipPlugin };
|