react-tooltip 5.26.1-beta.1170.0 → 5.26.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.
@@ -344,6 +344,28 @@ const cssTimeToMs = (time) => {
344
344
  return Number(amount) * (unit === 'ms' ? 1 : 1000);
345
345
  };
346
346
 
347
+ const isObject = (object) => {
348
+ return object !== null && typeof object === 'object';
349
+ };
350
+ const deepEqual = (object1, object2) => {
351
+ if (!isObject(object1) || !isObject(object2)) {
352
+ return object1 === object2;
353
+ }
354
+ const keys1 = Object.keys(object1);
355
+ const keys2 = Object.keys(object2);
356
+ if (keys1.length !== keys2.length) {
357
+ return false;
358
+ }
359
+ return keys1.every((key) => {
360
+ const val1 = object1[key];
361
+ const val2 = object2[key];
362
+ if (isObject(val1) && isObject(val2)) {
363
+ return deepEqual(val1, val2);
364
+ }
365
+ return val1 === val2;
366
+ });
367
+ };
368
+
347
369
  var coreStyles = {"tooltip":"core-styles-module_tooltip__3vRRp","fixed":"core-styles-module_fixed__pcSol","arrow":"core-styles-module_arrow__cvMwQ","noArrow":"core-styles-module_noArrow__xock6","clickable":"core-styles-module_clickable__ZuTTB","show":"core-styles-module_show__Nt9eE","closing":"core-styles-module_closing__sGnxF"};
348
370
 
349
371
  var styles = {"tooltip":"styles-module_tooltip__mnnfp","arrow":"styles-module_arrow__K0L3T","dark":"styles-module_dark__xNqje","light":"styles-module_light__Z6W-X","success":"styles-module_success__A2AKt","warning":"styles-module_warning__SCK0X","error":"styles-module_error__JvumD","info":"styles-module_info__BWdHW"};
@@ -359,9 +381,11 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
359
381
  const tooltipShowDelayTimerRef = useRef(null);
360
382
  const tooltipHideDelayTimerRef = useRef(null);
361
383
  const missedTransitionTimerRef = useRef(null);
362
- const [actualPlacement, setActualPlacement] = useState(place);
363
- const [inlineStyles, setInlineStyles] = useState({});
364
- const [inlineArrowStyles, setInlineArrowStyles] = useState({});
384
+ const [computedPosition, setComputedPosition] = useState({
385
+ tooltipStyles: {},
386
+ tooltipArrowStyles: {},
387
+ place,
388
+ });
365
389
  const [show, setShow] = useState(false);
366
390
  const [rendered, setRendered] = useState(false);
367
391
  const [imperativeOptions, setImperativeOptions] = useState(null);
@@ -519,10 +543,20 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
519
543
  }, transitionShowDelay + 25);
520
544
  }
521
545
  }, [show]);
546
+ const handleComputedPosition = (newComputedPosition) => {
547
+ setComputedPosition((oldComputedPosition) => deepEqual(oldComputedPosition, newComputedPosition)
548
+ ? oldComputedPosition
549
+ : newComputedPosition);
550
+ };
522
551
  const handleShowTooltipDelayed = (delay = delayShow) => {
523
552
  if (tooltipShowDelayTimerRef.current) {
524
553
  clearTimeout(tooltipShowDelayTimerRef.current);
525
554
  }
555
+ if (rendered) {
556
+ // if the tooltip is already rendered, ignore delay
557
+ handleShow(true);
558
+ return;
559
+ }
526
560
  tooltipShowDelayTimerRef.current = setTimeout(() => {
527
561
  handleShow(true);
528
562
  }, delay);
@@ -606,13 +640,7 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
606
640
  middlewares,
607
641
  border,
608
642
  }).then((computedStylesData) => {
609
- if (Object.keys(computedStylesData.tooltipStyles).length) {
610
- setInlineStyles(computedStylesData.tooltipStyles);
611
- }
612
- if (Object.keys(computedStylesData.tooltipArrowStyles).length) {
613
- setInlineArrowStyles(computedStylesData.tooltipArrowStyles);
614
- }
615
- setActualPlacement(computedStylesData.place);
643
+ handleComputedPosition(computedStylesData);
616
644
  });
617
645
  };
618
646
  const handlePointerMove = (event) => {
@@ -705,13 +733,7 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
705
733
  // invalidate computed positions after remount
706
734
  return;
707
735
  }
708
- if (Object.keys(computedStylesData.tooltipStyles).length) {
709
- setInlineStyles(computedStylesData.tooltipStyles);
710
- }
711
- if (Object.keys(computedStylesData.tooltipArrowStyles).length) {
712
- setInlineArrowStyles(computedStylesData.tooltipArrowStyles);
713
- }
714
- setActualPlacement(computedStylesData.place);
736
+ handleComputedPosition(computedStylesData);
715
737
  });
716
738
  }, [
717
739
  show,
@@ -887,6 +909,8 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
887
909
  closeEvents,
888
910
  globalCloseEvents,
889
911
  shouldOpenOnClick,
912
+ delayShow,
913
+ delayHide,
890
914
  ]);
891
915
  useEffect(() => {
892
916
  var _a, _b;
@@ -1045,8 +1069,14 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
1045
1069
  setAnchorsBySelect([]);
1046
1070
  }
1047
1071
  }, [id, anchorSelect, imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.anchorSelect]);
1072
+ useEffect(() => {
1073
+ if (tooltipShowDelayTimerRef.current) {
1074
+ clearTimeout(tooltipShowDelayTimerRef.current);
1075
+ handleShowTooltipDelayed(delayShow);
1076
+ }
1077
+ }, [delayShow]);
1048
1078
  const actualContent = (_a = imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.content) !== null && _a !== void 0 ? _a : content;
1049
- const canShow = show && Object.keys(inlineStyles).length > 0;
1079
+ const canShow = show && Object.keys(computedPosition.tooltipStyles).length > 0;
1050
1080
  useImperativeHandle(forwardRef, () => ({
1051
1081
  open: (options) => {
1052
1082
  if (options === null || options === void 0 ? void 0 : options.anchorSelect) {
@@ -1078,10 +1108,10 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
1078
1108
  }
1079
1109
  },
1080
1110
  activeAnchor,
1081
- place: actualPlacement,
1111
+ place: computedPosition.place,
1082
1112
  isOpen: Boolean(rendered && !hidden && actualContent && canShow),
1083
1113
  }));
1084
- return rendered && !hidden && actualContent ? (React.createElement(WrapperElement, { id: id, role: role, className: classNames('react-tooltip', coreStyles['tooltip'], styles['tooltip'], styles[variant], className, `react-tooltip__place-${actualPlacement}`, coreStyles[canShow ? 'show' : 'closing'], canShow ? 'react-tooltip__show' : 'react-tooltip__closing', positionStrategy === 'fixed' && coreStyles['fixed'], clickable && coreStyles['clickable']), onTransitionEnd: (event) => {
1114
+ return rendered && !hidden && actualContent ? (React.createElement(WrapperElement, { id: id, role: role, className: classNames('react-tooltip', coreStyles['tooltip'], styles['tooltip'], styles[variant], className, `react-tooltip__place-${computedPosition.place}`, coreStyles[canShow ? 'show' : 'closing'], canShow ? 'react-tooltip__show' : 'react-tooltip__closing', positionStrategy === 'fixed' && coreStyles['fixed'], clickable && coreStyles['clickable']), onTransitionEnd: (event) => {
1085
1115
  if (missedTransitionTimerRef.current) {
1086
1116
  clearTimeout(missedTransitionTimerRef.current);
1087
1117
  }
@@ -1093,12 +1123,12 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
1093
1123
  afterHide === null || afterHide === void 0 ? void 0 : afterHide();
1094
1124
  }, style: {
1095
1125
  ...externalStyles,
1096
- ...inlineStyles,
1126
+ ...computedPosition.tooltipStyles,
1097
1127
  opacity: opacity !== undefined && canShow ? opacity : undefined,
1098
1128
  }, ref: tooltipRef },
1099
1129
  actualContent,
1100
1130
  React.createElement(WrapperElement, { className: classNames('react-tooltip-arrow', coreStyles['arrow'], styles['arrow'], classNameArrow, noArrow && coreStyles['noArrow']), style: {
1101
- ...inlineArrowStyles,
1131
+ ...computedPosition.tooltipArrowStyles,
1102
1132
  background: arrowColor
1103
1133
  ? `linear-gradient(to right bottom, transparent 50%, ${arrowColor} 50%)`
1104
1134
  : undefined,
@@ -1333,7 +1363,8 @@ const TooltipController = React.forwardRef(({ id, anchorId, anchorSelect, conten
1333
1363
  let renderedContent = children;
1334
1364
  const contentWrapperRef = useRef(null);
1335
1365
  if (render) {
1336
- const rendered = render({ content: tooltipContent !== null && tooltipContent !== void 0 ? tooltipContent : null, activeAnchor });
1366
+ const actualContent = (activeAnchor === null || activeAnchor === void 0 ? void 0 : activeAnchor.getAttribute('data-tooltip-content')) || tooltipContent || null;
1367
+ const rendered = render({ content: actualContent, activeAnchor });
1337
1368
  renderedContent = rendered ? (React.createElement("div", { ref: contentWrapperRef, className: "react-tooltip-content-wrapper" }, rendered)) : null;
1338
1369
  }
1339
1370
  else if (tooltipContent) {