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.
@@ -325,15 +325,16 @@
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
+ 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,
335
335
  // props handled by controller
336
336
  content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, border, opacity, arrowColor, }) => {
337
+ var _a;
337
338
  const tooltipRef = React.useRef(null);
338
339
  const tooltipArrowRef = React.useRef(null);
339
340
  const tooltipShowDelayTimerRef = React.useRef(null);
@@ -343,6 +344,7 @@
343
344
  const [inlineArrowStyles, setInlineArrowStyles] = React.useState({});
344
345
  const [show, setShow] = React.useState(false);
345
346
  const [rendered, setRendered] = React.useState(false);
347
+ const [imperativeOptions, setImperativeOptions] = React.useState(null);
346
348
  const wasShowing = React.useRef(false);
347
349
  const lastFloatPosition = React.useRef(null);
348
350
  /**
@@ -364,6 +366,23 @@
364
366
  mounted.current = false;
365
367
  };
366
368
  }, []);
369
+ React.useEffect(() => {
370
+ if (!show) {
371
+ /**
372
+ * this fixes weird behavior when switching between two anchor elements very quickly
373
+ * remove the timeout and switch quickly between two adjancent anchor elements to see it
374
+ *
375
+ * in practice, this means the tooltip is not immediately removed from the DOM on hide
376
+ */
377
+ const timeout = setTimeout(() => {
378
+ setRendered(false);
379
+ }, 150);
380
+ return () => {
381
+ clearTimeout(timeout);
382
+ };
383
+ }
384
+ return () => null;
385
+ }, [show]);
367
386
  const handleShow = (value) => {
368
387
  if (!mounted.current) {
369
388
  return;
@@ -412,6 +431,7 @@
412
431
  afterShow === null || afterShow === void 0 ? void 0 : afterShow();
413
432
  }
414
433
  else {
434
+ setImperativeOptions(null);
415
435
  afterHide === null || afterHide === void 0 ? void 0 : afterHide();
416
436
  }
417
437
  }, [show]);
@@ -530,6 +550,9 @@
530
550
  };
531
551
  const handleClickOutsideAnchors = (event) => {
532
552
  var _a;
553
+ if (!show) {
554
+ return;
555
+ }
533
556
  const anchorById = document.querySelector(`[id='${anchorId}']`);
534
557
  const anchors = [anchorById, ...anchorsBySelect];
535
558
  if (anchors.some((anchor) => anchor === null || anchor === void 0 ? void 0 : anchor.contains(event.target))) {
@@ -548,9 +571,11 @@
548
571
  const debouncedHandleShowTooltip = debounce(handleShowTooltip, 50, true);
549
572
  const debouncedHandleHideTooltip = debounce(handleHideTooltip, 50, true);
550
573
  const updateTooltipPosition = React.useCallback(() => {
551
- if (position) {
574
+ var _a;
575
+ const actualPosition = (_a = imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.position) !== null && _a !== void 0 ? _a : position;
576
+ if (actualPosition) {
552
577
  // if `position` is set, override regular and `float` positioning
553
- handleTooltipPosition(position);
578
+ handleTooltipPosition(actualPosition);
554
579
  return;
555
580
  }
556
581
  if (float) {
@@ -601,6 +626,7 @@
601
626
  offset,
602
627
  positionStrategy,
603
628
  position,
629
+ imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.position,
604
630
  float,
605
631
  ]);
606
632
  React.useEffect(() => {
@@ -718,7 +744,8 @@
718
744
  events,
719
745
  ]);
720
746
  React.useEffect(() => {
721
- let selector = anchorSelect !== null && anchorSelect !== void 0 ? anchorSelect : '';
747
+ var _a, _b;
748
+ let selector = (_b = (_a = imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.anchorSelect) !== null && _a !== void 0 ? _a : anchorSelect) !== null && _b !== void 0 ? _b : '';
722
749
  if (!selector && id) {
723
750
  selector = `[data-tooltip-id='${id}']`;
724
751
  }
@@ -807,7 +834,7 @@
807
834
  return () => {
808
835
  documentObserver.disconnect();
809
836
  };
810
- }, [id, anchorSelect, activeAnchor]);
837
+ }, [id, anchorSelect, imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.anchorSelect, activeAnchor]);
811
838
  React.useEffect(() => {
812
839
  updateTooltipPosition();
813
840
  }, [updateTooltipPosition]);
@@ -847,7 +874,8 @@
847
874
  };
848
875
  }, []);
849
876
  React.useEffect(() => {
850
- let selector = anchorSelect;
877
+ var _a;
878
+ let selector = (_a = imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.anchorSelect) !== null && _a !== void 0 ? _a : anchorSelect;
851
879
  if (!selector && id) {
852
880
  selector = `[data-tooltip-id='${id}']`;
853
881
  }
@@ -858,28 +886,55 @@
858
886
  const anchors = Array.from(document.querySelectorAll(selector));
859
887
  setAnchorsBySelect(anchors);
860
888
  }
861
- catch (_a) {
889
+ catch (_b) {
862
890
  // warning was already issued in the controller
863
891
  setAnchorsBySelect([]);
864
892
  }
865
- }, [id, anchorSelect]);
866
- 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;
893
+ }, [id, anchorSelect, imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.anchorSelect]);
894
+ const actualContent = (_a = imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.content) !== null && _a !== void 0 ? _a : content;
895
+ const canShow = Boolean(!hidden && actualContent && show && Object.keys(inlineStyles).length > 0);
896
+ React.useImperativeHandle(forwardRef, () => ({
897
+ open: (options) => {
898
+ if (options === null || options === void 0 ? void 0 : options.anchorSelect) {
899
+ try {
900
+ document.querySelector(options.anchorSelect);
901
+ }
902
+ catch (_a) {
903
+ {
904
+ // eslint-disable-next-line no-console
905
+ console.warn(`[react-tooltip] "${options.anchorSelect}" is not a valid CSS selector`);
906
+ }
907
+ return;
908
+ }
874
909
  }
875
- setRendered(false);
876
- }, style: {
910
+ setImperativeOptions(options !== null && options !== void 0 ? options : null);
911
+ handleShow(true);
912
+ },
913
+ close: () => {
914
+ handleShow(false);
915
+ },
916
+ activeAnchor,
917
+ place: actualPlacement,
918
+ isOpen: rendered && canShow,
919
+ }));
920
+ 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}`, {
921
+ 'react-tooltip__show': canShow,
922
+ [coreStyles['show']]: canShow,
923
+ [coreStyles['fixed']]: positionStrategy === 'fixed',
924
+ [coreStyles['clickable']]: clickable,
925
+ }), style: {
877
926
  ...externalStyles,
878
927
  ...inlineStyles,
879
928
  opacity: opacity !== undefined && canShow ? opacity : undefined,
880
929
  }, ref: tooltipRef },
881
- content,
882
- React__default["default"].createElement(WrapperElement, { className: classNames__default["default"]('react-tooltip-arrow', coreStyles['arrow'], styles['arrow'], classNameArrow, noArrow && coreStyles['noArrow']), style: {
930
+ actualContent,
931
+ React__default["default"].createElement(WrapperElement, { className: classNames__default["default"]('react-tooltip-arrow', coreStyles['arrow'], styles['arrow'], classNameArrow, {
932
+ /**
933
+ * changed from dash `no-arrow` to camelcase because of:
934
+ * https://github.com/indooorsman/esbuild-css-modules-plugin/issues/42
935
+ */
936
+ [coreStyles['noArrow']]: noArrow,
937
+ }), style: {
883
938
  ...inlineArrowStyles,
884
939
  background: arrowColor
885
940
  ? `linear-gradient(to right bottom, transparent 50%, ${arrowColor} 50%)`
@@ -892,7 +947,7 @@
892
947
  return React__default["default"].createElement("span", { dangerouslySetInnerHTML: { __html: content } });
893
948
  };
894
949
 
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, }) => {
950
+ 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) => {
896
951
  const [tooltipContent, setTooltipContent] = React.useState(content);
897
952
  const [tooltipHtml, setTooltipHtml] = React.useState(html);
898
953
  const [tooltipPlace, setTooltipPlace] = React.useState(place);
@@ -1116,6 +1171,7 @@
1116
1171
  renderedContent = React__default["default"].createElement(TooltipContent, { content: tooltipHtml });
1117
1172
  }
1118
1173
  const props = {
1174
+ forwardRef: ref,
1119
1175
  id,
1120
1176
  anchorId,
1121
1177
  anchorSelect,
@@ -1153,7 +1209,7 @@
1153
1209
  setActiveAnchor: (anchor) => setActiveAnchor(anchor),
1154
1210
  };
1155
1211
  return React__default["default"].createElement(Tooltip, { ...props });
1156
- };
1212
+ });
1157
1213
 
1158
1214
  // those content will be replaced in build time with the `react-tooltip.css` builded content
1159
1215
  const TooltipCoreStyles = `:root {
@@ -1164,17 +1220,17 @@
1164
1220
  --rt-color-warning: #f0ad4e;
1165
1221
  --rt-color-info: #337ab7;
1166
1222
  --rt-opacity: 0.9;
1167
- --rt-transition-show-delay: 0.15s;
1168
- --rt-transition-closing-delay: 0.15s;
1169
1223
  }
1170
1224
 
1171
1225
  .core-styles-module_tooltip__3vRRp {
1226
+ visibility: hidden;
1172
1227
  position: absolute;
1173
1228
  top: 0;
1174
1229
  left: 0;
1175
1230
  pointer-events: none;
1176
1231
  opacity: 0;
1177
- will-change: opacity;
1232
+ transition: opacity 0.3s ease-out;
1233
+ will-change: opacity, visibility;
1178
1234
  }
1179
1235
 
1180
1236
  .core-styles-module_fixed__pcSol {
@@ -1195,13 +1251,8 @@
1195
1251
  }
1196
1252
 
1197
1253
  .core-styles-module_show__Nt9eE {
1254
+ visibility: visible;
1198
1255
  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
1256
  }
1206
1257
 
1207
1258
  `;