@versini/ui-tooltip 3.1.1 → 4.0.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 +36 -15
- package/dist/index.d.ts +7 -2
- package/dist/index.js +38 -8
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ The Tooltip component provides contextual help and information with proper acces
|
|
|
18
18
|
## Features
|
|
19
19
|
|
|
20
20
|
- **🧭 Smart Positioning**: Uses Floating UI for collision-aware placement & arrow positioning
|
|
21
|
-
- **⏱️
|
|
21
|
+
- **⏱️ Configurable Timing**: Show delay (`delay` prop) and fade-in duration (`animationDuration` prop)
|
|
22
22
|
- **♿ Accessible**: Proper `role="tooltip"`, hover & focus behavior, optional disabling period
|
|
23
23
|
- **🎨 Theming**: Supports light / dark / system / alt-system modes
|
|
24
24
|
- **🪶 Lightweight**: Minimal DOM & style footprint; only renders when visible
|
|
@@ -59,17 +59,37 @@ function App() {
|
|
|
59
59
|
</div>
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
-
### Custom
|
|
62
|
+
### Custom Animation Duration & Dark Mode
|
|
63
63
|
|
|
64
64
|
```tsx
|
|
65
65
|
<Tooltip
|
|
66
|
-
label="
|
|
67
|
-
|
|
66
|
+
label="Smooth fade-in"
|
|
67
|
+
animationDuration={1000}
|
|
68
68
|
mode="dark"
|
|
69
|
-
trigger={<button>
|
|
69
|
+
trigger={<button>Slow animation</button>}
|
|
70
70
|
/>
|
|
71
71
|
```
|
|
72
72
|
|
|
73
|
+
### Delayed Appearance
|
|
74
|
+
|
|
75
|
+
```tsx
|
|
76
|
+
<Tooltip
|
|
77
|
+
label="Appears after 500ms"
|
|
78
|
+
delay={500}
|
|
79
|
+
trigger={<button>Hover and wait</button>}
|
|
80
|
+
/>;
|
|
81
|
+
|
|
82
|
+
{
|
|
83
|
+
/* Combine delay and animation duration */
|
|
84
|
+
}
|
|
85
|
+
<Tooltip
|
|
86
|
+
label="Wait 300ms, then fade in over 800ms"
|
|
87
|
+
delay={300}
|
|
88
|
+
animationDuration={800}
|
|
89
|
+
trigger={<button>Delayed & animated</button>}
|
|
90
|
+
/>;
|
|
91
|
+
```
|
|
92
|
+
|
|
73
93
|
### Styling the Tooltip & Arrow
|
|
74
94
|
|
|
75
95
|
```tsx
|
|
@@ -85,15 +105,16 @@ function App() {
|
|
|
85
105
|
|
|
86
106
|
### Tooltip Props
|
|
87
107
|
|
|
88
|
-
| Prop
|
|
89
|
-
|
|
|
90
|
-
| `label`
|
|
91
|
-
| `trigger`
|
|
92
|
-
| `placement`
|
|
93
|
-
| `mode`
|
|
94
|
-
| `delay`
|
|
95
|
-
| `
|
|
96
|
-
| `
|
|
97
|
-
| `
|
|
108
|
+
| Prop | Type | Default | Description |
|
|
109
|
+
| ------------------- | --------------------------------------- | ------- | -------------------------------------------------- | ------------- | ---------- | ------------------------------ |
|
|
110
|
+
| `label` | `string` | - | Text content of the tooltip. |
|
|
111
|
+
| `trigger` | `React.ReactNode` | - | Element that the tooltip is anchored to. |
|
|
112
|
+
| `placement` | `Placement` (from `@floating-ui/react`) | `"top"` | Preferred initial placement (auto flips / shifts). |
|
|
113
|
+
| `mode` | `"dark" | "light" | "system" | "alt-system"` | `"system"` | Theme mode controlling colors. |
|
|
114
|
+
| `delay` | `number` | `0` | Delay before showing tooltip (milliseconds). |
|
|
115
|
+
| `animationDuration` | `number` | `300` | Duration of fade-in animation (milliseconds). |
|
|
116
|
+
| `className` | `string` | - | Extra classes for outer wrapper. |
|
|
117
|
+
| `tooltipClassName` | `string` | - | Extra classes for tooltip bubble. |
|
|
118
|
+
| `arrowClassName` | `string` | - | Extra classes for tooltip arrow element. |
|
|
98
119
|
|
|
99
120
|
> Tooltip appears on hover/focus, hides on leave/click, and temporarily disables after click to prevent flicker.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { JSX } from 'react/jsx-runtime';
|
|
2
2
|
import { Placement } from '@floating-ui/react';
|
|
3
3
|
|
|
4
|
-
export declare const Tooltip: ({ trigger, label, placement, mode, delay, className, tooltipClassName, arrowClassName, }: TooltipTypes.Props) => JSX.Element;
|
|
4
|
+
export declare const Tooltip: ({ trigger, label, placement, mode, animationDuration, delay, className, tooltipClassName, arrowClassName, }: TooltipTypes.Props) => JSX.Element;
|
|
5
5
|
|
|
6
6
|
export declare const TOOLTIP_ARROW_CLASSNAME = "av-tooltip-arrow";
|
|
7
7
|
|
|
@@ -43,9 +43,14 @@ declare namespace TooltipTypes {
|
|
|
43
43
|
*/
|
|
44
44
|
mode?: "dark" | "light" | "system" | "alt-system";
|
|
45
45
|
/**
|
|
46
|
-
* The
|
|
46
|
+
* The duration in milliseconds of the tooltip fade-in animation.
|
|
47
47
|
* @default 300
|
|
48
48
|
*/
|
|
49
|
+
animationDuration?: number;
|
|
50
|
+
/**
|
|
51
|
+
* The delay in milliseconds before showing the tooltip after hovering.
|
|
52
|
+
* @default 0
|
|
53
|
+
*/
|
|
49
54
|
delay?: number;
|
|
50
55
|
};
|
|
51
56
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
@versini/ui-tooltip
|
|
2
|
+
@versini/ui-tooltip v4.0.1
|
|
3
3
|
© 2025 gizmette.com
|
|
4
4
|
*/
|
|
5
5
|
try {
|
|
6
6
|
if (!window.__VERSINI_UI_TOOLTIP__) {
|
|
7
7
|
window.__VERSINI_UI_TOOLTIP__ = {
|
|
8
|
-
version: "
|
|
9
|
-
buildTime: "11/
|
|
8
|
+
version: "4.0.1",
|
|
9
|
+
buildTime: "11/30/2025 07:18 PM EST",
|
|
10
10
|
homepage: "https://github.com/aversini/ui-components",
|
|
11
11
|
license: "MIT",
|
|
12
12
|
};
|
|
@@ -79,9 +79,9 @@ const getTooltipClasses = ({ mode, className, tooltipClassName, arrowClassName }
|
|
|
79
79
|
wrapper
|
|
80
80
|
};
|
|
81
81
|
};
|
|
82
|
-
const getAnimationStyles = ({
|
|
82
|
+
const getAnimationStyles = ({ animationDuration = 300 })=>{
|
|
83
83
|
return {
|
|
84
|
-
animation: `av-tooltip-fade-in ${
|
|
84
|
+
animation: `av-tooltip-fade-in ${animationDuration}ms ease-in-out`
|
|
85
85
|
};
|
|
86
86
|
};
|
|
87
87
|
|
|
@@ -92,14 +92,16 @@ const getAnimationStyles = ({ delay = 300 })=>{
|
|
|
92
92
|
|
|
93
93
|
|
|
94
94
|
const DEFAULT_DEACTIVATION_DELAY = 5000;
|
|
95
|
-
const Tooltip = ({ trigger, label, placement = "top", mode = "system",
|
|
95
|
+
const Tooltip = ({ trigger, label, placement = "top", mode = "system", animationDuration = 300, delay = 0, className, tooltipClassName, arrowClassName })=>{
|
|
96
96
|
const referenceRef = useClickOutside(()=>{
|
|
97
97
|
/* v8 ignore next 1 */ delayedRestartTooltip.stop(), setDisabled(false);
|
|
98
98
|
});
|
|
99
99
|
const floatingRef = useRef(null);
|
|
100
100
|
const floatingArrowRef = useRef(null);
|
|
101
|
+
const showTimeoutRef = useRef(null);
|
|
101
102
|
const [showTooltip, setShowTooltip] = useState(false);
|
|
102
103
|
const [disabled, setDisabled] = useState(false);
|
|
104
|
+
const [isPositioned, setIsPositioned] = useState(false);
|
|
103
105
|
const delayedRestartTooltip = useInterval(()=>{
|
|
104
106
|
setDisabled(false);
|
|
105
107
|
}, DEFAULT_DEACTIVATION_DELAY);
|
|
@@ -110,7 +112,7 @@ const Tooltip = ({ trigger, label, placement = "top", mode = "system", delay = 3
|
|
|
110
112
|
arrowClassName
|
|
111
113
|
});
|
|
112
114
|
const animationStyles = getAnimationStyles({
|
|
113
|
-
|
|
115
|
+
animationDuration
|
|
114
116
|
});
|
|
115
117
|
const updatePosition = useCallback(async ()=>{
|
|
116
118
|
if (referenceRef.current && floatingRef.current && floatingArrowRef.current) {
|
|
@@ -152,6 +154,7 @@ const Tooltip = ({ trigger, label, placement = "top", mode = "system", delay = 3
|
|
|
152
154
|
[staticSide]: "-4px"
|
|
153
155
|
});
|
|
154
156
|
}
|
|
157
|
+
setIsPositioned(true);
|
|
155
158
|
}
|
|
156
159
|
}, [
|
|
157
160
|
placement,
|
|
@@ -162,13 +165,26 @@ const Tooltip = ({ trigger, label, placement = "top", mode = "system", delay = 3
|
|
|
162
165
|
(async ()=>{
|
|
163
166
|
if (showTooltip) {
|
|
164
167
|
await updatePosition();
|
|
168
|
+
} else {
|
|
169
|
+
setIsPositioned(false);
|
|
165
170
|
}
|
|
166
171
|
})();
|
|
167
172
|
}, [
|
|
168
173
|
updatePosition,
|
|
169
174
|
showTooltip
|
|
170
175
|
]);
|
|
176
|
+
useEffect(()=>{
|
|
177
|
+
return ()=>{
|
|
178
|
+
if (showTimeoutRef.current) {
|
|
179
|
+
clearTimeout(showTimeoutRef.current);
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
}, []);
|
|
171
183
|
const handleMouseClick = ()=>{
|
|
184
|
+
if (showTimeoutRef.current) {
|
|
185
|
+
clearTimeout(showTimeoutRef.current);
|
|
186
|
+
showTimeoutRef.current = null;
|
|
187
|
+
}
|
|
172
188
|
setShowTooltip(false);
|
|
173
189
|
setDisabled(true);
|
|
174
190
|
// disabling tooltip for 5 seconds
|
|
@@ -176,10 +192,21 @@ const Tooltip = ({ trigger, label, placement = "top", mode = "system", delay = 3
|
|
|
176
192
|
};
|
|
177
193
|
const handleMouseEnter = ()=>{
|
|
178
194
|
if (!disabled) {
|
|
179
|
-
|
|
195
|
+
if (delay > 0) {
|
|
196
|
+
showTimeoutRef.current = setTimeout(()=>{
|
|
197
|
+
setShowTooltip(true);
|
|
198
|
+
showTimeoutRef.current = null;
|
|
199
|
+
}, delay);
|
|
200
|
+
} else {
|
|
201
|
+
setShowTooltip(true);
|
|
202
|
+
}
|
|
180
203
|
}
|
|
181
204
|
};
|
|
182
205
|
const handleMouseLeave = ()=>{
|
|
206
|
+
if (showTimeoutRef.current) {
|
|
207
|
+
clearTimeout(showTimeoutRef.current);
|
|
208
|
+
showTimeoutRef.current = null;
|
|
209
|
+
}
|
|
183
210
|
if (!disabled) {
|
|
184
211
|
setShowTooltip(false);
|
|
185
212
|
}
|
|
@@ -196,6 +223,9 @@ const Tooltip = ({ trigger, label, placement = "top", mode = "system", delay = 3
|
|
|
196
223
|
role: "tooltip",
|
|
197
224
|
ref: floatingRef,
|
|
198
225
|
className: tooltipClasses.tooltip,
|
|
226
|
+
style: {
|
|
227
|
+
opacity: isPositioned ? undefined : 0
|
|
228
|
+
},
|
|
199
229
|
children: [
|
|
200
230
|
label,
|
|
201
231
|
/*#__PURE__*/ jsx("div", {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@versini/ui-tooltip",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Arno Versini",
|
|
6
6
|
"publishConfig": {
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@testing-library/jest-dom": "6.9.1",
|
|
41
|
-
"@versini/ui-types": "
|
|
41
|
+
"@versini/ui-types": "7.0.0"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@floating-ui/react": "0.27.16",
|
|
@@ -50,5 +50,5 @@
|
|
|
50
50
|
"sideEffects": [
|
|
51
51
|
"**/*.css"
|
|
52
52
|
],
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "86a93dd1fc801dedf9d72169bb5a352a855fbf20"
|
|
54
54
|
}
|