react-tooltip 5.22.0-beta.1106.0 → 5.22.0-beta.1108.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.
@@ -325,13 +325,13 @@
325
325
  });
326
326
  };
327
327
 
328
- 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"};
328
+ 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"};
329
329
 
330
330
  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"};
331
331
 
332
332
  const Tooltip = ({
333
333
  // props
334
- id, className, classNameArrow, variant = 'dark', anchorId, anchorSelect, place = 'top', offset = 10, events = ['hover'], openOnClick = false, positionStrategy = 'absolute', middlewares, wrapper: WrapperElement, delayShow = 0, delayHide = 0, float = false, hidden = false, noArrow = false, clickable = false, closeOnEsc = false, closeOnScroll = false, closeOnResize = false, style: externalStyles, position, afterShow, afterHide,
334
+ id, className, classNameArrow, variant = 'dark', anchorId, anchorSelect, place = 'top', offset = 10, events = ['hover'], openOnClick = false, positionStrategy = 'absolute', middlewares, wrapper: WrapperElement, delayShow = 0, delayHide = 0, float = false, hidden = false, noArrow = false, clickable = false, closeOnEsc = false, closeOnScroll = false, closeOnResize = false, openEvents, closeEvents, globalCloseEvents, style: externalStyles, position, afterShow, afterHide,
335
335
  // props handled by controller
336
336
  content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, border, opacity, arrowColor, }) => {
337
337
  const tooltipRef = React.useRef(null);
@@ -352,7 +352,48 @@
352
352
  const hoveringTooltip = React.useRef(false);
353
353
  const [anchorsBySelect, setAnchorsBySelect] = React.useState([]);
354
354
  const mounted = React.useRef(false);
355
+ /**
356
+ * @todo Update when deprecated stuff gets removed.
357
+ */
355
358
  const shouldOpenOnClick = openOnClick || events.includes('click');
359
+ const hasClickEvent = shouldOpenOnClick || (openEvents === null || openEvents === void 0 ? void 0 : openEvents.click) || (openEvents === null || openEvents === void 0 ? void 0 : openEvents.dblclick) || (openEvents === null || openEvents === void 0 ? void 0 : openEvents.mousedown);
360
+ const actualOpenEvents = openEvents
361
+ ? { ...openEvents }
362
+ : {
363
+ mouseenter: true,
364
+ focus: true,
365
+ click: false,
366
+ dblclick: false,
367
+ mousedown: false,
368
+ };
369
+ if (!openEvents && shouldOpenOnClick) {
370
+ Object.assign(actualOpenEvents, {
371
+ mouseenter: false,
372
+ focus: false,
373
+ click: true,
374
+ });
375
+ }
376
+ const actualCloseEvents = closeEvents
377
+ ? { ...closeEvents }
378
+ : {
379
+ mouseleave: true,
380
+ blur: true,
381
+ click: false,
382
+ };
383
+ if (!closeEvents && shouldOpenOnClick) {
384
+ Object.assign(actualCloseEvents, {
385
+ mouseleave: false,
386
+ blur: false,
387
+ });
388
+ }
389
+ const actualGlobalCloseEvents = globalCloseEvents
390
+ ? { ...globalCloseEvents }
391
+ : {
392
+ escape: closeOnEsc || false,
393
+ scroll: closeOnScroll || false,
394
+ resize: closeOnResize || false,
395
+ clickOutsideAnchor: hasClickEvent || false,
396
+ };
356
397
  /**
357
398
  * useLayoutEffect runs before useEffect,
358
399
  * but should be used carefully because of caveats
@@ -364,6 +405,23 @@
364
405
  mounted.current = false;
365
406
  };
366
407
  }, []);
408
+ React.useEffect(() => {
409
+ if (!show) {
410
+ /**
411
+ * this fixes weird behavior when switching between two anchor elements very quickly
412
+ * remove the timeout and switch quickly between two adjancent anchor elements to see it
413
+ *
414
+ * in practice, this means the tooltip is not immediately removed from the DOM on hide
415
+ */
416
+ const timeout = setTimeout(() => {
417
+ setRendered(false);
418
+ }, 150);
419
+ return () => {
420
+ clearTimeout(timeout);
421
+ };
422
+ }
423
+ return () => null;
424
+ }, [show]);
367
425
  const handleShow = (value) => {
368
426
  if (!mounted.current) {
369
427
  return;
@@ -522,12 +580,6 @@
522
580
  handleTooltipPosition(mousePosition);
523
581
  lastFloatPosition.current = mousePosition;
524
582
  };
525
- const handleClickTooltipAnchor = (event) => {
526
- handleShowTooltip(event);
527
- if (delayHide) {
528
- handleHideTooltipDelayed();
529
- }
530
- };
531
583
  const handleClickOutsideAnchors = (event) => {
532
584
  var _a;
533
585
  const anchorById = document.querySelector(`[id='${anchorId}']`);
@@ -618,13 +670,13 @@
618
670
  };
619
671
  const anchorScrollParent = getScrollParent(activeAnchor);
620
672
  const tooltipScrollParent = getScrollParent(tooltipRef.current);
621
- if (closeOnScroll) {
673
+ if (actualGlobalCloseEvents.scroll) {
622
674
  window.addEventListener('scroll', handleScrollResize);
623
675
  anchorScrollParent === null || anchorScrollParent === void 0 ? void 0 : anchorScrollParent.addEventListener('scroll', handleScrollResize);
624
676
  tooltipScrollParent === null || tooltipScrollParent === void 0 ? void 0 : tooltipScrollParent.addEventListener('scroll', handleScrollResize);
625
677
  }
626
678
  let updateTooltipCleanup = null;
627
- if (closeOnResize) {
679
+ if (actualGlobalCloseEvents.resize) {
628
680
  window.addEventListener('resize', handleScrollResize);
629
681
  }
630
682
  else if (activeAnchor && tooltipRef.current) {
@@ -640,22 +692,56 @@
640
692
  }
641
693
  handleShow(false);
642
694
  };
643
- if (closeOnEsc) {
695
+ if (actualGlobalCloseEvents.escape) {
644
696
  window.addEventListener('keydown', handleEsc);
645
697
  }
646
- const enabledEvents = [];
647
- if (shouldOpenOnClick) {
698
+ if (actualGlobalCloseEvents.clickOutsideAnchor) {
648
699
  window.addEventListener('click', handleClickOutsideAnchors);
649
- enabledEvents.push({ event: 'click', listener: handleClickTooltipAnchor });
650
700
  }
651
- else {
652
- enabledEvents.push({ event: 'mouseenter', listener: debouncedHandleShowTooltip }, { event: 'mouseleave', listener: debouncedHandleHideTooltip }, { event: 'focus', listener: debouncedHandleShowTooltip }, { event: 'blur', listener: debouncedHandleHideTooltip });
653
- if (float) {
654
- enabledEvents.push({
655
- event: 'mousemove',
656
- listener: handleMouseMove,
657
- });
701
+ const enabledEvents = [];
702
+ const handleClickOpenTooltipAnchor = (event) => {
703
+ if (show) {
704
+ return;
658
705
  }
706
+ handleShowTooltip(event);
707
+ };
708
+ const handleClickCloseTooltipAnchor = () => {
709
+ if (!show) {
710
+ return;
711
+ }
712
+ handleHideTooltip();
713
+ };
714
+ const regularEvents = ['mouseenter', 'mouseleave', 'focus', 'blur'];
715
+ const clickEvents = ['click', 'dblclick', 'mousedown', 'mouseup'];
716
+ Object.entries(actualOpenEvents).forEach(([event, enabled]) => {
717
+ if (!enabled) {
718
+ return;
719
+ }
720
+ if (regularEvents.includes(event)) {
721
+ enabledEvents.push({ event, listener: debouncedHandleShowTooltip });
722
+ }
723
+ else if (clickEvents.includes(event)) {
724
+ enabledEvents.push({ event, listener: handleClickOpenTooltipAnchor });
725
+ }
726
+ else ;
727
+ });
728
+ Object.entries(actualCloseEvents).forEach(([event, enabled]) => {
729
+ if (!enabled) {
730
+ return;
731
+ }
732
+ if (regularEvents.includes(event)) {
733
+ enabledEvents.push({ event, listener: debouncedHandleHideTooltip });
734
+ }
735
+ else if (clickEvents.includes(event)) {
736
+ enabledEvents.push({ event, listener: handleClickCloseTooltipAnchor });
737
+ }
738
+ else ;
739
+ });
740
+ if (float) {
741
+ enabledEvents.push({
742
+ event: 'mousemove',
743
+ listener: handleMouseMove,
744
+ });
659
745
  }
660
746
  const handleMouseEnterTooltip = () => {
661
747
  hoveringTooltip.current = true;
@@ -664,7 +750,9 @@
664
750
  hoveringTooltip.current = false;
665
751
  handleHideTooltip();
666
752
  };
667
- if (clickable && !shouldOpenOnClick) {
753
+ if (clickable && !hasClickEvent) {
754
+ // used to keep the tooltip open when hovering content.
755
+ // not needed if using click events.
668
756
  (_a = tooltipRef.current) === null || _a === void 0 ? void 0 : _a.addEventListener('mouseenter', handleMouseEnterTooltip);
669
757
  (_b = tooltipRef.current) === null || _b === void 0 ? void 0 : _b.addEventListener('mouseleave', handleMouseLeaveTooltip);
670
758
  }
@@ -676,24 +764,24 @@
676
764
  });
677
765
  return () => {
678
766
  var _a, _b;
679
- if (closeOnScroll) {
767
+ if (actualGlobalCloseEvents.scroll) {
680
768
  window.removeEventListener('scroll', handleScrollResize);
681
769
  anchorScrollParent === null || anchorScrollParent === void 0 ? void 0 : anchorScrollParent.removeEventListener('scroll', handleScrollResize);
682
770
  tooltipScrollParent === null || tooltipScrollParent === void 0 ? void 0 : tooltipScrollParent.removeEventListener('scroll', handleScrollResize);
683
771
  }
684
- if (closeOnResize) {
772
+ if (actualGlobalCloseEvents.resize) {
685
773
  window.removeEventListener('resize', handleScrollResize);
686
774
  }
687
775
  else {
688
776
  updateTooltipCleanup === null || updateTooltipCleanup === void 0 ? void 0 : updateTooltipCleanup();
689
777
  }
690
- if (shouldOpenOnClick) {
778
+ if (actualGlobalCloseEvents.clickOutsideAnchor) {
691
779
  window.removeEventListener('click', handleClickOutsideAnchors);
692
780
  }
693
- if (closeOnEsc) {
781
+ if (actualGlobalCloseEvents.escape) {
694
782
  window.removeEventListener('keydown', handleEsc);
695
783
  }
696
- if (clickable && !shouldOpenOnClick) {
784
+ if (clickable && !hasClickEvent) {
697
785
  (_a = tooltipRef.current) === null || _a === void 0 ? void 0 : _a.removeEventListener('mouseenter', handleMouseEnterTooltip);
698
786
  (_b = tooltipRef.current) === null || _b === void 0 ? void 0 : _b.removeEventListener('mouseleave', handleMouseLeaveTooltip);
699
787
  }
@@ -714,8 +802,11 @@
714
802
  rendered,
715
803
  anchorRefs,
716
804
  anchorsBySelect,
717
- closeOnEsc,
718
- events,
805
+ // the effect uses the `actual*Events` objects, but this should work
806
+ openEvents,
807
+ closeEvents,
808
+ globalCloseEvents,
809
+ shouldOpenOnClick,
719
810
  ]);
720
811
  React.useEffect(() => {
721
812
  let selector = anchorSelect !== null && anchorSelect !== void 0 ? anchorSelect : '';
@@ -864,22 +955,24 @@
864
955
  }
865
956
  }, [id, anchorSelect]);
866
957
  const canShow = !hidden && content && show && Object.keys(inlineStyles).length > 0;
867
- return rendered ? (React__default["default"].createElement(WrapperElement, { id: id, role: "tooltip", 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) => {
868
- /**
869
- * @warning if `--rt-transition-closing-delay` is set to 0,
870
- * the tooltip will be stuck (but not visible) on the DOM
871
- */
872
- if (show || event.propertyName !== 'opacity') {
873
- return;
874
- }
875
- setRendered(false);
876
- }, style: {
958
+ return rendered ? (React__default["default"].createElement(WrapperElement, { id: id, role: "tooltip", className: classNames__default["default"]('react-tooltip', coreStyles['tooltip'], styles['tooltip'], styles[variant], className, `react-tooltip__place-${actualPlacement}`, {
959
+ 'react-tooltip__show': canShow,
960
+ [coreStyles['show']]: canShow,
961
+ [coreStyles['fixed']]: positionStrategy === 'fixed',
962
+ [coreStyles['clickable']]: clickable,
963
+ }), style: {
877
964
  ...externalStyles,
878
965
  ...inlineStyles,
879
966
  opacity: opacity !== undefined && canShow ? opacity : undefined,
880
967
  }, ref: tooltipRef },
881
968
  content,
882
- React__default["default"].createElement(WrapperElement, { className: classNames__default["default"]('react-tooltip-arrow', coreStyles['arrow'], styles['arrow'], classNameArrow, noArrow && coreStyles['noArrow']), style: {
969
+ React__default["default"].createElement(WrapperElement, { className: classNames__default["default"]('react-tooltip-arrow', coreStyles['arrow'], styles['arrow'], classNameArrow, {
970
+ /**
971
+ * changed from dash `no-arrow` to camelcase because of:
972
+ * https://github.com/indooorsman/esbuild-css-modules-plugin/issues/42
973
+ */
974
+ [coreStyles['noArrow']]: noArrow,
975
+ }), style: {
883
976
  ...inlineArrowStyles,
884
977
  background: arrowColor
885
978
  ? `linear-gradient(to right bottom, transparent 50%, ${arrowColor} 50%)`
@@ -892,7 +985,7 @@
892
985
  return React__default["default"].createElement("span", { dangerouslySetInnerHTML: { __html: content } });
893
986
  };
894
987
 
895
- const TooltipController = ({ id, anchorId, anchorSelect, content, html, render, className, classNameArrow, variant = 'dark', place = 'top', offset = 10, wrapper = 'div', children = null, events = ['hover'], openOnClick = false, positionStrategy = 'absolute', middlewares, delayShow = 0, delayHide = 0, float = false, hidden = false, noArrow = false, clickable = false, closeOnEsc = false, closeOnScroll = false, closeOnResize = false, style, position, isOpen, disableStyleInjection = false, border, opacity, arrowColor, setIsOpen, afterShow, afterHide, }) => {
988
+ const TooltipController = ({ id, anchorId, anchorSelect, content, html, render, className, classNameArrow, variant = 'dark', place = 'top', offset = 10, wrapper = 'div', children = null, events = ['hover'], openOnClick = false, positionStrategy = 'absolute', middlewares, delayShow = 0, delayHide = 0, float = false, hidden = false, noArrow = false, clickable = false, closeOnEsc = false, closeOnScroll = false, closeOnResize = false, openEvents, closeEvents, globalCloseEvents, style, position, isOpen, disableStyleInjection = false, border, opacity, arrowColor, setIsOpen, afterShow, afterHide, }) => {
896
989
  const [tooltipContent, setTooltipContent] = React.useState(content);
897
990
  const [tooltipHtml, setTooltipHtml] = React.useState(html);
898
991
  const [tooltipPlace, setTooltipPlace] = React.useState(place);
@@ -1140,6 +1233,9 @@
1140
1233
  closeOnEsc,
1141
1234
  closeOnScroll,
1142
1235
  closeOnResize,
1236
+ openEvents,
1237
+ closeEvents,
1238
+ globalCloseEvents,
1143
1239
  style,
1144
1240
  position,
1145
1241
  isOpen,
@@ -1164,17 +1260,17 @@
1164
1260
  --rt-color-warning: #f0ad4e;
1165
1261
  --rt-color-info: #337ab7;
1166
1262
  --rt-opacity: 0.9;
1167
- --rt-transition-show-delay: 0.15s;
1168
- --rt-transition-closing-delay: 0.15s;
1169
1263
  }
1170
1264
 
1171
1265
  .core-styles-module_tooltip__3vRRp {
1266
+ visibility: hidden;
1172
1267
  position: absolute;
1173
1268
  top: 0;
1174
1269
  left: 0;
1175
1270
  pointer-events: none;
1176
1271
  opacity: 0;
1177
- will-change: opacity;
1272
+ transition: opacity 0.3s ease-out;
1273
+ will-change: opacity, visibility;
1178
1274
  }
1179
1275
 
1180
1276
  .core-styles-module_fixed__pcSol {
@@ -1195,13 +1291,8 @@
1195
1291
  }
1196
1292
 
1197
1293
  .core-styles-module_show__Nt9eE {
1294
+ visibility: visible;
1198
1295
  opacity: var(--rt-opacity);
1199
- transition: opacity var(--rt-transition-show-delay) ease-out;
1200
- }
1201
-
1202
- .core-styles-module_closing__sGnxF {
1203
- opacity: 0;
1204
- transition: opacity var(--rt-transition-closing-delay) ease-in;
1205
1296
  }
1206
1297
 
1207
1298
  `;