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.
@@ -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"};
@@ -354,14 +376,17 @@ forwardRef, id, className, classNameArrow, variant = 'dark', anchorId, anchorSel
354
376
  // props handled by controller
355
377
  content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnchor, setActiveAnchor, border, opacity, arrowColor, role = 'tooltip', }) => {
356
378
  var _a;
379
+ console.log('render');
357
380
  const tooltipRef = useRef(null);
358
381
  const tooltipArrowRef = useRef(null);
359
382
  const tooltipShowDelayTimerRef = useRef(null);
360
383
  const tooltipHideDelayTimerRef = useRef(null);
361
384
  const missedTransitionTimerRef = useRef(null);
362
- const [actualPlacement, setActualPlacement] = useState(place);
363
- const [inlineStyles, setInlineStyles] = useState({});
364
- const [inlineArrowStyles, setInlineArrowStyles] = useState({});
385
+ const [computedPosition, setComputedPosition] = useState({
386
+ tooltipStyles: {},
387
+ tooltipArrowStyles: {},
388
+ place,
389
+ });
365
390
  const [show, setShow] = useState(false);
366
391
  const [rendered, setRendered] = useState(false);
367
392
  const [imperativeOptions, setImperativeOptions] = useState(null);
@@ -519,6 +544,11 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
519
544
  }, transitionShowDelay + 25);
520
545
  }
521
546
  }, [show]);
547
+ const handleComputedPosition = (newComputedPosition) => {
548
+ setComputedPosition((oldComputedPosition) => deepEqual(oldComputedPosition, newComputedPosition)
549
+ ? oldComputedPosition
550
+ : newComputedPosition);
551
+ };
522
552
  const handleShowTooltipDelayed = (delay = delayShow) => {
523
553
  if (tooltipShowDelayTimerRef.current) {
524
554
  clearTimeout(tooltipShowDelayTimerRef.current);
@@ -606,13 +636,7 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
606
636
  middlewares,
607
637
  border,
608
638
  }).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);
639
+ handleComputedPosition(computedStylesData);
616
640
  });
617
641
  };
618
642
  const handlePointerMove = (event) => {
@@ -702,13 +726,7 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
702
726
  // invalidate computed positions after remount
703
727
  return;
704
728
  }
705
- if (Object.keys(computedStylesData.tooltipStyles).length) {
706
- setInlineStyles(computedStylesData.tooltipStyles);
707
- }
708
- if (Object.keys(computedStylesData.tooltipArrowStyles).length) {
709
- setInlineArrowStyles(computedStylesData.tooltipArrowStyles);
710
- }
711
- setActualPlacement(computedStylesData.place);
729
+ handleComputedPosition(computedStylesData);
712
730
  });
713
731
  }, [
714
732
  show,
@@ -1043,7 +1061,7 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
1043
1061
  }
1044
1062
  }, [id, anchorSelect, imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.anchorSelect]);
1045
1063
  const actualContent = (_a = imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.content) !== null && _a !== void 0 ? _a : content;
1046
- const canShow = show && Object.keys(inlineStyles).length > 0;
1064
+ const canShow = show && Object.keys(computedPosition.tooltipStyles).length > 0;
1047
1065
  useImperativeHandle(forwardRef, () => ({
1048
1066
  open: (options) => {
1049
1067
  if (options === null || options === void 0 ? void 0 : options.anchorSelect) {
@@ -1075,10 +1093,10 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
1075
1093
  }
1076
1094
  },
1077
1095
  activeAnchor,
1078
- place: actualPlacement,
1096
+ place: computedPosition.place,
1079
1097
  isOpen: Boolean(rendered && !hidden && actualContent && canShow),
1080
1098
  }));
1081
- 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) => {
1099
+ 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) => {
1082
1100
  if (missedTransitionTimerRef.current) {
1083
1101
  clearTimeout(missedTransitionTimerRef.current);
1084
1102
  }
@@ -1090,12 +1108,12 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
1090
1108
  afterHide === null || afterHide === void 0 ? void 0 : afterHide();
1091
1109
  }, style: {
1092
1110
  ...externalStyles,
1093
- ...inlineStyles,
1111
+ ...computedPosition.tooltipStyles,
1094
1112
  opacity: opacity !== undefined && canShow ? opacity : undefined,
1095
1113
  }, ref: tooltipRef },
1096
1114
  actualContent,
1097
1115
  React.createElement(WrapperElement, { className: classNames('react-tooltip-arrow', coreStyles['arrow'], styles['arrow'], classNameArrow, noArrow && coreStyles['noArrow']), style: {
1098
- ...inlineArrowStyles,
1116
+ ...computedPosition.tooltipArrowStyles,
1099
1117
  background: arrowColor
1100
1118
  ? `linear-gradient(to right bottom, transparent 50%, ${arrowColor} 50%)`
1101
1119
  : undefined,