react-tooltip 5.26.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.
@@ -351,6 +351,28 @@
351
351
  return Number(amount) * (unit === 'ms' ? 1 : 1000);
352
352
  };
353
353
 
354
+ const isObject = (object) => {
355
+ return object !== null && typeof object === 'object';
356
+ };
357
+ const deepEqual = (object1, object2) => {
358
+ if (!isObject(object1) || !isObject(object2)) {
359
+ return object1 === object2;
360
+ }
361
+ const keys1 = Object.keys(object1);
362
+ const keys2 = Object.keys(object2);
363
+ if (keys1.length !== keys2.length) {
364
+ return false;
365
+ }
366
+ return keys1.every((key) => {
367
+ const val1 = object1[key];
368
+ const val2 = object2[key];
369
+ if (isObject(val1) && isObject(val2)) {
370
+ return deepEqual(val1, val2);
371
+ }
372
+ return val1 === val2;
373
+ });
374
+ };
375
+
354
376
  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"};
355
377
 
356
378
  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"};
@@ -361,14 +383,17 @@
361
383
  // props handled by controller
362
384
  content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnchor, setActiveAnchor, border, opacity, arrowColor, role = 'tooltip', }) => {
363
385
  var _a;
386
+ console.log('render');
364
387
  const tooltipRef = React.useRef(null);
365
388
  const tooltipArrowRef = React.useRef(null);
366
389
  const tooltipShowDelayTimerRef = React.useRef(null);
367
390
  const tooltipHideDelayTimerRef = React.useRef(null);
368
391
  const missedTransitionTimerRef = React.useRef(null);
369
- const [actualPlacement, setActualPlacement] = React.useState(place);
370
- const [inlineStyles, setInlineStyles] = React.useState({});
371
- const [inlineArrowStyles, setInlineArrowStyles] = React.useState({});
392
+ const [computedPosition, setComputedPosition] = React.useState({
393
+ tooltipStyles: {},
394
+ tooltipArrowStyles: {},
395
+ place,
396
+ });
372
397
  const [show, setShow] = React.useState(false);
373
398
  const [rendered, setRendered] = React.useState(false);
374
399
  const [imperativeOptions, setImperativeOptions] = React.useState(null);
@@ -526,6 +551,11 @@
526
551
  }, transitionShowDelay + 25);
527
552
  }
528
553
  }, [show]);
554
+ const handleComputedPosition = (newComputedPosition) => {
555
+ setComputedPosition((oldComputedPosition) => deepEqual(oldComputedPosition, newComputedPosition)
556
+ ? oldComputedPosition
557
+ : newComputedPosition);
558
+ };
529
559
  const handleShowTooltipDelayed = (delay = delayShow) => {
530
560
  if (tooltipShowDelayTimerRef.current) {
531
561
  clearTimeout(tooltipShowDelayTimerRef.current);
@@ -613,13 +643,7 @@
613
643
  middlewares,
614
644
  border,
615
645
  }).then((computedStylesData) => {
616
- if (Object.keys(computedStylesData.tooltipStyles).length) {
617
- setInlineStyles(computedStylesData.tooltipStyles);
618
- }
619
- if (Object.keys(computedStylesData.tooltipArrowStyles).length) {
620
- setInlineArrowStyles(computedStylesData.tooltipArrowStyles);
621
- }
622
- setActualPlacement(computedStylesData.place);
646
+ handleComputedPosition(computedStylesData);
623
647
  });
624
648
  };
625
649
  const handlePointerMove = (event) => {
@@ -709,13 +733,7 @@
709
733
  // invalidate computed positions after remount
710
734
  return;
711
735
  }
712
- if (Object.keys(computedStylesData.tooltipStyles).length) {
713
- setInlineStyles(computedStylesData.tooltipStyles);
714
- }
715
- if (Object.keys(computedStylesData.tooltipArrowStyles).length) {
716
- setInlineArrowStyles(computedStylesData.tooltipArrowStyles);
717
- }
718
- setActualPlacement(computedStylesData.place);
736
+ handleComputedPosition(computedStylesData);
719
737
  });
720
738
  }, [
721
739
  show,
@@ -1050,7 +1068,7 @@
1050
1068
  }
1051
1069
  }, [id, anchorSelect, imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.anchorSelect]);
1052
1070
  const actualContent = (_a = imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.content) !== null && _a !== void 0 ? _a : content;
1053
- const canShow = show && Object.keys(inlineStyles).length > 0;
1071
+ const canShow = show && Object.keys(computedPosition.tooltipStyles).length > 0;
1054
1072
  React.useImperativeHandle(forwardRef, () => ({
1055
1073
  open: (options) => {
1056
1074
  if (options === null || options === void 0 ? void 0 : options.anchorSelect) {
@@ -1082,10 +1100,10 @@
1082
1100
  }
1083
1101
  },
1084
1102
  activeAnchor,
1085
- place: actualPlacement,
1103
+ place: computedPosition.place,
1086
1104
  isOpen: Boolean(rendered && !hidden && actualContent && canShow),
1087
1105
  }));
1088
- 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) => {
1106
+ 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) => {
1089
1107
  if (missedTransitionTimerRef.current) {
1090
1108
  clearTimeout(missedTransitionTimerRef.current);
1091
1109
  }
@@ -1097,12 +1115,12 @@
1097
1115
  afterHide === null || afterHide === void 0 ? void 0 : afterHide();
1098
1116
  }, style: {
1099
1117
  ...externalStyles,
1100
- ...inlineStyles,
1118
+ ...computedPosition.tooltipStyles,
1101
1119
  opacity: opacity !== undefined && canShow ? opacity : undefined,
1102
1120
  }, ref: tooltipRef },
1103
1121
  actualContent,
1104
1122
  React__default["default"].createElement(WrapperElement, { className: classNames__default["default"]('react-tooltip-arrow', coreStyles['arrow'], styles['arrow'], classNameArrow, noArrow && coreStyles['noArrow']), style: {
1105
- ...inlineArrowStyles,
1123
+ ...computedPosition.tooltipArrowStyles,
1106
1124
  background: arrowColor
1107
1125
  ? `linear-gradient(to right bottom, transparent 50%, ${arrowColor} 50%)`
1108
1126
  : undefined,