@versini/ui-tooltip 2.1.1 → 2.1.2
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 +35 -2
- package/dist/components/Tooltip/Tooltip.js +77 -78
- package/dist/index.js +3 -3
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -1,3 +1,36 @@
|
|
|
1
|
-
# @versini/ui-
|
|
1
|
+
# @versini/ui-tooltip
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@versini/ui-tooltip)
|
|
4
|
+
|
|
5
|
+
> An accessible React tooltip component built with TypeScript and TailwindCSS.
|
|
6
|
+
|
|
7
|
+
The Tooltip component provides contextual help and information with proper accessibility support and customizable positioning.
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
## Table of Contents
|
|
11
|
+
|
|
12
|
+
- [Features](#features)
|
|
13
|
+
- [Installation](#installation)
|
|
14
|
+
- [Usage](#usage)
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @versini/ui-tooltip
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
> **Note**: This component requires TailwindCSS and the `@versini/ui-styles` plugin for proper styling. See the [root README](../../README.md#tailwindcss-setup) for complete setup instructions.
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
```tsx
|
|
27
|
+
import { Tooltip } from "@versini/ui-tooltip";
|
|
28
|
+
|
|
29
|
+
function App() {
|
|
30
|
+
return (
|
|
31
|
+
<Tooltip content="This is a helpful tooltip">
|
|
32
|
+
<button>Hover me</button>
|
|
33
|
+
</Tooltip>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
```
|
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { computePosition as
|
|
3
|
-
import { useRef as
|
|
4
|
-
import
|
|
5
|
-
const
|
|
6
|
-
function
|
|
7
|
-
const a =
|
|
1
|
+
import { jsxs as E, jsx as _ } from "react/jsx-runtime";
|
|
2
|
+
import { computePosition as j, offset as B, flip as $, shift as z, arrow as F } from "@floating-ui/react";
|
|
3
|
+
import { useRef as p, useEffect as T, useState as h, useCallback as x } from "react";
|
|
4
|
+
import i from "clsx";
|
|
5
|
+
const H = "av-tooltip", U = "av-tooltip-arrow", L = ["mousedown", "touchstart"];
|
|
6
|
+
function V(t, n, s) {
|
|
7
|
+
const a = p(null);
|
|
8
8
|
return T(() => {
|
|
9
9
|
const r = (e) => {
|
|
10
10
|
const o = e ? e.target : void 0;
|
|
11
11
|
if (Array.isArray(s)) {
|
|
12
|
-
const
|
|
12
|
+
const c = !document.body.contains(o) && o.tagName !== "HTML";
|
|
13
13
|
s.every(
|
|
14
|
-
(
|
|
15
|
-
) && !
|
|
14
|
+
(l) => !!l && !e.composedPath().includes(l)
|
|
15
|
+
) && !c && t();
|
|
16
16
|
} else a.current && !a.current.contains(o) && t();
|
|
17
17
|
};
|
|
18
|
-
return
|
|
18
|
+
return L.forEach(
|
|
19
19
|
(e) => document.addEventListener(e, r)
|
|
20
20
|
), () => {
|
|
21
|
-
|
|
21
|
+
L.forEach(
|
|
22
22
|
(e) => document.removeEventListener(e, r)
|
|
23
23
|
);
|
|
24
24
|
};
|
|
25
25
|
}, [t, s, n]), a;
|
|
26
26
|
}
|
|
27
|
-
function
|
|
28
|
-
const [s, a] =
|
|
29
|
-
a((
|
|
30
|
-
}, [n]),
|
|
27
|
+
function W(t, n) {
|
|
28
|
+
const [s, a] = h(!1), r = p(null), e = p(null), o = x(() => {
|
|
29
|
+
a((l) => (!l && (!r.current || r.current === -1) && (r.current = window.setInterval(e.current, n)), !0));
|
|
30
|
+
}, [n]), c = x(() => {
|
|
31
31
|
a(!1), window.clearInterval(r.current || -1), r.current = -1;
|
|
32
32
|
}, []);
|
|
33
|
-
return T(() => (e.current = t, s && o(),
|
|
33
|
+
return T(() => (e.current = t, s && o(), c), [t, s, o, c]), { start: o, stop: c, active: s };
|
|
34
34
|
}
|
|
35
|
-
const d = (t, n = "px") => typeof t > "u" ? "" : `${Math.round(t)}${n}`,
|
|
35
|
+
const d = (t, n = "px") => typeof t > "u" ? "" : `${Math.round(t)}${n}`, Y = () => i("absolute top-0 left-0 w-max py-1 px-2 rounded-sm text-sm z-50"), S = ({
|
|
36
36
|
mode: t
|
|
37
|
-
}) =>
|
|
37
|
+
}) => i({
|
|
38
38
|
"bg-surface-darker": t === "dark" || t === "system",
|
|
39
39
|
"bg-surface-light": t === "light" || t === "alt-system",
|
|
40
40
|
"dark:bg-surface-light": t === "system",
|
|
41
41
|
"dark:bg-surface-darker": t === "alt-system"
|
|
42
|
-
}),
|
|
42
|
+
}), q = ({
|
|
43
43
|
mode: t
|
|
44
|
-
}) =>
|
|
44
|
+
}) => i({
|
|
45
45
|
"text-copy-light": t === "dark" || t === "system",
|
|
46
46
|
"text-copy-dark": t === "light" || t === "alt-system",
|
|
47
47
|
"dark:text-copy-dark": t === "system",
|
|
48
48
|
"dark:text-copy-light": t === "alt-system"
|
|
49
|
-
}),
|
|
49
|
+
}), G = () => i("absolute", "size-2", "transform rotate-45"), J = ({
|
|
50
50
|
mode: t,
|
|
51
51
|
className: n,
|
|
52
52
|
tooltipClassName: s,
|
|
53
53
|
arrowClassName: a
|
|
54
54
|
}) => {
|
|
55
|
-
const r =
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
55
|
+
const r = i("relative inline-block", n), e = i(
|
|
56
|
+
H,
|
|
57
|
+
Y(),
|
|
58
|
+
S({ mode: t }),
|
|
59
|
+
q({ mode: t }),
|
|
60
60
|
s
|
|
61
|
-
), o =
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
), o = i(
|
|
62
|
+
U,
|
|
63
|
+
G(),
|
|
64
|
+
S({ mode: t }),
|
|
65
65
|
a
|
|
66
66
|
);
|
|
67
67
|
return { tooltip: e, arrow: o, wrapper: r };
|
|
68
|
-
},
|
|
68
|
+
}, K = ({ delay: t = 300 }) => ({
|
|
69
69
|
animation: `av-tooltip-fade-in ${t}ms ease-in-out`
|
|
70
|
-
}),
|
|
70
|
+
}), Q = 5e3, st = ({
|
|
71
71
|
trigger: t,
|
|
72
72
|
label: n,
|
|
73
73
|
placement: s = "top",
|
|
@@ -75,86 +75,85 @@ const d = (t, n = "px") => typeof t > "u" ? "" : `${Math.round(t)}${n}`, K = ()
|
|
|
75
75
|
delay: r = 300,
|
|
76
76
|
className: e,
|
|
77
77
|
tooltipClassName: o,
|
|
78
|
-
arrowClassName:
|
|
78
|
+
arrowClassName: c
|
|
79
79
|
}) => {
|
|
80
|
-
const
|
|
80
|
+
const l = V(() => {
|
|
81
81
|
k.stop(), g(!1);
|
|
82
|
-
}),
|
|
82
|
+
}), u = p(null), f = p(null), [y, m] = h(!1), [b, g] = h(!1), k = W(() => {
|
|
83
83
|
g(!1);
|
|
84
|
-
},
|
|
84
|
+
}, Q), w = J({
|
|
85
85
|
mode: a,
|
|
86
86
|
className: e,
|
|
87
87
|
tooltipClassName: o,
|
|
88
|
-
arrowClassName:
|
|
89
|
-
}), v =
|
|
90
|
-
|
|
91
|
-
if (c.current && i.current && u.current) {
|
|
88
|
+
arrowClassName: c
|
|
89
|
+
}), v = K({ delay: r }), A = x(async () => {
|
|
90
|
+
if (l.current && u.current && f.current) {
|
|
92
91
|
const {
|
|
93
|
-
x:
|
|
94
|
-
y:
|
|
95
|
-
middlewareData:
|
|
96
|
-
placement:
|
|
97
|
-
} = await
|
|
92
|
+
x: N,
|
|
93
|
+
y: R,
|
|
94
|
+
middlewareData: C,
|
|
95
|
+
placement: D
|
|
96
|
+
} = await j(l.current, u.current, {
|
|
98
97
|
placement: s,
|
|
99
98
|
middleware: [
|
|
100
|
-
|
|
101
|
-
|
|
99
|
+
B(10),
|
|
100
|
+
$({
|
|
102
101
|
crossAxis: s.includes("-"),
|
|
103
102
|
fallbackAxisSideDirection: "start"
|
|
104
103
|
}),
|
|
105
|
-
|
|
106
|
-
|
|
104
|
+
z({ padding: 5 }),
|
|
105
|
+
F({ element: f.current })
|
|
107
106
|
]
|
|
108
107
|
});
|
|
109
|
-
|
|
110
|
-
left: d(
|
|
111
|
-
top: d(
|
|
108
|
+
u?.current?.style && Object.assign(u.current.style, {
|
|
109
|
+
left: d(N),
|
|
110
|
+
top: d(R),
|
|
112
111
|
...v
|
|
113
112
|
});
|
|
114
|
-
const
|
|
113
|
+
const P = {
|
|
115
114
|
top: "bottom",
|
|
116
115
|
right: "left",
|
|
117
116
|
bottom: "top",
|
|
118
117
|
left: "right"
|
|
119
|
-
}[
|
|
120
|
-
|
|
121
|
-
left: d(
|
|
122
|
-
top: d(
|
|
118
|
+
}[D.split("-")[0]];
|
|
119
|
+
f?.current?.style && Object.assign(f.current.style, {
|
|
120
|
+
left: d(C.arrow?.x),
|
|
121
|
+
top: d(C.arrow?.y),
|
|
123
122
|
right: "",
|
|
124
123
|
bottom: "",
|
|
125
|
-
[
|
|
124
|
+
[P]: "-4px"
|
|
126
125
|
});
|
|
127
126
|
}
|
|
128
|
-
}, [s, v,
|
|
127
|
+
}, [s, v, l]);
|
|
129
128
|
T(() => {
|
|
130
|
-
(async () => y && await
|
|
131
|
-
}, [
|
|
132
|
-
const
|
|
129
|
+
(async () => y && await A())();
|
|
130
|
+
}, [A, y]);
|
|
131
|
+
const M = () => {
|
|
133
132
|
m(!1), g(!0), k.start();
|
|
134
|
-
},
|
|
133
|
+
}, O = () => {
|
|
135
134
|
b || m(!0);
|
|
136
|
-
},
|
|
135
|
+
}, I = () => {
|
|
137
136
|
b || m(!1);
|
|
138
137
|
};
|
|
139
|
-
return /* @__PURE__ */
|
|
138
|
+
return /* @__PURE__ */ E(
|
|
140
139
|
"div",
|
|
141
140
|
{
|
|
142
|
-
className:
|
|
143
|
-
ref:
|
|
144
|
-
onMouseEnter:
|
|
145
|
-
onMouseLeave:
|
|
146
|
-
onClick:
|
|
141
|
+
className: w.wrapper,
|
|
142
|
+
ref: l,
|
|
143
|
+
onMouseEnter: O,
|
|
144
|
+
onMouseLeave: I,
|
|
145
|
+
onClick: M,
|
|
147
146
|
children: [
|
|
148
147
|
t,
|
|
149
|
-
y && /* @__PURE__ */
|
|
148
|
+
y && /* @__PURE__ */ E(
|
|
150
149
|
"div",
|
|
151
150
|
{
|
|
152
151
|
role: "tooltip",
|
|
153
|
-
ref:
|
|
154
|
-
className:
|
|
152
|
+
ref: u,
|
|
153
|
+
className: w.tooltip,
|
|
155
154
|
children: [
|
|
156
155
|
n,
|
|
157
|
-
/* @__PURE__ */
|
|
156
|
+
/* @__PURE__ */ _("div", { ref: f, className: w.arrow })
|
|
158
157
|
]
|
|
159
158
|
}
|
|
160
159
|
)
|
|
@@ -163,7 +162,7 @@ const d = (t, n = "px") => typeof t > "u" ? "" : `${Math.round(t)}${n}`, K = ()
|
|
|
163
162
|
);
|
|
164
163
|
};
|
|
165
164
|
export {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
165
|
+
U as TOOLTIP_ARROW_CLASSNAME,
|
|
166
|
+
H as TOOLTIP_CLASSNAME,
|
|
167
|
+
st as Tooltip
|
|
169
168
|
};
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { TOOLTIP_ARROW_CLASSNAME as T, TOOLTIP_CLASSNAME as I, Tooltip as e } from "./components/Tooltip/Tooltip.js";
|
|
2
2
|
/*!
|
|
3
|
-
@versini/ui-tooltip v2.1.
|
|
3
|
+
@versini/ui-tooltip v2.1.2
|
|
4
4
|
© 2025 gizmette.com
|
|
5
5
|
*/
|
|
6
6
|
try {
|
|
7
7
|
window.__VERSINI_UI_TOOLTIP__ || (window.__VERSINI_UI_TOOLTIP__ = {
|
|
8
|
-
version: "2.1.
|
|
9
|
-
buildTime: "07/
|
|
8
|
+
version: "2.1.2",
|
|
9
|
+
buildTime: "08/07/2025 04:12 PM EDT",
|
|
10
10
|
homepage: "https://github.com/aversini/ui-components",
|
|
11
11
|
license: "MIT"
|
|
12
12
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@versini/ui-tooltip",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Arno Versini",
|
|
6
6
|
"publishConfig": {
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"dev:types": "tsup --watch src",
|
|
28
28
|
"dev": "npm-run-all clean --parallel dev:js dev:types",
|
|
29
29
|
"lint": "biome lint src",
|
|
30
|
+
"lint:fix": "biome check src --write --no-errors-on-unmatched",
|
|
30
31
|
"prettier": "biome check --write --no-errors-on-unmatched",
|
|
31
32
|
"start": "static-server dist --port 5173",
|
|
32
33
|
"test:coverage:ui": "vitest --coverage --ui",
|
|
@@ -39,11 +40,11 @@
|
|
|
39
40
|
"react-dom": "^18.3.1 || ^19.0.0"
|
|
40
41
|
},
|
|
41
42
|
"devDependencies": {
|
|
42
|
-
"@testing-library/jest-dom": "6.6.
|
|
43
|
-
"@versini/ui-types": "5.0.
|
|
43
|
+
"@testing-library/jest-dom": "6.6.4",
|
|
44
|
+
"@versini/ui-types": "5.0.6"
|
|
44
45
|
},
|
|
45
46
|
"dependencies": {
|
|
46
|
-
"@floating-ui/react": "0.27.
|
|
47
|
+
"@floating-ui/react": "0.27.15",
|
|
47
48
|
"@tailwindcss/typography": "0.5.16",
|
|
48
49
|
"@versini/ui-hooks": "4.7.5",
|
|
49
50
|
"clsx": "2.1.1",
|
|
@@ -52,5 +53,5 @@
|
|
|
52
53
|
"sideEffects": [
|
|
53
54
|
"**/*.css"
|
|
54
55
|
],
|
|
55
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "42daab1fb88c366495abbc1db78a9987de05e59b"
|
|
56
57
|
}
|