react-tooltip 5.22.0-beta.1106.0 → 5.22.0-beta.1109.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.
@@ -6,6 +6,4 @@
6
6
  --rt-color-warning: #f0ad4e;
7
7
  --rt-color-info: #337ab7;
8
8
  --rt-opacity: 0.9;
9
- --rt-transition-show-delay: 0.15s;
10
- --rt-transition-closing-delay: 0.15s;
11
9
  }
@@ -327,15 +327,16 @@ const computeTooltipPosition = async ({ elementReference = null, tooltipReferenc
327
327
  });
328
328
  };
329
329
 
330
- 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"};
330
+ 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"};
331
331
 
332
332
  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"};
333
333
 
334
334
  const Tooltip = ({
335
335
  // props
336
- 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,
336
+ forwardRef, 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,
337
337
  // props handled by controller
338
338
  content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, border, opacity, arrowColor, }) => {
339
+ var _a;
339
340
  const tooltipRef = React.useRef(null);
340
341
  const tooltipArrowRef = React.useRef(null);
341
342
  const tooltipShowDelayTimerRef = React.useRef(null);
@@ -345,6 +346,7 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
345
346
  const [inlineArrowStyles, setInlineArrowStyles] = React.useState({});
346
347
  const [show, setShow] = React.useState(false);
347
348
  const [rendered, setRendered] = React.useState(false);
349
+ const [imperativeOptions, setImperativeOptions] = React.useState(null);
348
350
  const wasShowing = React.useRef(false);
349
351
  const lastFloatPosition = React.useRef(null);
350
352
  /**
@@ -366,6 +368,23 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
366
368
  mounted.current = false;
367
369
  };
368
370
  }, []);
371
+ React.useEffect(() => {
372
+ if (!show) {
373
+ /**
374
+ * this fixes weird behavior when switching between two anchor elements very quickly
375
+ * remove the timeout and switch quickly between two adjancent anchor elements to see it
376
+ *
377
+ * in practice, this means the tooltip is not immediately removed from the DOM on hide
378
+ */
379
+ const timeout = setTimeout(() => {
380
+ setRendered(false);
381
+ }, 150);
382
+ return () => {
383
+ clearTimeout(timeout);
384
+ };
385
+ }
386
+ return () => null;
387
+ }, [show]);
369
388
  const handleShow = (value) => {
370
389
  if (!mounted.current) {
371
390
  return;
@@ -414,6 +433,7 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
414
433
  afterShow === null || afterShow === void 0 ? void 0 : afterShow();
415
434
  }
416
435
  else {
436
+ setImperativeOptions(null);
417
437
  afterHide === null || afterHide === void 0 ? void 0 : afterHide();
418
438
  }
419
439
  }, [show]);
@@ -532,6 +552,9 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
532
552
  };
533
553
  const handleClickOutsideAnchors = (event) => {
534
554
  var _a;
555
+ if (!show) {
556
+ return;
557
+ }
535
558
  const anchorById = document.querySelector(`[id='${anchorId}']`);
536
559
  const anchors = [anchorById, ...anchorsBySelect];
537
560
  if (anchors.some((anchor) => anchor === null || anchor === void 0 ? void 0 : anchor.contains(event.target))) {
@@ -550,9 +573,11 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
550
573
  const debouncedHandleShowTooltip = debounce(handleShowTooltip, 50, true);
551
574
  const debouncedHandleHideTooltip = debounce(handleHideTooltip, 50, true);
552
575
  const updateTooltipPosition = React.useCallback(() => {
553
- if (position) {
576
+ var _a;
577
+ const actualPosition = (_a = imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.position) !== null && _a !== void 0 ? _a : position;
578
+ if (actualPosition) {
554
579
  // if `position` is set, override regular and `float` positioning
555
- handleTooltipPosition(position);
580
+ handleTooltipPosition(actualPosition);
556
581
  return;
557
582
  }
558
583
  if (float) {
@@ -603,6 +628,7 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
603
628
  offset,
604
629
  positionStrategy,
605
630
  position,
631
+ imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.position,
606
632
  float,
607
633
  ]);
608
634
  React.useEffect(() => {
@@ -720,7 +746,8 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
720
746
  events,
721
747
  ]);
722
748
  React.useEffect(() => {
723
- let selector = anchorSelect !== null && anchorSelect !== void 0 ? anchorSelect : '';
749
+ var _a, _b;
750
+ let selector = (_b = (_a = imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.anchorSelect) !== null && _a !== void 0 ? _a : anchorSelect) !== null && _b !== void 0 ? _b : '';
724
751
  if (!selector && id) {
725
752
  selector = `[data-tooltip-id='${id}']`;
726
753
  }
@@ -809,7 +836,7 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
809
836
  return () => {
810
837
  documentObserver.disconnect();
811
838
  };
812
- }, [id, anchorSelect, activeAnchor]);
839
+ }, [id, anchorSelect, imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.anchorSelect, activeAnchor]);
813
840
  React.useEffect(() => {
814
841
  updateTooltipPosition();
815
842
  }, [updateTooltipPosition]);
@@ -849,7 +876,8 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
849
876
  };
850
877
  }, []);
851
878
  React.useEffect(() => {
852
- let selector = anchorSelect;
879
+ var _a;
880
+ let selector = (_a = imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.anchorSelect) !== null && _a !== void 0 ? _a : anchorSelect;
853
881
  if (!selector && id) {
854
882
  selector = `[data-tooltip-id='${id}']`;
855
883
  }
@@ -860,28 +888,55 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
860
888
  const anchors = Array.from(document.querySelectorAll(selector));
861
889
  setAnchorsBySelect(anchors);
862
890
  }
863
- catch (_a) {
891
+ catch (_b) {
864
892
  // warning was already issued in the controller
865
893
  setAnchorsBySelect([]);
866
894
  }
867
- }, [id, anchorSelect]);
868
- const canShow = !hidden && content && show && Object.keys(inlineStyles).length > 0;
869
- 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) => {
870
- /**
871
- * @warning if `--rt-transition-closing-delay` is set to 0,
872
- * the tooltip will be stuck (but not visible) on the DOM
873
- */
874
- if (show || event.propertyName !== 'opacity') {
875
- return;
895
+ }, [id, anchorSelect, imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.anchorSelect]);
896
+ const actualContent = (_a = imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.content) !== null && _a !== void 0 ? _a : content;
897
+ const canShow = Boolean(!hidden && actualContent && show && Object.keys(inlineStyles).length > 0);
898
+ React.useImperativeHandle(forwardRef, () => ({
899
+ open: (options) => {
900
+ if (options === null || options === void 0 ? void 0 : options.anchorSelect) {
901
+ try {
902
+ document.querySelector(options.anchorSelect);
903
+ }
904
+ catch (_a) {
905
+ {
906
+ // eslint-disable-next-line no-console
907
+ console.warn(`[react-tooltip] "${options.anchorSelect}" is not a valid CSS selector`);
908
+ }
909
+ return;
910
+ }
876
911
  }
877
- setRendered(false);
878
- }, style: {
912
+ setImperativeOptions(options !== null && options !== void 0 ? options : null);
913
+ handleShow(true);
914
+ },
915
+ close: () => {
916
+ handleShow(false);
917
+ },
918
+ activeAnchor,
919
+ place: actualPlacement,
920
+ isOpen: rendered && canShow,
921
+ }));
922
+ 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}`, {
923
+ 'react-tooltip__show': canShow,
924
+ [coreStyles['show']]: canShow,
925
+ [coreStyles['fixed']]: positionStrategy === 'fixed',
926
+ [coreStyles['clickable']]: clickable,
927
+ }), style: {
879
928
  ...externalStyles,
880
929
  ...inlineStyles,
881
930
  opacity: opacity !== undefined && canShow ? opacity : undefined,
882
931
  }, ref: tooltipRef },
883
- content,
884
- React__default["default"].createElement(WrapperElement, { className: classNames__default["default"]('react-tooltip-arrow', coreStyles['arrow'], styles['arrow'], classNameArrow, noArrow && coreStyles['noArrow']), style: {
932
+ actualContent,
933
+ React__default["default"].createElement(WrapperElement, { className: classNames__default["default"]('react-tooltip-arrow', coreStyles['arrow'], styles['arrow'], classNameArrow, {
934
+ /**
935
+ * changed from dash `no-arrow` to camelcase because of:
936
+ * https://github.com/indooorsman/esbuild-css-modules-plugin/issues/42
937
+ */
938
+ [coreStyles['noArrow']]: noArrow,
939
+ }), style: {
885
940
  ...inlineArrowStyles,
886
941
  background: arrowColor
887
942
  ? `linear-gradient(to right bottom, transparent 50%, ${arrowColor} 50%)`
@@ -894,7 +949,7 @@ const TooltipContent = ({ content }) => {
894
949
  return React__default["default"].createElement("span", { dangerouslySetInnerHTML: { __html: content } });
895
950
  };
896
951
 
897
- 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, }) => {
952
+ const TooltipController = React__default["default"].forwardRef(({ 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, }, ref) => {
898
953
  const [tooltipContent, setTooltipContent] = React.useState(content);
899
954
  const [tooltipHtml, setTooltipHtml] = React.useState(html);
900
955
  const [tooltipPlace, setTooltipPlace] = React.useState(place);
@@ -1118,6 +1173,7 @@ const TooltipController = ({ id, anchorId, anchorSelect, content, html, render,
1118
1173
  renderedContent = React__default["default"].createElement(TooltipContent, { content: tooltipHtml });
1119
1174
  }
1120
1175
  const props = {
1176
+ forwardRef: ref,
1121
1177
  id,
1122
1178
  anchorId,
1123
1179
  anchorSelect,
@@ -1155,7 +1211,7 @@ const TooltipController = ({ id, anchorId, anchorSelect, content, html, render,
1155
1211
  setActiveAnchor: (anchor) => setActiveAnchor(anchor),
1156
1212
  };
1157
1213
  return React__default["default"].createElement(Tooltip, { ...props });
1158
- };
1214
+ });
1159
1215
 
1160
1216
  // those content will be replaced in build time with the `react-tooltip.css` builded content
1161
1217
  const TooltipCoreStyles = `:root {
@@ -1166,17 +1222,17 @@ const TooltipCoreStyles = `:root {
1166
1222
  --rt-color-warning: #f0ad4e;
1167
1223
  --rt-color-info: #337ab7;
1168
1224
  --rt-opacity: 0.9;
1169
- --rt-transition-show-delay: 0.15s;
1170
- --rt-transition-closing-delay: 0.15s;
1171
1225
  }
1172
1226
 
1173
1227
  .core-styles-module_tooltip__3vRRp {
1228
+ visibility: hidden;
1174
1229
  position: absolute;
1175
1230
  top: 0;
1176
1231
  left: 0;
1177
1232
  pointer-events: none;
1178
1233
  opacity: 0;
1179
- will-change: opacity;
1234
+ transition: opacity 0.3s ease-out;
1235
+ will-change: opacity, visibility;
1180
1236
  }
1181
1237
 
1182
1238
  .core-styles-module_fixed__pcSol {
@@ -1197,13 +1253,8 @@ const TooltipCoreStyles = `:root {
1197
1253
  }
1198
1254
 
1199
1255
  .core-styles-module_show__Nt9eE {
1256
+ visibility: visible;
1200
1257
  opacity: var(--rt-opacity);
1201
- transition: opacity var(--rt-transition-show-delay) ease-out;
1202
- }
1203
-
1204
- .core-styles-module_closing__sGnxF {
1205
- opacity: 0;
1206
- transition: opacity var(--rt-transition-closing-delay) ease-in;
1207
1258
  }
1208
1259
 
1209
1260
  `;