react-tooltip 5.26.1-beta.1168.0 → 5.26.1-beta.1169.0

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.
@@ -353,6 +353,28 @@ const cssTimeToMs = (time) => {
353
353
  return Number(amount) * (unit === 'ms' ? 1 : 1000);
354
354
  };
355
355
 
356
+ const isObject = (object) => {
357
+ return object !== null && typeof object === 'object';
358
+ };
359
+ const deepEqual = (object1, object2) => {
360
+ if (!isObject(object1) || !isObject(object2)) {
361
+ return object1 === object2;
362
+ }
363
+ const keys1 = Object.keys(object1);
364
+ const keys2 = Object.keys(object2);
365
+ if (keys1.length !== keys2.length) {
366
+ return false;
367
+ }
368
+ return keys1.every((key) => {
369
+ const val1 = object1[key];
370
+ const val2 = object2[key];
371
+ if (isObject(val1) && isObject(val2)) {
372
+ return deepEqual(val1, val2);
373
+ }
374
+ return val1 === val2;
375
+ });
376
+ };
377
+
356
378
  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"};
357
379
 
358
380
  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"};
@@ -363,14 +385,17 @@ forwardRef, id, className, classNameArrow, variant = 'dark', anchorId, anchorSel
363
385
  // props handled by controller
364
386
  content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnchor, setActiveAnchor, border, opacity, arrowColor, role = 'tooltip', }) => {
365
387
  var _a;
388
+ console.log('render');
366
389
  const tooltipRef = React.useRef(null);
367
390
  const tooltipArrowRef = React.useRef(null);
368
391
  const tooltipShowDelayTimerRef = React.useRef(null);
369
392
  const tooltipHideDelayTimerRef = React.useRef(null);
370
393
  const missedTransitionTimerRef = React.useRef(null);
371
- const [actualPlacement, setActualPlacement] = React.useState(place);
372
- const [inlineStyles, setInlineStyles] = React.useState({});
373
- const [inlineArrowStyles, setInlineArrowStyles] = React.useState({});
394
+ const [computedPosition, setComputedPosition] = React.useState({
395
+ tooltipStyles: {},
396
+ tooltipArrowStyles: {},
397
+ place,
398
+ });
374
399
  const [show, setShow] = React.useState(false);
375
400
  const [rendered, setRendered] = React.useState(false);
376
401
  const [imperativeOptions, setImperativeOptions] = React.useState(null);
@@ -528,15 +553,15 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
528
553
  }, transitionShowDelay + 25);
529
554
  }
530
555
  }, [show]);
556
+ const handleComputedPosition = (newComputedPosition) => {
557
+ setComputedPosition((oldComputedPosition) => deepEqual(oldComputedPosition, newComputedPosition)
558
+ ? oldComputedPosition
559
+ : newComputedPosition);
560
+ };
531
561
  const handleShowTooltipDelayed = (delay = delayShow) => {
532
562
  if (tooltipShowDelayTimerRef.current) {
533
563
  clearTimeout(tooltipShowDelayTimerRef.current);
534
564
  }
535
- if (rendered) {
536
- // if the tooltip is already rendered, ignore delay
537
- handleShow(true);
538
- return;
539
- }
540
565
  tooltipShowDelayTimerRef.current = setTimeout(() => {
541
566
  handleShow(true);
542
567
  }, delay);
@@ -620,13 +645,7 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
620
645
  middlewares,
621
646
  border,
622
647
  }).then((computedStylesData) => {
623
- if (Object.keys(computedStylesData.tooltipStyles).length) {
624
- setInlineStyles(computedStylesData.tooltipStyles);
625
- }
626
- if (Object.keys(computedStylesData.tooltipArrowStyles).length) {
627
- setInlineArrowStyles(computedStylesData.tooltipArrowStyles);
628
- }
629
- setActualPlacement(computedStylesData.place);
648
+ handleComputedPosition(computedStylesData);
630
649
  });
631
650
  };
632
651
  const handlePointerMove = (event) => {
@@ -716,13 +735,7 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
716
735
  // invalidate computed positions after remount
717
736
  return;
718
737
  }
719
- if (Object.keys(computedStylesData.tooltipStyles).length) {
720
- setInlineStyles(computedStylesData.tooltipStyles);
721
- }
722
- if (Object.keys(computedStylesData.tooltipArrowStyles).length) {
723
- setInlineArrowStyles(computedStylesData.tooltipArrowStyles);
724
- }
725
- setActualPlacement(computedStylesData.place);
738
+ handleComputedPosition(computedStylesData);
726
739
  });
727
740
  }, [
728
741
  show,
@@ -898,8 +911,6 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
898
911
  closeEvents,
899
912
  globalCloseEvents,
900
913
  shouldOpenOnClick,
901
- delayShow,
902
- delayHide,
903
914
  ]);
904
915
  React.useEffect(() => {
905
916
  var _a, _b;
@@ -1058,14 +1069,8 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
1058
1069
  setAnchorsBySelect([]);
1059
1070
  }
1060
1071
  }, [id, anchorSelect, imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.anchorSelect]);
1061
- React.useEffect(() => {
1062
- if (tooltipShowDelayTimerRef.current) {
1063
- clearTimeout(tooltipShowDelayTimerRef.current);
1064
- handleShowTooltipDelayed(delayShow);
1065
- }
1066
- }, [delayShow]);
1067
1072
  const actualContent = (_a = imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.content) !== null && _a !== void 0 ? _a : content;
1068
- const canShow = show && Object.keys(inlineStyles).length > 0;
1073
+ const canShow = show && Object.keys(computedPosition.tooltipStyles).length > 0;
1069
1074
  React.useImperativeHandle(forwardRef, () => ({
1070
1075
  open: (options) => {
1071
1076
  if (options === null || options === void 0 ? void 0 : options.anchorSelect) {
@@ -1097,10 +1102,10 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
1097
1102
  }
1098
1103
  },
1099
1104
  activeAnchor,
1100
- place: actualPlacement,
1105
+ place: computedPosition.place,
1101
1106
  isOpen: Boolean(rendered && !hidden && actualContent && canShow),
1102
1107
  }));
1103
- return rendered && !hidden && actualContent ? (React__default["default"].createElement(WrapperElement, { id: id, role: role, className: classNames__default["default"]('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) => {
1108
+ return rendered && !hidden && actualContent ? (React__default["default"].createElement(WrapperElement, { id: id, role: role, className: classNames__default["default"]('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) => {
1104
1109
  if (missedTransitionTimerRef.current) {
1105
1110
  clearTimeout(missedTransitionTimerRef.current);
1106
1111
  }
@@ -1112,12 +1117,12 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
1112
1117
  afterHide === null || afterHide === void 0 ? void 0 : afterHide();
1113
1118
  }, style: {
1114
1119
  ...externalStyles,
1115
- ...inlineStyles,
1120
+ ...computedPosition.tooltipStyles,
1116
1121
  opacity: opacity !== undefined && canShow ? opacity : undefined,
1117
1122
  }, ref: tooltipRef },
1118
1123
  actualContent,
1119
1124
  React__default["default"].createElement(WrapperElement, { className: classNames__default["default"]('react-tooltip-arrow', coreStyles['arrow'], styles['arrow'], classNameArrow, noArrow && coreStyles['noArrow']), style: {
1120
- ...inlineArrowStyles,
1125
+ ...computedPosition.tooltipArrowStyles,
1121
1126
  background: arrowColor
1122
1127
  ? `linear-gradient(to right bottom, transparent 50%, ${arrowColor} 50%)`
1123
1128
  : undefined,