react-tooltip 5.15.0-beta.1041.0 → 5.15.0-beta.1045.1

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.
@@ -18,45 +18,36 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
18
18
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
19
19
  var classNames__default = /*#__PURE__*/_interopDefaultLegacy(classNames);
20
20
 
21
- const REACT_TOOLTIP_STYLES_ID = 'react-tooltip-styles';
22
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, default-param-last
23
- function injectStyle(css, id = REACT_TOOLTIP_STYLES_ID, ref) {
24
- if (!ref) {
25
- // eslint-disable-next-line no-param-reassign
26
- ref = {};
27
- }
28
- const { insertAt } = ref;
29
- if (!css || typeof document === 'undefined' || document.getElementById(REACT_TOOLTIP_STYLES_ID)) {
30
- return;
31
- }
32
- const head = document.head || document.getElementsByTagName('head')[0];
33
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
34
- const style = document.createElement('style');
35
- style.id = id;
36
- style.type = 'text/css';
37
- if (insertAt === 'top') {
38
- if (head.firstChild) {
39
- head.insertBefore(style, head.firstChild);
40
- }
41
- else {
42
- head.appendChild(style);
43
- }
44
- }
45
- else {
46
- head.appendChild(style);
47
- }
48
- if (style.styleSheet) {
49
- style.styleSheet.cssText = css;
50
- }
51
- else {
52
- style.appendChild(document.createTextNode(css));
21
+ function styleInject(css, ref) {
22
+ if ( ref === void 0 ) ref = {};
23
+ var insertAt = ref.insertAt;
24
+
25
+ if (!css || typeof document === 'undefined') { return; }
26
+
27
+ var head = document.head || document.getElementsByTagName('head')[0];
28
+ var style = document.createElement('style');
29
+ style.type = 'text/css';
30
+
31
+ if (insertAt === 'top') {
32
+ if (head.firstChild) {
33
+ head.insertBefore(style, head.firstChild);
34
+ } else {
35
+ head.appendChild(style);
53
36
  }
54
- }
55
- function removeStyle(id = REACT_TOOLTIP_STYLES_ID) {
56
- const style = document.getElementById(id);
57
- style === null || style === void 0 ? void 0 : style.remove();
37
+ } else {
38
+ head.appendChild(style);
39
+ }
40
+
41
+ if (style.styleSheet) {
42
+ style.styleSheet.cssText = css;
43
+ } else {
44
+ style.appendChild(document.createTextNode(css));
45
+ }
58
46
  }
59
47
 
48
+ var css_248z$1 = ":root {\n --rt-color-white: #fff;\n --rt-color-dark: #222;\n --rt-color-success: #8dc572;\n --rt-color-error: #be6464;\n --rt-color-warning: #f0ad4e;\n --rt-color-info: #337ab7;\n --rt-opacity: 0.9;\n}\n";
49
+ styleInject(css_248z$1);
50
+
60
51
  /* eslint-disable @typescript-eslint/no-explicit-any */
61
52
  /**
62
53
  * This function debounce the received function
@@ -190,6 +181,30 @@ const TooltipWrapper = ({ tooltipId, children, className, place, content, html,
190
181
 
191
182
  const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;
192
183
 
184
+ const isScrollable = (node) => {
185
+ if (!(node instanceof HTMLElement || node instanceof SVGElement)) {
186
+ return null;
187
+ }
188
+ const style = getComputedStyle(node);
189
+ return ['overflow', 'overflow-x', 'overflow-y'].some((propertyName) => {
190
+ const value = style.getPropertyValue(propertyName);
191
+ return value === 'auto' || value === 'scroll';
192
+ });
193
+ };
194
+ const getScrollParent = (node) => {
195
+ if (!node) {
196
+ return null;
197
+ }
198
+ let currentParent = node.parentElement;
199
+ while (currentParent) {
200
+ if (isScrollable(currentParent)) {
201
+ return currentParent;
202
+ }
203
+ currentParent = currentParent.parentElement;
204
+ }
205
+ return document.scrollingElement || document.documentElement;
206
+ };
207
+
193
208
  const computeTooltipPosition = async ({ elementReference = null, tooltipReference = null, tooltipArrowReference = null, place = 'top', offset: offsetValue = 10, strategy = 'absolute', middlewares = [dom.offset(Number(offsetValue)), dom.flip(), dom.shift({ padding: 5 })], }) => {
194
209
  if (!elementReference) {
195
210
  // elementReference can be null or undefined and we will not compute the position
@@ -237,9 +252,9 @@ const computeTooltipPosition = async ({ elementReference = null, tooltipReferenc
237
252
  });
238
253
  };
239
254
 
240
- 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"};
241
-
242
- var styles = {"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"};
255
+ var css_248z = ".styles-module_tooltip__mnnfp {\n visibility: hidden;\n width: max-content;\n position: absolute;\n top: 0;\n left: 0;\n padding: 8px 16px;\n border-radius: 3px;\n font-size: 90%;\n pointer-events: none;\n opacity: 0;\n transition: opacity 0.3s ease-out;\n will-change: opacity, visibility;\n}\n\n.styles-module_fixed__7ciUi {\n position: fixed;\n}\n\n.styles-module_arrow__K0L3T {\n position: absolute;\n background: inherit;\n width: 8px;\n height: 8px;\n transform: rotate(45deg);\n}\n\n.styles-module_noArrow__T8y2L {\n display: none;\n}\n\n.styles-module_clickable__Bv9o7 {\n pointer-events: auto;\n}\n\n.styles-module_show__2NboJ {\n visibility: visible;\n opacity: var(--rt-opacity);\n}\n\n/** Types variant **/\n.styles-module_dark__xNqje {\n background: var(--rt-color-dark);\n color: var(--rt-color-white);\n}\n\n.styles-module_light__Z6W-X {\n background-color: var(--rt-color-white);\n color: var(--rt-color-dark);\n}\n\n.styles-module_success__A2AKt {\n background-color: var(--rt-color-success);\n color: var(--rt-color-white);\n}\n\n.styles-module_warning__SCK0X {\n background-color: var(--rt-color-warning);\n color: var(--rt-color-white);\n}\n\n.styles-module_error__JvumD {\n background-color: var(--rt-color-error);\n color: var(--rt-color-white);\n}\n\n.styles-module_info__BWdHW {\n background-color: var(--rt-color-info);\n color: var(--rt-color-white);\n}\n";
256
+ var styles = {"tooltip":"styles-module_tooltip__mnnfp","fixed":"styles-module_fixed__7ciUi","arrow":"styles-module_arrow__K0L3T","noArrow":"styles-module_noArrow__T8y2L","clickable":"styles-module_clickable__Bv9o7","show":"styles-module_show__2NboJ","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"};
257
+ styleInject(css_248z);
243
258
 
244
259
  const Tooltip = ({
245
260
  // props
@@ -468,12 +483,6 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, })
468
483
  }
469
484
  handleShow(false);
470
485
  };
471
- const handleEsc = (event) => {
472
- if (event.key !== 'Escape') {
473
- return;
474
- }
475
- handleShow(false);
476
- };
477
486
  // debounce handler to prevent call twice when
478
487
  // mouse enter and focus events being triggered toggether
479
488
  const debouncedHandleShowTooltip = debounce(handleShowTooltip, 50, true);
@@ -488,12 +497,25 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, })
488
497
  if (anchorById) {
489
498
  elementRefs.add({ current: anchorById });
490
499
  }
500
+ const handleScrollResize = () => {
501
+ handleShow(false);
502
+ };
503
+ const anchorScrollParent = getScrollParent(activeAnchor);
504
+ const tooltipScrollParent = getScrollParent(tooltipRef.current);
491
505
  if (closeOnScroll) {
492
- window.addEventListener('scroll', debouncedHandleHideTooltip);
506
+ window.addEventListener('scroll', handleScrollResize);
507
+ anchorScrollParent === null || anchorScrollParent === void 0 ? void 0 : anchorScrollParent.addEventListener('scroll', handleScrollResize);
508
+ tooltipScrollParent === null || tooltipScrollParent === void 0 ? void 0 : tooltipScrollParent.addEventListener('scroll', handleScrollResize);
493
509
  }
494
510
  if (closeOnResize) {
495
- window.addEventListener('resize', debouncedHandleHideTooltip);
511
+ window.addEventListener('resize', handleScrollResize);
496
512
  }
513
+ const handleEsc = (event) => {
514
+ if (event.key !== 'Escape') {
515
+ return;
516
+ }
517
+ handleShow(false);
518
+ };
497
519
  if (closeOnEsc) {
498
520
  window.addEventListener('keydown', handleEsc);
499
521
  }
@@ -531,10 +553,12 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, })
531
553
  return () => {
532
554
  var _a, _b;
533
555
  if (closeOnScroll) {
534
- window.removeEventListener('scroll', debouncedHandleHideTooltip);
556
+ window.removeEventListener('scroll', handleScrollResize);
557
+ anchorScrollParent === null || anchorScrollParent === void 0 ? void 0 : anchorScrollParent.removeEventListener('scroll', handleScrollResize);
558
+ tooltipScrollParent === null || tooltipScrollParent === void 0 ? void 0 : tooltipScrollParent.removeEventListener('scroll', handleScrollResize);
535
559
  }
536
560
  if (closeOnResize) {
537
- window.removeEventListener('resize', debouncedHandleHideTooltip);
561
+ window.removeEventListener('resize', handleScrollResize);
538
562
  }
539
563
  if (shouldOpenOnClick) {
540
564
  window.removeEventListener('click', handleClickOutsideAnchors);
@@ -720,18 +744,18 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, })
720
744
  }
721
745
  }, [id, anchorSelect]);
722
746
  const canShow = !hidden && content && show && Object.keys(inlineStyles).length > 0;
723
- return rendered ? (React__default["default"].createElement(WrapperElement, { id: id, role: "tooltip", className: classNames__default["default"]('react-tooltip', coreStyles['tooltip'], styles[variant], className, `react-tooltip__place-${actualPlacement}`, {
724
- [coreStyles['show']]: canShow,
725
- [coreStyles['fixed']]: positionStrategy === 'fixed',
726
- [coreStyles['clickable']]: clickable,
747
+ return rendered ? (React__default["default"].createElement(WrapperElement, { id: id, role: "tooltip", className: classNames__default["default"]('react-tooltip', styles['tooltip'], styles[variant], className, `react-tooltip__place-${actualPlacement}`, {
748
+ [styles['show']]: canShow,
749
+ [styles['fixed']]: positionStrategy === 'fixed',
750
+ [styles['clickable']]: clickable,
727
751
  }), style: { ...externalStyles, ...inlineStyles }, ref: tooltipRef },
728
752
  content,
729
- React__default["default"].createElement(WrapperElement, { className: classNames__default["default"]('react-tooltip-arrow', coreStyles['arrow'], styles['arrow'], classNameArrow, {
753
+ React__default["default"].createElement(WrapperElement, { className: classNames__default["default"]('react-tooltip-arrow', styles['arrow'], classNameArrow, {
730
754
  /**
731
755
  * changed from dash `no-arrow` to camelcase because of:
732
756
  * https://github.com/indooorsman/esbuild-css-modules-plugin/issues/42
733
757
  */
734
- [coreStyles['noArrow']]: noArrow,
758
+ [styles['noArrow']]: noArrow,
735
759
  }), style: inlineArrowStyles, ref: tooltipArrowRef }))) : null;
736
760
  };
737
761
 
@@ -962,98 +986,7 @@ const TooltipController = ({ id, anchorId, anchorSelect, content, html, render,
962
986
  return React__default["default"].createElement(Tooltip, { ...props });
963
987
  };
964
988
 
965
- // those content will be replaced in build time with the `react-tooltip.css` builded content
966
- const TooltipCoreStyles = `:root {
967
- --rt-color-white: #fff;
968
- --rt-color-dark: #222;
969
- --rt-color-success: #8dc572;
970
- --rt-color-error: #be6464;
971
- --rt-color-warning: #f0ad4e;
972
- --rt-color-info: #337ab7;
973
- --rt-opacity: 0.9;
974
- }
975
-
976
- .core-styles-module_tooltip__3vRRp {
977
- visibility: hidden;
978
- width: max-content;
979
- position: absolute;
980
- top: 0;
981
- left: 0;
982
- padding: 8px 16px;
983
- border-radius: 3px;
984
- font-size: 90%;
985
- pointer-events: none;
986
- opacity: 0;
987
- transition: opacity 0.3s ease-out;
988
- will-change: opacity, visibility;
989
- }
990
-
991
- .core-styles-module_fixed__pcSol {
992
- position: fixed;
993
- }
994
-
995
- .core-styles-module_arrow__cvMwQ {
996
- position: absolute;
997
- background: inherit;
998
- }
999
-
1000
- .core-styles-module_noArrow__xock6 {
1001
- display: none;
1002
- }
1003
-
1004
- .core-styles-module_clickable__ZuTTB {
1005
- pointer-events: auto;
1006
- }
1007
-
1008
- .core-styles-module_show__Nt9eE {
1009
- visibility: visible;
1010
- opacity: var(--rt-opacity);
1011
- }
1012
-
1013
- `;
1014
- const TooltipStyles = `
1015
-
1016
- .styles-module_arrow__K0L3T {
1017
- width: 8px;
1018
- height: 8px;
1019
- transform: rotate(45deg);
1020
- }
1021
-
1022
- /** Types variant **/
1023
- .styles-module_dark__xNqje {
1024
- background: var(--rt-color-dark);
1025
- color: var(--rt-color-white);
1026
- }
1027
-
1028
- .styles-module_light__Z6W-X {
1029
- background-color: var(--rt-color-white);
1030
- color: var(--rt-color-dark);
1031
- }
1032
-
1033
- .styles-module_success__A2AKt {
1034
- background-color: var(--rt-color-success);
1035
- color: var(--rt-color-white);
1036
- }
1037
-
1038
- .styles-module_warning__SCK0X {
1039
- background-color: var(--rt-color-warning);
1040
- color: var(--rt-color-white);
1041
- }
1042
-
1043
- .styles-module_error__JvumD {
1044
- background-color: var(--rt-color-error);
1045
- color: var(--rt-color-white);
1046
- }
1047
-
1048
- .styles-module_info__BWdHW {
1049
- background-color: var(--rt-color-info);
1050
- color: var(--rt-color-white);
1051
- }
1052
- `;
1053
- injectStyle(TooltipCoreStyles, 'react-tooltip-core-styles');
1054
- injectStyle(TooltipStyles);
1055
-
1056
989
  exports.Tooltip = TooltipController;
1057
990
  exports.TooltipProvider = TooltipProvider;
1058
991
  exports.TooltipWrapper = TooltipWrapper;
1059
- exports.removeStyle = removeStyle;
992
+ //# sourceMappingURL=react-tooltip.cjs.map