react-tooltip 6.0.0-beta.1179.rc.0 → 6.0.0-beta.1179.rc.2

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.
package/README.md CHANGED
@@ -54,9 +54,9 @@ React Tooltip is proud to be sponsored by [Frigade](https://frigade.com/?source=
54
54
 
55
55
  #### Silver Sponsors ✪
56
56
 
57
- <a href="https://dopt.com/?source=react-tooltip">
58
- <img alt="Dopt" style="height: 200px; width: 200px;" src="docs/static/img/sponsors/dopt.png" />
59
- </a>
57
+ <!-- <a href="#">
58
+ <img alt="Slot" style="height: 200px; width: 200px;" src="docs/static/img/sponsors/slot.png" />
59
+ </a> -->
60
60
 
61
61
  ## Powered by
62
62
 
@@ -44,11 +44,7 @@ function injectStyle({ css, id = REACT_TOOLTIP_BASE_STYLES_ID, type = 'base', re
44
44
  }
45
45
  const { insertAt } = ref;
46
46
  if (document.getElementById(id)) {
47
- // this should never happen because of `injected[type]`
48
- {
49
- // eslint-disable-next-line no-console
50
- console.warn(`[react-tooltip] Element with id '${id}' already exists. Call \`removeStyle()\` first`);
51
- }
47
+ // this could happen in cases the tooltip is imported by multiple js modules
52
48
  return;
53
49
  }
54
50
  const head = document.head || document.getElementsByTagName('head')[0];
@@ -152,11 +148,6 @@ const computeTooltipPosition = async ({ elementReference = null, tooltipReferenc
152
148
  });
153
149
  };
154
150
 
155
- const cssSupports = (property, value) => {
156
- const hasCssSupports = 'CSS' in window && 'supports' in window.CSS;
157
- return hasCssSupports ? window.CSS.supports(property, value) : true;
158
- };
159
-
160
151
  const cssTimeToMs = (time) => {
161
152
  const match = time.match(/^([\d.]+)(m?s)$/);
162
153
  if (!match) {
@@ -178,11 +169,8 @@ const debounce = (func, wait, immediate) => {
178
169
  const debounced = function debounced(...args) {
179
170
  const later = () => {
180
171
  timeout = null;
181
- if (!immediate) {
182
- func.apply(this, args);
183
- }
184
172
  };
185
- if (immediate && !timeout) {
173
+ if (!timeout) {
186
174
  /**
187
175
  * there's no need to clear the timeout
188
176
  * since we expect it to resolve and set `timeout = null`
@@ -190,12 +178,6 @@ const debounce = (func, wait, immediate) => {
190
178
  func.apply(this, args);
191
179
  timeout = setTimeout(later, wait);
192
180
  }
193
- if (!immediate) {
194
- if (timeout) {
195
- clearTimeout(timeout);
196
- }
197
- timeout = setTimeout(later, wait);
198
- }
199
181
  };
200
182
  debounced.cancel = () => {
201
183
  /* c8 ignore start */
@@ -262,6 +244,14 @@ const getScrollParent = (node) => {
262
244
 
263
245
  const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;
264
246
 
247
+ const clearTimeoutRef = (ref) => {
248
+ if (ref.current) {
249
+ clearTimeout(ref.current);
250
+ // eslint-disable-next-line no-param-reassign
251
+ ref.current = null;
252
+ }
253
+ };
254
+
265
255
  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"};
266
256
 
267
257
  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"};
@@ -344,9 +334,7 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
344
334
  if (show === wasShowing.current) {
345
335
  return;
346
336
  }
347
- if (missedTransitionTimerRef.current) {
348
- clearTimeout(missedTransitionTimerRef.current);
349
- }
337
+ clearTimeoutRef(missedTransitionTimerRef);
350
338
  wasShowing.current = show;
351
339
  if (show) {
352
340
  afterShow === null || afterShow === void 0 ? void 0 : afterShow();
@@ -564,8 +552,8 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
564
552
  };
565
553
  // debounce handler to prevent call twice when
566
554
  // mouse enter and focus events being triggered toggether
567
- const internalDebouncedHandleShowTooltip = debounce(handleShowTooltip, 50, true);
568
- const internalDebouncedHandleHideTooltip = debounce(handleHideTooltip, 50, true);
555
+ const internalDebouncedHandleShowTooltip = debounce(handleShowTooltip, 50);
556
+ const internalDebouncedHandleHideTooltip = debounce(handleHideTooltip, 50);
569
557
  // If either of the functions is called while the other is still debounced,
570
558
  // reset the timeout. Otherwise if there is a sub-50ms (leave A, enter B, leave B)
571
559
  // sequence of events, the tooltip will stay open because the hide debounce
@@ -697,7 +685,7 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
697
685
  }
698
686
  handleHideTooltip();
699
687
  };
700
- const regularEvents = ['mouseenter', 'mouseleave', 'focus', 'blur'];
688
+ const regularEvents = ['mouseover', 'mouseout', 'mouseenter', 'mouseleave', 'focus', 'blur'];
701
689
  const clickEvents = ['click', 'dblclick', 'mousedown', 'mouseup'];
702
690
  Object.entries(actualOpenEvents).forEach(([event, enabled]) => {
703
691
  if (!enabled) {
@@ -841,12 +829,8 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
841
829
  setRendered(false);
842
830
  handleShow(false);
843
831
  setActiveAnchor(null);
844
- if (tooltipShowDelayTimerRef.current) {
845
- clearTimeout(tooltipShowDelayTimerRef.current);
846
- }
847
- if (tooltipHideDelayTimerRef.current) {
848
- clearTimeout(tooltipHideDelayTimerRef.current);
849
- }
832
+ clearTimeoutRef(tooltipShowDelayTimerRef);
833
+ clearTimeoutRef(tooltipHideDelayTimerRef);
850
834
  return true;
851
835
  }
852
836
  return false;
@@ -965,12 +949,8 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
965
949
  handleShow(true);
966
950
  }
967
951
  return () => {
968
- if (tooltipShowDelayTimerRef.current) {
969
- clearTimeout(tooltipShowDelayTimerRef.current);
970
- }
971
- if (tooltipHideDelayTimerRef.current) {
972
- clearTimeout(tooltipHideDelayTimerRef.current);
973
- }
952
+ clearTimeoutRef(tooltipShowDelayTimerRef);
953
+ clearTimeoutRef(tooltipHideDelayTimerRef);
974
954
  };
975
955
  }, [defaultIsOpen, handleShow]);
976
956
  React.useEffect(() => {
@@ -993,7 +973,11 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
993
973
  }, [id, anchorSelect, imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.anchorSelect]);
994
974
  React.useEffect(() => {
995
975
  if (tooltipShowDelayTimerRef.current) {
996
- clearTimeout(tooltipShowDelayTimerRef.current);
976
+ /**
977
+ * if the delay changes while the tooltip is waiting to show,
978
+ * reset the timer with the new delay
979
+ */
980
+ clearTimeoutRef(tooltipShowDelayTimerRef);
997
981
  handleShowTooltipDelayed(delayShow);
998
982
  }
999
983
  }, [delayShow, handleShowTooltipDelayed]);
@@ -1034,9 +1018,7 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
1034
1018
  isOpen: Boolean(rendered && !hidden && actualContent && canShow),
1035
1019
  }));
1036
1020
  return rendered && !hidden && actualContent ? (React.createElement(WrapperElement, { id: id, role: role, className: clsx('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) => {
1037
- if (missedTransitionTimerRef.current) {
1038
- clearTimeout(missedTransitionTimerRef.current);
1039
- }
1021
+ clearTimeoutRef(missedTransitionTimerRef);
1040
1022
  if (show || event.propertyName !== 'opacity') {
1041
1023
  return;
1042
1024
  }
@@ -1226,18 +1208,10 @@ const TooltipController = React.forwardRef(({ id, anchorSelect, content, render,
1226
1208
  // eslint-disable-next-line no-console
1227
1209
  console.warn('[react-tooltip] Do not set `style.border`. Use `border` prop instead.');
1228
1210
  }
1229
- if (border && !cssSupports('border', `${border}`)) {
1230
- // eslint-disable-next-line no-console
1231
- console.warn(`[react-tooltip] "${border}" is not a valid \`border\`.`);
1232
- }
1233
1211
  if (style === null || style === void 0 ? void 0 : style.opacity) {
1234
1212
  // eslint-disable-next-line no-console
1235
1213
  console.warn('[react-tooltip] Do not set `style.opacity`. Use `opacity` prop instead.');
1236
1214
  }
1237
- if (opacity && !cssSupports('opacity', `${opacity}`)) {
1238
- // eslint-disable-next-line no-console
1239
- console.warn(`[react-tooltip] "${opacity}" is not a valid \`opacity\`.`);
1240
- }
1241
1215
  }, [border, opacity, style === null || style === void 0 ? void 0 : style.border, style === null || style === void 0 ? void 0 : style.opacity]);
1242
1216
  /**
1243
1217
  * content priority: children < render or content < html