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.
@@ -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,6 +553,11 @@ 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);
@@ -615,13 +645,7 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
615
645
  middlewares,
616
646
  border,
617
647
  }).then((computedStylesData) => {
618
- if (Object.keys(computedStylesData.tooltipStyles).length) {
619
- setInlineStyles(computedStylesData.tooltipStyles);
620
- }
621
- if (Object.keys(computedStylesData.tooltipArrowStyles).length) {
622
- setInlineArrowStyles(computedStylesData.tooltipArrowStyles);
623
- }
624
- setActualPlacement(computedStylesData.place);
648
+ handleComputedPosition(computedStylesData);
625
649
  });
626
650
  };
627
651
  const handlePointerMove = (event) => {
@@ -711,13 +735,7 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
711
735
  // invalidate computed positions after remount
712
736
  return;
713
737
  }
714
- if (Object.keys(computedStylesData.tooltipStyles).length) {
715
- setInlineStyles(computedStylesData.tooltipStyles);
716
- }
717
- if (Object.keys(computedStylesData.tooltipArrowStyles).length) {
718
- setInlineArrowStyles(computedStylesData.tooltipArrowStyles);
719
- }
720
- setActualPlacement(computedStylesData.place);
738
+ handleComputedPosition(computedStylesData);
721
739
  });
722
740
  }, [
723
741
  show,
@@ -1052,7 +1070,7 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
1052
1070
  }
1053
1071
  }, [id, anchorSelect, imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.anchorSelect]);
1054
1072
  const actualContent = (_a = imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.content) !== null && _a !== void 0 ? _a : content;
1055
- const canShow = show && Object.keys(inlineStyles).length > 0;
1073
+ const canShow = show && Object.keys(computedPosition.tooltipStyles).length > 0;
1056
1074
  React.useImperativeHandle(forwardRef, () => ({
1057
1075
  open: (options) => {
1058
1076
  if (options === null || options === void 0 ? void 0 : options.anchorSelect) {
@@ -1084,10 +1102,10 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
1084
1102
  }
1085
1103
  },
1086
1104
  activeAnchor,
1087
- place: actualPlacement,
1105
+ place: computedPosition.place,
1088
1106
  isOpen: Boolean(rendered && !hidden && actualContent && canShow),
1089
1107
  }));
1090
- 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) => {
1091
1109
  if (missedTransitionTimerRef.current) {
1092
1110
  clearTimeout(missedTransitionTimerRef.current);
1093
1111
  }
@@ -1099,12 +1117,12 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
1099
1117
  afterHide === null || afterHide === void 0 ? void 0 : afterHide();
1100
1118
  }, style: {
1101
1119
  ...externalStyles,
1102
- ...inlineStyles,
1120
+ ...computedPosition.tooltipStyles,
1103
1121
  opacity: opacity !== undefined && canShow ? opacity : undefined,
1104
1122
  }, ref: tooltipRef },
1105
1123
  actualContent,
1106
1124
  React__default["default"].createElement(WrapperElement, { className: classNames__default["default"]('react-tooltip-arrow', coreStyles['arrow'], styles['arrow'], classNameArrow, noArrow && coreStyles['noArrow']), style: {
1107
- ...inlineArrowStyles,
1125
+ ...computedPosition.tooltipArrowStyles,
1108
1126
  background: arrowColor
1109
1127
  ? `linear-gradient(to right bottom, transparent 50%, ${arrowColor} 50%)`
1110
1128
  : undefined,