@vingy/vueltip 2.0.1 → 2.1.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 +59 -0
- package/dist/basicTooltip.css +42 -0
- package/dist/index.d.mts +10 -7
- package/dist/index.mjs +39 -8
- 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,
|
|
3
|
+
import { computed, createVNode, defineComponent, h, ref, render, 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;
|
|
@@ -1514,6 +1514,30 @@ const useVueltip = ({ tooltipElement, arrowElement, offset: _offset, padding, ar
|
|
|
1514
1514
|
};
|
|
1515
1515
|
};
|
|
1516
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
|
+
|
|
1517
1541
|
//#endregion
|
|
1518
1542
|
//#region src/utils.ts
|
|
1519
1543
|
function isTruncated(el) {
|
|
@@ -1627,17 +1651,24 @@ const vueltipDirective = {
|
|
|
1627
1651
|
|
|
1628
1652
|
//#endregion
|
|
1629
1653
|
//#region src/plugin.ts
|
|
1654
|
+
const CONTAINER_ID = "__vueltip_root__";
|
|
1655
|
+
const getContainer = () => {
|
|
1656
|
+
const existing = document.getElementById(CONTAINER_ID);
|
|
1657
|
+
if (existing) return existing;
|
|
1658
|
+
const container = document.createElement("div");
|
|
1659
|
+
container.id = CONTAINER_ID;
|
|
1660
|
+
document.body.appendChild(container);
|
|
1661
|
+
return container;
|
|
1662
|
+
};
|
|
1630
1663
|
const vueltipPlugin = { install: (app, options) => {
|
|
1631
1664
|
const { component, ...rest } = options;
|
|
1632
1665
|
setOptions(rest);
|
|
1633
1666
|
if (!component) return;
|
|
1634
|
-
const container =
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
tooltipApp._context = app._context;
|
|
1639
|
-
tooltipApp.mount(container);
|
|
1667
|
+
const container = getContainer();
|
|
1668
|
+
const vnode = createVNode(component);
|
|
1669
|
+
vnode.appContext = app._context;
|
|
1670
|
+
render(vnode, container);
|
|
1640
1671
|
} };
|
|
1641
1672
|
|
|
1642
1673
|
//#endregion
|
|
1643
|
-
export { setOptions, useVueltip, vueltipDirective, vueltipPlugin };
|
|
1674
|
+
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.1",
|
|
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"
|