@versini/ui-tooltip 6.3.3 → 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.
Files changed (2) hide show
  1. package/dist/index.js +45 -22
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- @versini/ui-tooltip v6.3.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
- }), tooltipClassName);
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
- const getAnimationStyles = ({ animationDuration = 300 })=>{
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
- animation: `av-tooltip-fade-in ${animationDuration}ms ease-in-out`
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, animationDuration, isOpen }) {
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 = 300, delay = 0, className, tooltipClassName, arrowClassName })=>{
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 tooltipClasses = getTooltipClasses({
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@versini/ui-tooltip",
3
- "version": "6.3.3",
3
+ "version": "6.3.4",
4
4
  "license": "MIT",
5
5
  "author": "Arno Versini",
6
6
  "publishConfig": {
@@ -22,9 +22,9 @@
22
22
  "@testing-library/jest-dom": "7.0.1"
23
23
  },
24
24
  "dependencies": {
25
+ "@versini/ui-hooks": "6.2.2",
25
26
  "clsx": "2.1.1",
26
- "tailwindcss": "4.3.3",
27
- "@versini/ui-hooks": "6.2.2"
27
+ "tailwindcss": "4.3.3"
28
28
  },
29
29
  "sideEffects": [
30
30
  "**/*.css"