@vingy/vueltip 2.0.0 → 2.1.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 +59 -0
- package/dist/basicTooltip.css +42 -0
- package/dist/index.d.mts +10 -7
- package/dist/index.mjs +34 -3
- package/package.json +6 -3
package/README.md
CHANGED
|
@@ -139,6 +139,65 @@ Now you can use the `v-tooltip` directive on any element:
|
|
|
139
139
|
|
|
140
140
|
See the demo app in [demo/](../../demo/).
|
|
141
141
|
|
|
142
|
+
## Basic Tooltip Component
|
|
143
|
+
|
|
144
|
+
Vueltip provides a pre-built `BasicTooltip` component with default styling that you can use out of the box:
|
|
145
|
+
|
|
146
|
+
```ts
|
|
147
|
+
import {
|
|
148
|
+
vueltipPlugin,
|
|
149
|
+
vueltipDirective,
|
|
150
|
+
BasicTooltip,
|
|
151
|
+
} from '@vingy/vueltip'
|
|
152
|
+
import '@vingy/vueltip/basicTooltip.css'
|
|
153
|
+
|
|
154
|
+
const app = createApp(App)
|
|
155
|
+
|
|
156
|
+
app
|
|
157
|
+
.use(vueltipPlugin, {
|
|
158
|
+
component: BasicTooltip,
|
|
159
|
+
})
|
|
160
|
+
.directive('tooltip', vueltipDirective)
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Theming the Basic Tooltip
|
|
164
|
+
|
|
165
|
+
The `BasicTooltip` component uses CSS custom properties for theming. You can customize it in two ways:
|
|
166
|
+
|
|
167
|
+
**1. Use the default theme:**
|
|
168
|
+
|
|
169
|
+
Import the provided CSS file for automatic light/dark mode support:
|
|
170
|
+
|
|
171
|
+
```ts
|
|
172
|
+
import '@vingy/vueltip/basicTooltip.css'
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
**2. Override with custom CSS variables:**
|
|
176
|
+
|
|
177
|
+
Define your own theme by setting CSS variables:
|
|
178
|
+
|
|
179
|
+
```css
|
|
180
|
+
.vueltip-theme {
|
|
181
|
+
--vueltip-bg: hotpink;
|
|
182
|
+
--vueltip-text: white;
|
|
183
|
+
--vueltip-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
|
|
184
|
+
--vueltip-border-radius: 8px;
|
|
185
|
+
--vueltip-padding: 8px 12px;
|
|
186
|
+
--vueltip-font-size: 16px;
|
|
187
|
+
--vueltip-font-weight: 500;
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
**Available CSS variables:**
|
|
192
|
+
|
|
193
|
+
- `--vueltip-bg`: Background color
|
|
194
|
+
- `--vueltip-text`: Text color
|
|
195
|
+
- `--vueltip-shadow`: Box shadow
|
|
196
|
+
- `--vueltip-border-radius`: Border radius
|
|
197
|
+
- `--vueltip-padding`: Content padding
|
|
198
|
+
- `--vueltip-font-size`: Font size
|
|
199
|
+
- `--vueltip-font-weight`: Font weight
|
|
200
|
+
|
|
142
201
|
## Options
|
|
143
202
|
|
|
144
203
|
### Plugin Options
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
.vueltip-theme {
|
|
2
|
+
isolation: isolate;
|
|
3
|
+
|
|
4
|
+
--vueltip-bg: rgb(241, 245, 249);
|
|
5
|
+
--vueltip-text: rgb(15, 23, 42);
|
|
6
|
+
--vueltip-shadow:
|
|
7
|
+
0 10px 15px -3px rgba(0, 0, 0, 0.1),
|
|
8
|
+
0 4px 6px -4px rgba(0, 0, 0, 0.1);
|
|
9
|
+
--vueltip-border-radius: 4px;
|
|
10
|
+
--vueltip-padding: 4px 8px;
|
|
11
|
+
--vueltip-font-size: 14px;
|
|
12
|
+
--vueltip-font-weight: 600;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
@media (prefers-color-scheme: dark) {
|
|
16
|
+
.vueltip-theme {
|
|
17
|
+
--vueltip-bg: rgb(30, 41, 59);
|
|
18
|
+
--vueltip-text: rgb(248, 250, 252);
|
|
19
|
+
--vueltip-shadow:
|
|
20
|
+
0 10px 15px -3px rgba(0, 0, 0, 0.5),
|
|
21
|
+
0 4px 6px -4px rgba(0, 0, 0, 0.5);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.vueltip-arrow {
|
|
26
|
+
pointer-events: none;
|
|
27
|
+
position: absolute;
|
|
28
|
+
z-index: 0;
|
|
29
|
+
background: var(--vueltip-bg);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.vueltip-content {
|
|
33
|
+
position: relative;
|
|
34
|
+
z-index: 10;
|
|
35
|
+
border-radius: var(--vueltip-border-radius);
|
|
36
|
+
background: var(--vueltip-bg);
|
|
37
|
+
padding: var(--vueltip-padding);
|
|
38
|
+
font-size: var(--vueltip-font-size);
|
|
39
|
+
font-weight: var(--vueltip-font-weight);
|
|
40
|
+
color: var(--vueltip-text);
|
|
41
|
+
box-shadow: var(--vueltip-shadow);
|
|
42
|
+
}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as vue from "vue";
|
|
2
2
|
import { App, Component, Directive, DirectiveBinding, ShallowRef, StyleValue } from "vue";
|
|
3
3
|
|
|
4
|
+
//#region src/basicTooltip.component.d.ts
|
|
5
|
+
declare const BasicTooltip: vue.DefineSetupFnComponent<Record<string, any>, {}, {}, Record<string, any> & {}, vue.PublicProps>;
|
|
6
|
+
//#endregion
|
|
4
7
|
//#region ../../node_modules/.pnpm/@floating-ui+utils@0.2.10/node_modules/@floating-ui/utils/dist/floating-ui.utils.d.mts
|
|
5
8
|
declare type AlignedPlacement = `${Side}-${Alignment}`;
|
|
6
9
|
declare type Alignment = 'start' | 'end';
|
|
@@ -202,7 +205,7 @@ declare const install: (vue?: any) => void;
|
|
|
202
205
|
* @deprecated To avoid bringing in all the tree-shakable modules, this API has been deprecated. Use `Vue2` or named exports instead.
|
|
203
206
|
* Refer to https://github.com/vueuse/vue-demi/issues/41
|
|
204
207
|
*/
|
|
205
|
-
declare const V: typeof
|
|
208
|
+
declare const V: typeof vue;
|
|
206
209
|
declare function set<T>(target: any, key: any, val: T): T;
|
|
207
210
|
declare function del(target: any, key: any): void;
|
|
208
211
|
//#endregion
|
|
@@ -291,7 +294,7 @@ declare const useVueltip: ({
|
|
|
291
294
|
arrowSize,
|
|
292
295
|
floatingOptions
|
|
293
296
|
}: UseTooltipOptions) => {
|
|
294
|
-
tooltipStyles: Readonly<
|
|
297
|
+
tooltipStyles: Readonly<vue.Ref<{
|
|
295
298
|
position: Strategy;
|
|
296
299
|
top: string;
|
|
297
300
|
left: string;
|
|
@@ -304,9 +307,9 @@ declare const useVueltip: ({
|
|
|
304
307
|
transform?: string;
|
|
305
308
|
willChange?: string;
|
|
306
309
|
}>>;
|
|
307
|
-
arrowStyles:
|
|
308
|
-
show:
|
|
309
|
-
content:
|
|
310
|
+
arrowStyles: vue.ComputedRef<StyleValue>;
|
|
311
|
+
show: vue.ComputedRef<boolean>;
|
|
312
|
+
content: vue.Ref<Maybe<Content>, Maybe<Content>>;
|
|
310
313
|
};
|
|
311
314
|
//#endregion
|
|
312
315
|
//#region src/directive.d.ts
|
|
@@ -326,4 +329,4 @@ declare const vueltipPlugin: {
|
|
|
326
329
|
}>) => void;
|
|
327
330
|
};
|
|
328
331
|
//#endregion
|
|
329
|
-
export { type Content, type CustomVueltipData, setOptions, useVueltip, vueltipDirective, vueltipPlugin };
|
|
332
|
+
export { BasicTooltip, type Content, type CustomVueltipData, 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, createApp, ref, watch } from "vue";
|
|
3
|
+
import { computed, createApp, defineComponent, h, ref, useTemplateRef, 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;
|
|
@@ -1409,10 +1409,17 @@ const getOption = (key) => options[key];
|
|
|
1409
1409
|
|
|
1410
1410
|
//#endregion
|
|
1411
1411
|
//#region src/state.ts
|
|
1412
|
+
let timerId;
|
|
1412
1413
|
const tooltipPlacement = ref("top");
|
|
1413
1414
|
const debouncedTooltipPlacement = ref("top");
|
|
1414
1415
|
const hoveredElement = ref();
|
|
1415
1416
|
const debouncedHoveredElement = ref();
|
|
1417
|
+
const forceClearHoveredElement = (el) => {
|
|
1418
|
+
if (el !== debouncedHoveredElement.value && el !== hoveredElement.value) return;
|
|
1419
|
+
hoveredElement.value = void 0;
|
|
1420
|
+
debouncedHoveredElement.value = void 0;
|
|
1421
|
+
if (timerId) clearTimeout(timerId);
|
|
1422
|
+
};
|
|
1416
1423
|
const contentMap = ref(/* @__PURE__ */ new Map());
|
|
1417
1424
|
const getContent = (key) => contentMap.value.get(key);
|
|
1418
1425
|
const setContent = (key, value) => contentMap.value.set(key, value);
|
|
@@ -1420,7 +1427,6 @@ const deleteContent = (key) => contentMap.value.delete(key);
|
|
|
1420
1427
|
const generateKey = () => crypto.randomUUID();
|
|
1421
1428
|
const tooltipKey = ref();
|
|
1422
1429
|
const tooltipContent = ref();
|
|
1423
|
-
let timerId;
|
|
1424
1430
|
watch([
|
|
1425
1431
|
tooltipKey,
|
|
1426
1432
|
hoveredElement,
|
|
@@ -1508,6 +1514,30 @@ const useVueltip = ({ tooltipElement, arrowElement, offset: _offset, padding, ar
|
|
|
1508
1514
|
};
|
|
1509
1515
|
};
|
|
1510
1516
|
|
|
1517
|
+
//#endregion
|
|
1518
|
+
//#region src/basicTooltip.component.ts
|
|
1519
|
+
const BasicTooltip = defineComponent(() => {
|
|
1520
|
+
const { tooltipStyles, arrowStyles, show, content } = useVueltip({
|
|
1521
|
+
tooltipElement: useTemplateRef("tooltipElement"),
|
|
1522
|
+
arrowElement: useTemplateRef("arrowElement"),
|
|
1523
|
+
offset: 8,
|
|
1524
|
+
padding: 8
|
|
1525
|
+
});
|
|
1526
|
+
return () => {
|
|
1527
|
+
if (!show.value) return null;
|
|
1528
|
+
return h("div", {
|
|
1529
|
+
ref: "tooltipElement",
|
|
1530
|
+
class: "vueltip-theme",
|
|
1531
|
+
style: tooltipStyles.value,
|
|
1532
|
+
role: "tooltip"
|
|
1533
|
+
}, [h("div", {
|
|
1534
|
+
ref: "arrowElement",
|
|
1535
|
+
class: "vueltip-arrow",
|
|
1536
|
+
style: arrowStyles.value
|
|
1537
|
+
}), h("div", { class: "vueltip-content" }, [content.value?.text])]);
|
|
1538
|
+
};
|
|
1539
|
+
});
|
|
1540
|
+
|
|
1511
1541
|
//#endregion
|
|
1512
1542
|
//#region src/utils.ts
|
|
1513
1543
|
function isTruncated(el) {
|
|
@@ -1611,6 +1641,7 @@ const vueltipDirective = {
|
|
|
1611
1641
|
},
|
|
1612
1642
|
beforeUnmount: (el) => {
|
|
1613
1643
|
ensureKey(el, (key) => deleteContent(key));
|
|
1644
|
+
forceClearHoveredElement(el);
|
|
1614
1645
|
el.removeEventListener("mouseenter", onMouseover);
|
|
1615
1646
|
el.removeEventListener("focus", onMouseover);
|
|
1616
1647
|
el.removeEventListener("mouseleave", onMouseout);
|
|
@@ -1633,4 +1664,4 @@ const vueltipPlugin = { install: (app, options) => {
|
|
|
1633
1664
|
} };
|
|
1634
1665
|
|
|
1635
1666
|
//#endregion
|
|
1636
|
-
export { setOptions, useVueltip, vueltipDirective, vueltipPlugin };
|
|
1667
|
+
export { BasicTooltip, setOptions, useVueltip, vueltipDirective, vueltipPlugin };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vingy/vueltip",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Headless tooltip which only shows when necessary.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"composition-api",
|
|
@@ -18,14 +18,17 @@
|
|
|
18
18
|
"dist"
|
|
19
19
|
],
|
|
20
20
|
"type": "module",
|
|
21
|
-
"sideEffects":
|
|
21
|
+
"sideEffects": [
|
|
22
|
+
"./dist/basicTooltip.css"
|
|
23
|
+
],
|
|
22
24
|
"main": "./dist/index.mjs",
|
|
23
25
|
"types": "./dist/index.d.mts",
|
|
24
26
|
"exports": {
|
|
25
27
|
".": {
|
|
26
28
|
"types": "./dist/index.d.mts",
|
|
27
29
|
"import": "./dist/index.mjs"
|
|
28
|
-
}
|
|
30
|
+
},
|
|
31
|
+
"./basicTooltip.css": "./dist/basicTooltip.css"
|
|
29
32
|
},
|
|
30
33
|
"publishConfig": {
|
|
31
34
|
"access": "public"
|