@versini/ui-tooltip 6.3.2 → 6.3.4
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/dist/index.js +45 -22
- package/package.json +52 -53
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
@versini/ui-tooltip v6.3.
|
|
2
|
+
@versini/ui-tooltip v6.3.4
|
|
3
3
|
© 2026 gizmette.com
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -163,7 +163,7 @@ const getTooltipShadowClasses = ({ mode })=>{
|
|
|
163
163
|
const getTooltipArrowBaseClasses = ()=>{
|
|
164
164
|
return clsx("absolute", "size-2", "transform rotate-45");
|
|
165
165
|
};
|
|
166
|
-
const getTooltipClasses = ({ mode, className, tooltipClassName, arrowClassName })=>{
|
|
166
|
+
const getTooltipClasses = ({ mode, className, tooltipClassName, arrowClassName, animate })=>{
|
|
167
167
|
const wrapper = clsx("inline-block", className);
|
|
168
168
|
const tooltip = clsx(TOOLTIP_CLASSNAME, getTooltipBaseClasses(), getTooltipBackgroundColorClasses({
|
|
169
169
|
mode
|
|
@@ -171,7 +171,9 @@ const getTooltipClasses = ({ mode, className, tooltipClassName, arrowClassName }
|
|
|
171
171
|
mode
|
|
172
172
|
}), getTooltipShadowClasses({
|
|
173
173
|
mode
|
|
174
|
-
}),
|
|
174
|
+
}), {
|
|
175
|
+
[TOOLTIP_ANIMATE_CLASSNAME]: animate
|
|
176
|
+
}, tooltipClassName);
|
|
175
177
|
const arrow = clsx(TOOLTIP_ARROW_CLASSNAME, getTooltipArrowBaseClasses(), getTooltipBackgroundColorClasses({
|
|
176
178
|
mode
|
|
177
179
|
}), arrowClassName);
|
|
@@ -181,15 +183,38 @@ const getTooltipClasses = ({ mode, className, tooltipClassName, arrowClassName }
|
|
|
181
183
|
wrapper
|
|
182
184
|
};
|
|
183
185
|
};
|
|
184
|
-
|
|
186
|
+
/**
|
|
187
|
+
* The fade-in itself is the `.av-tooltip-animate` rule ui-styles injects: its
|
|
188
|
+
* `animation` names the `av-tooltip-fade-in` keyframes and reads the duration
|
|
189
|
+
* from the custom property below, with the default duration as the fallback.
|
|
190
|
+
* The component must never name the keyframes itself, as the inline `animation`
|
|
191
|
+
* it used to set did. A consumer minifying with cssnano's advanced preset drops
|
|
192
|
+
* a `@keyframes` no stylesheet references and renames the ones it keeps, so an
|
|
193
|
+
* inline reference pointed either at nothing or at the old name, and the
|
|
194
|
+
* tooltip appeared instantly (versini-org/ui-components#2016).
|
|
195
|
+
*
|
|
196
|
+
* Both names are private: they are the contract with ui-styles, not a styling
|
|
197
|
+
* hook for consumers, and the class only fades correctly once the tooltip has
|
|
198
|
+
* been positioned.
|
|
199
|
+
*
|
|
200
|
+
*/ const TOOLTIP_ANIMATE_CLASSNAME = "av-tooltip-animate";
|
|
201
|
+
const TOOLTIP_ANIMATION_DURATION_PROPERTY = "--av-tooltip-animation-duration";
|
|
202
|
+
/**
|
|
203
|
+
* The property is only written when the prop is set, so the stylesheet owns the
|
|
204
|
+
* default and a consumer can still theme the duration from the cascade
|
|
205
|
+
* (`--av-tooltip-animation-duration` on any ancestor); an explicit prop wins.
|
|
206
|
+
*/ const getAnimationStyles = ({ animationDuration })=>{
|
|
207
|
+
if (animationDuration === undefined) {
|
|
208
|
+
return {};
|
|
209
|
+
}
|
|
185
210
|
return {
|
|
186
|
-
|
|
211
|
+
[TOOLTIP_ANIMATION_DURATION_PROPERTY]: `${animationDuration}ms`
|
|
187
212
|
};
|
|
188
213
|
};
|
|
189
214
|
|
|
190
215
|
|
|
191
216
|
|
|
192
|
-
function useTooltipPosition({ triggerRef, tooltipRef, arrowRef, placement, sideOffset,
|
|
217
|
+
function useTooltipPosition({ triggerRef, tooltipRef, arrowRef, placement, sideOffset, isOpen }) {
|
|
193
218
|
const [isPositioned, setIsPositioned] = useState(false);
|
|
194
219
|
const updatePosition = useCallback(()=>{
|
|
195
220
|
/* v8 ignore start - positioning requires real DOM layout */ if (!triggerRef.current || !tooltipRef.current || !arrowRef.current) {
|
|
@@ -206,15 +231,11 @@ function useTooltipPosition({ triggerRef, tooltipRef, arrowRef, placement, sideO
|
|
|
206
231
|
const arrowWidth = arrowRef.current.offsetWidth;
|
|
207
232
|
const arrowHeight = arrowRef.current.offsetHeight;
|
|
208
233
|
const arrowPosition = calculateArrowPosition(triggerRect, top, left, tooltipRect.width, tooltipRect.height, resolvedSide, arrowWidth, arrowHeight);
|
|
209
|
-
const animationStyles = getAnimationStyles({
|
|
210
|
-
animationDuration
|
|
211
|
-
});
|
|
212
234
|
Object.assign(tooltipRef.current.style, {
|
|
213
235
|
position: "fixed",
|
|
214
236
|
top: `${Math.round(top)}px`,
|
|
215
237
|
left: `${Math.round(left)}px`,
|
|
216
|
-
margin: "0"
|
|
217
|
-
...animationStyles
|
|
238
|
+
margin: "0"
|
|
218
239
|
});
|
|
219
240
|
Object.assign(arrowRef.current.style, {
|
|
220
241
|
left: arrowPosition.arrowLeft,
|
|
@@ -229,8 +250,7 @@ function useTooltipPosition({ triggerRef, tooltipRef, arrowRef, placement, sideO
|
|
|
229
250
|
tooltipRef,
|
|
230
251
|
arrowRef,
|
|
231
252
|
placement,
|
|
232
|
-
sideOffset
|
|
233
|
-
animationDuration
|
|
253
|
+
sideOffset
|
|
234
254
|
]);
|
|
235
255
|
useEffect(()=>{
|
|
236
256
|
if (isOpen) {
|
|
@@ -256,7 +276,7 @@ function useTooltipPosition({ triggerRef, tooltipRef, arrowRef, placement, sideO
|
|
|
256
276
|
|
|
257
277
|
|
|
258
278
|
const DEFAULT_DEACTIVATION_DELAY = 5000;
|
|
259
|
-
const Tooltip = ({ trigger, label, placement = "top", mode = "system", animationDuration
|
|
279
|
+
const Tooltip = ({ trigger, label, placement = "top", mode = "system", animationDuration, delay = 0, className, tooltipClassName, arrowClassName })=>{
|
|
260
280
|
const referenceRef = useClickOutside(()=>{
|
|
261
281
|
/* v8 ignore start */ delayedRestartTooltip.stop(), setDisabled(false);
|
|
262
282
|
/* v8 ignore stop */ });
|
|
@@ -268,21 +288,21 @@ const Tooltip = ({ trigger, label, placement = "top", mode = "system", animation
|
|
|
268
288
|
/* v8 ignore start - delayed interval callback */ const delayedRestartTooltip = useInterval(()=>{
|
|
269
289
|
setDisabled(false);
|
|
270
290
|
}, DEFAULT_DEACTIVATION_DELAY);
|
|
271
|
-
/* v8 ignore stop */ const
|
|
272
|
-
mode,
|
|
273
|
-
className,
|
|
274
|
-
tooltipClassName,
|
|
275
|
-
arrowClassName
|
|
276
|
-
});
|
|
277
|
-
const { isPositioned } = useTooltipPosition({
|
|
291
|
+
/* v8 ignore stop */ const { isPositioned } = useTooltipPosition({
|
|
278
292
|
triggerRef: referenceRef,
|
|
279
293
|
tooltipRef,
|
|
280
294
|
arrowRef,
|
|
281
295
|
placement,
|
|
282
296
|
sideOffset: 10,
|
|
283
|
-
animationDuration,
|
|
284
297
|
isOpen: showTooltip
|
|
285
298
|
});
|
|
299
|
+
const tooltipClasses = getTooltipClasses({
|
|
300
|
+
mode,
|
|
301
|
+
className,
|
|
302
|
+
tooltipClassName,
|
|
303
|
+
arrowClassName,
|
|
304
|
+
animate: isPositioned
|
|
305
|
+
});
|
|
286
306
|
useEffect(()=>{
|
|
287
307
|
/* v8 ignore start - cleanup function */ return ()=>{
|
|
288
308
|
if (showTimeoutRef.current) {
|
|
@@ -334,6 +354,9 @@ const Tooltip = ({ trigger, label, placement = "top", mode = "system", animation
|
|
|
334
354
|
ref: tooltipRef,
|
|
335
355
|
className: tooltipClasses.tooltip,
|
|
336
356
|
style: {
|
|
357
|
+
...getAnimationStyles({
|
|
358
|
+
animationDuration
|
|
359
|
+
}),
|
|
337
360
|
opacity: isPositioned ? undefined : 0
|
|
338
361
|
},
|
|
339
362
|
children: [
|
package/package.json
CHANGED
|
@@ -1,54 +1,53 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
2
|
+
"name": "@versini/ui-tooltip",
|
|
3
|
+
"version": "6.3.4",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"author": "Arno Versini",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"homepage": "https://www.npmjs.com/package/@versini/ui-tooltip",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git@github.com:aversini/ui-components.git"
|
|
13
|
+
},
|
|
14
|
+
"type": "module",
|
|
15
|
+
"main": "dist/index.js",
|
|
16
|
+
"types": "dist/index.d.ts",
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"README.md"
|
|
20
|
+
],
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@testing-library/jest-dom": "7.0.1"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@versini/ui-hooks": "6.2.2",
|
|
26
|
+
"clsx": "2.1.1",
|
|
27
|
+
"tailwindcss": "4.3.3"
|
|
28
|
+
},
|
|
29
|
+
"sideEffects": [
|
|
30
|
+
"**/*.css"
|
|
31
|
+
],
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"react": "^19.0.0"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build:check": "tsc",
|
|
37
|
+
"build:js": "rslib build",
|
|
38
|
+
"build:types": "echo 'Types now built with rslib'",
|
|
39
|
+
"build": "npm-run-all --serial clean build:check build:js",
|
|
40
|
+
"clean": "rimraf dist tmp coverage",
|
|
41
|
+
"dev:js": "rslib build --watch",
|
|
42
|
+
"dev:types": "echo 'Types now watched with rslib'",
|
|
43
|
+
"dev": "rslib build --watch",
|
|
44
|
+
"lint": "biome lint src",
|
|
45
|
+
"lint:fix": "biome check src --write --no-errors-on-unmatched",
|
|
46
|
+
"prettier": "biome check --write --no-errors-on-unmatched",
|
|
47
|
+
"start": "static-server dist --port 5173",
|
|
48
|
+
"test:coverage:ui": "vitest --coverage --ui",
|
|
49
|
+
"test:coverage": "vitest run --coverage",
|
|
50
|
+
"test:watch": "vitest",
|
|
51
|
+
"test": "vitest run"
|
|
52
|
+
}
|
|
53
|
+
}
|