@vingy/vueltip 1.2.0 → 1.3.1
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 +74 -18
- package/dist/index.d.mts +7 -7
- package/dist/index.mjs +25 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -19,9 +19,11 @@ pnpm add vueltip
|
|
|
19
19
|
Register the tooltip in your app:
|
|
20
20
|
|
|
21
21
|
```ts
|
|
22
|
-
import
|
|
22
|
+
import { vueltipPlugin, vueltipDirective } from 'vueltip'
|
|
23
23
|
|
|
24
|
-
createApp(App)
|
|
24
|
+
createApp(App)
|
|
25
|
+
.use(vueltipPlugin, { component: Tooltip })
|
|
26
|
+
.directive('tooltip', vueltipDirective)
|
|
25
27
|
```
|
|
26
28
|
|
|
27
29
|
## Usage
|
|
@@ -49,19 +51,18 @@ First, create a tooltip component using the \`useTooltip\` composable:
|
|
|
49
51
|
</template>
|
|
50
52
|
|
|
51
53
|
<script setup>
|
|
52
|
-
import {
|
|
53
|
-
import {
|
|
54
|
+
import { useTemplateRef } from 'vue'
|
|
55
|
+
import { useVueltip } from 'vueltip'
|
|
54
56
|
|
|
55
|
-
const tooltipElement =
|
|
56
|
-
const arrowElement =
|
|
57
|
+
const tooltipElement = useTemplateRef('tooltipElement')
|
|
58
|
+
const arrowElement = useTemplateRef('arrowElement')
|
|
57
59
|
|
|
58
60
|
const { tooltipStyles, arrowStyles, show, content } =
|
|
59
|
-
|
|
61
|
+
useVueltip({
|
|
60
62
|
tooltipElement,
|
|
61
63
|
arrowElement,
|
|
62
64
|
offset: 8,
|
|
63
65
|
padding: 8,
|
|
64
|
-
arrowSize: 10,
|
|
65
66
|
})
|
|
66
67
|
</script>
|
|
67
68
|
|
|
@@ -89,14 +90,16 @@ Import and register the tooltip component and plugin in your app's entry point:
|
|
|
89
90
|
// main.ts
|
|
90
91
|
import { createApp } from 'vue'
|
|
91
92
|
import App from './App.vue'
|
|
92
|
-
import
|
|
93
|
+
import { vueltipPlugin, vueltipDirective } from 'vueltip'
|
|
93
94
|
import Tooltip from './components/Tooltip.vue'
|
|
94
95
|
|
|
95
96
|
const app = createApp(App)
|
|
96
97
|
|
|
97
|
-
app
|
|
98
|
-
|
|
99
|
-
|
|
98
|
+
app
|
|
99
|
+
.use(vueltipPlugin, {
|
|
100
|
+
component: Tooltip,
|
|
101
|
+
})
|
|
102
|
+
.directive('tooltip', vueltipDirective)
|
|
100
103
|
|
|
101
104
|
app.mount('#app')
|
|
102
105
|
```
|
|
@@ -105,20 +108,23 @@ app.mount('#app')
|
|
|
105
108
|
|
|
106
109
|
Now you can use the `v-tooltip` directive on any element:
|
|
107
110
|
|
|
108
|
-
```
|
|
111
|
+
```vue
|
|
109
112
|
<template>
|
|
110
113
|
<div>
|
|
111
|
-
<button v-tooltip="
|
|
112
|
-
Submit
|
|
113
|
-
</button>
|
|
114
|
+
<button v-tooltip="'Click me to submit'">Submit</button>
|
|
114
115
|
|
|
115
116
|
<input
|
|
116
|
-
v-tooltip="
|
|
117
|
+
v-tooltip="'Enter your email address'"
|
|
117
118
|
type="email"
|
|
118
119
|
placeholder="Email"
|
|
119
120
|
/>
|
|
120
121
|
|
|
121
|
-
<span
|
|
122
|
+
<span
|
|
123
|
+
v-tooltip="{
|
|
124
|
+
content: 'This is a helpful tooltip',
|
|
125
|
+
placement: 'right',
|
|
126
|
+
}"
|
|
127
|
+
>
|
|
122
128
|
Hover over me
|
|
123
129
|
</span>
|
|
124
130
|
</div>
|
|
@@ -126,3 +132,53 @@ Now you can use the `v-tooltip` directive on any element:
|
|
|
126
132
|
```
|
|
127
133
|
|
|
128
134
|
See the demo app in [demo/](../../demo/).
|
|
135
|
+
|
|
136
|
+
## Options
|
|
137
|
+
|
|
138
|
+
### Plugin Options
|
|
139
|
+
|
|
140
|
+
The `vueltipPlugin` accepts the following options:
|
|
141
|
+
|
|
142
|
+
| Option | Type | Default | Description |
|
|
143
|
+
| -------------------------- | -------------------------------- | --------------------- | ---------------------------------------------------------------------------------------------------------------------- |
|
|
144
|
+
| `component` | `Component` | Required | The Vue component to render as the tooltip |
|
|
145
|
+
| `showDelay` | `number` | `0` | Delay in milliseconds before the tooltip appears on hover |
|
|
146
|
+
| `hideDelay` | `number` | `200` | Delay in milliseconds before the tooltip disappears when the cursor leaves |
|
|
147
|
+
| `defaultPlacement` | `Placement` | `'top'` | Default tooltip placement: `'top'`, `'bottom'`, `'left'`, `'right'`, etc. |
|
|
148
|
+
| `defaultTruncateDetection` | `'x' \| 'y' \| 'both' \| 'none'` | `'both'` | Direction(s) to check for text truncation (`'x'` for horizontal, `'y'` for vertical, `'both'`, or `'none'` to disable) |
|
|
149
|
+
| `handleDialogModals` | `boolean` | `false` | Whether to handle tooltips within HTML `<dialog>` elements with the `open` attribute (modal dialogs) |
|
|
150
|
+
| `placementAttribute` | `string` | `'vueltip-placement'` | HTML attribute name for tooltip placement overrides |
|
|
151
|
+
| `keyAttribute` | `string` | `'vueltip-key'` | HTML attribute name for tooltip identification |
|
|
152
|
+
| `truncateAttribute` | `string` | `'vueltip-truncate'` | HTML attribute name for truncate detection overrides |
|
|
153
|
+
|
|
154
|
+
### useVueltip Composable Options
|
|
155
|
+
|
|
156
|
+
The `useVueltip` composable accepts the following options:
|
|
157
|
+
|
|
158
|
+
| Option | Type | Default | Description |
|
|
159
|
+
| ----------------- | -------------------------- | -------- | ---------------------------------------------------------- |
|
|
160
|
+
| `tooltipElement` | `Ref<HTMLElement \| null>` | Required | Reference to the tooltip container element |
|
|
161
|
+
| `arrowElement` | `Ref<HTMLElement \| null>` | Optional | Reference to the arrow element for positioning |
|
|
162
|
+
| `offset` | `number` | `0` | Offset distance between the tooltip and the target element |
|
|
163
|
+
| `padding` | `number` | `0` | Padding between the tooltip and the viewport edges |
|
|
164
|
+
| `arrowSize` | `number` | `0` | Size of the arrow element (used for proper positioning) |
|
|
165
|
+
| `floatingOptions` | `UseFloatingOptions` | `{}` | Advanced options for the underlying Floating UI library |
|
|
166
|
+
|
|
167
|
+
### Directive Options
|
|
168
|
+
|
|
169
|
+
The `v-tooltip` directive accepts bindings in two formats:
|
|
170
|
+
|
|
171
|
+
**Simple string (text only):**
|
|
172
|
+
|
|
173
|
+
```ts
|
|
174
|
+
v-tooltip="'Tooltip text'"
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
**Object with options:**
|
|
178
|
+
|
|
179
|
+
```ts
|
|
180
|
+
v-tooltip="{
|
|
181
|
+
content: 'Tooltip text',
|
|
182
|
+
placement: 'right' // Placement: 'top', 'bottom', 'left', 'right', etc.
|
|
183
|
+
}"
|
|
184
|
+
```
|
package/dist/index.d.mts
CHANGED
|
@@ -244,12 +244,16 @@ declare type UseFloatingOptions<T extends ReferenceElement = ReferenceElement> =
|
|
|
244
244
|
whileElementsMounted?: (reference: T, floating: FloatingElement, update: () => void) => () => void;
|
|
245
245
|
};
|
|
246
246
|
//#endregion
|
|
247
|
+
//#region ../shared/dist/types.d.mts
|
|
248
|
+
//#region src/types.d.ts
|
|
249
|
+
type Maybe<T> = T | null | undefined; //#endregion
|
|
250
|
+
//#endregion
|
|
247
251
|
//#region src/types.d.ts
|
|
248
252
|
interface Content {
|
|
249
|
-
text: string
|
|
253
|
+
text: Maybe<string>;
|
|
250
254
|
}
|
|
251
|
-
type Binding = string | {
|
|
252
|
-
content: string | Content
|
|
255
|
+
type Binding = Maybe<string> | {
|
|
256
|
+
content: Maybe<string | Content>;
|
|
253
257
|
placement: Placement;
|
|
254
258
|
};
|
|
255
259
|
type Modifier = 'x' | 'y' | 'none' | 'both';
|
|
@@ -278,10 +282,6 @@ declare module 'vue' {
|
|
|
278
282
|
}
|
|
279
283
|
}
|
|
280
284
|
//#endregion
|
|
281
|
-
//#region ../shared/dist/types.d.mts
|
|
282
|
-
//#region src/types.d.ts
|
|
283
|
-
type Maybe<T> = T | null | undefined; //#endregion
|
|
284
|
-
//#endregion
|
|
285
285
|
//#region src/composables.d.ts
|
|
286
286
|
declare const useVueltip: ({
|
|
287
287
|
tooltipElement,
|
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, createApp,
|
|
3
|
+
import { computed, createApp, 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;
|
|
@@ -1448,11 +1448,21 @@ const sideMap = {
|
|
|
1448
1448
|
};
|
|
1449
1449
|
const useVueltip = ({ tooltipElement, arrowElement, offset: _offset, padding, arrowSize, floatingOptions }) => {
|
|
1450
1450
|
let initialParent;
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1451
|
+
const show = computed(() => !!debouncedHoveredElement.value);
|
|
1452
|
+
watch(show, (value, _, onCleanup) => {
|
|
1453
|
+
if (!value) return;
|
|
1454
|
+
const el = tooltipElement.value;
|
|
1455
|
+
if (!el) return;
|
|
1456
|
+
initialParent = el.parentElement;
|
|
1457
|
+
const onEnter = () => hoveredElement.value = debouncedHoveredElement.value;
|
|
1458
|
+
const onLeave = () => hoveredElement.value = void 0;
|
|
1459
|
+
el.addEventListener("mouseenter", onEnter);
|
|
1460
|
+
el.addEventListener("mouseleave", onLeave);
|
|
1461
|
+
onCleanup(() => {
|
|
1462
|
+
el.removeEventListener("mouseenter", onEnter);
|
|
1463
|
+
el.removeEventListener("mouseleave", onLeave);
|
|
1464
|
+
});
|
|
1465
|
+
}, { flush: "post" });
|
|
1456
1466
|
const middleware = [
|
|
1457
1467
|
offset(_offset),
|
|
1458
1468
|
flip(),
|
|
@@ -1481,7 +1491,6 @@ const useVueltip = ({ tooltipElement, arrowElement, offset: _offset, padding, ar
|
|
|
1481
1491
|
[staticSide.value]: `-${size / 2}px`
|
|
1482
1492
|
};
|
|
1483
1493
|
});
|
|
1484
|
-
const show = computed(() => !!debouncedHoveredElement.value);
|
|
1485
1494
|
if (getOption("handleDialogModals")) watch(show, (value) => {
|
|
1486
1495
|
if (!value || !tooltipElement.value || !debouncedHoveredElement.value || !initialParent) return;
|
|
1487
1496
|
const dialogEl = debouncedHoveredElement.value.closest("dialog");
|
|
@@ -1548,7 +1557,7 @@ const onMouseover = ensureEventTarget((target) => ensureKey(target, (key) => {
|
|
|
1548
1557
|
const content = getContent(key);
|
|
1549
1558
|
if (!content) return;
|
|
1550
1559
|
const { text } = content;
|
|
1551
|
-
if (elementContainsText(target, text) && !isTruncated(target)) return;
|
|
1560
|
+
if (!text || elementContainsText(target, text) && !isTruncated(target)) return;
|
|
1552
1561
|
const placement = target.getAttribute(getOption("placementAttribute"));
|
|
1553
1562
|
tooltipKey.value = key;
|
|
1554
1563
|
hoveredElement.value = target;
|
|
@@ -1561,10 +1570,16 @@ const onMouseout = ensureEventTarget((target) => {
|
|
|
1561
1570
|
|
|
1562
1571
|
//#endregion
|
|
1563
1572
|
//#region src/directive.ts
|
|
1564
|
-
const toContent = (value) =>
|
|
1573
|
+
const toContent = (value) => {
|
|
1574
|
+
if (value == null) return { text: value };
|
|
1575
|
+
if (typeof value === "string") return { text: value };
|
|
1576
|
+
if (value.content == null) return { text: value.content };
|
|
1577
|
+
if (typeof value.content === "string") return { text: value.content };
|
|
1578
|
+
return value.content;
|
|
1579
|
+
};
|
|
1565
1580
|
const extractPlacement = (binding) => {
|
|
1566
1581
|
const { value, arg } = binding;
|
|
1567
|
-
if (typeof value !== "string" && "placement" in value) return value.placement;
|
|
1582
|
+
if (value && typeof value !== "string" && "placement" in value) return value.placement;
|
|
1568
1583
|
if (!arg) return getOption("defaultPlacement");
|
|
1569
1584
|
return arg;
|
|
1570
1585
|
};
|