react-tooltip 5.10.0-beta.0 → 5.10.0-beta.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.
@@ -109,9 +109,16 @@
109
109
  };
110
110
  var debounce_default = debounce;
111
111
 
112
+ // src/components/TooltipContent/TooltipContent.tsx
113
+ var import_jsx_runtime = __require("react/jsx-runtime");
114
+ var TooltipContent = ({ content }) => {
115
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { dangerouslySetInnerHTML: { __html: content } });
116
+ };
117
+ var TooltipContent_default = TooltipContent;
118
+
112
119
  // src/components/TooltipProvider/TooltipProvider.tsx
113
120
  var import_react = __require("react");
114
- var import_jsx_runtime = __require("react/jsx-runtime");
121
+ var import_jsx_runtime2 = __require("react/jsx-runtime");
115
122
  var DEFAULT_TOOLTIP_ID = "DEFAULT_TOOLTIP_ID";
116
123
  var DEFAULT_CONTEXT_DATA = {
117
124
  anchorRefs: /* @__PURE__ */ new Set(),
@@ -179,7 +186,7 @@
179
186
  getTooltipData
180
187
  };
181
188
  }, [getTooltipData]);
182
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TooltipContext.Provider, { value: context, children });
189
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(TooltipContext.Provider, { value: context, children });
183
190
  };
184
191
  function useTooltip(tooltipId = DEFAULT_TOOLTIP_ID) {
185
192
  return (0, import_react.useContext)(TooltipContext).getTooltipData(tooltipId);
@@ -189,7 +196,7 @@
189
196
  // src/components/TooltipProvider/TooltipWrapper.tsx
190
197
  var import_react2 = __require("react");
191
198
  var import_classnames = __toESM(require_classnames());
192
- var import_jsx_runtime2 = __require("react/jsx-runtime");
199
+ var import_jsx_runtime3 = __require("react/jsx-runtime");
193
200
  var TooltipWrapper = ({
194
201
  tooltipId,
195
202
  children,
@@ -213,7 +220,7 @@
213
220
  detach(anchorRef);
214
221
  };
215
222
  }, []);
216
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
223
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
217
224
  "span",
218
225
  {
219
226
  ref: anchorRef,
@@ -705,7 +712,7 @@
705
712
  var styles_module_default = { "arrow": "react-tooltip__arrow_KtSkBq", "clickable": "react-tooltip__clickable_KtSkBq", "dark": "react-tooltip__dark_KtSkBq", "error": "react-tooltip__error_KtSkBq", "fixed": "react-tooltip__fixed_KtSkBq", "info": "react-tooltip__info_KtSkBq", "light": "react-tooltip__light_KtSkBq", "noArrow": "react-tooltip__no-arrow_KtSkBq", "show": "react-tooltip__show_KtSkBq", "success": "react-tooltip__success_KtSkBq", "tooltip": "react-tooltip__tooltip_KtSkBq", "warning": "react-tooltip__warning_KtSkBq" };
706
713
 
707
714
  // src/components/Tooltip/Tooltip.tsx
708
- var import_jsx_runtime3 = __require("react/jsx-runtime");
715
+ var import_jsx_runtime4 = __require("react/jsx-runtime");
709
716
  var Tooltip = ({
710
717
  // props
711
718
  id,
@@ -717,9 +724,11 @@
717
724
  place = "top",
718
725
  offset = 10,
719
726
  events = ["hover"],
727
+ openOnClick = false,
720
728
  positionStrategy = "absolute",
721
729
  middlewares,
722
730
  wrapper: WrapperElement,
731
+ children = null,
723
732
  delayShow = 0,
724
733
  delayHide = 0,
725
734
  float = false,
@@ -732,6 +741,7 @@
732
741
  afterHide,
733
742
  // props handled by controller
734
743
  content,
744
+ html,
735
745
  isOpen,
736
746
  setIsOpen,
737
747
  activeAnchor,
@@ -752,6 +762,7 @@
752
762
  const hoveringTooltip = (0, import_react4.useRef)(false);
753
763
  const [anchorsBySelect, setAnchorsBySelect] = (0, import_react4.useState)([]);
754
764
  const mounted = (0, import_react4.useRef)(false);
765
+ const shouldOpenOnClick = openOnClick || events.includes("click");
755
766
  use_isomorphic_layout_effect_default(() => {
756
767
  mounted.current = true;
757
768
  return () => {
@@ -911,11 +922,13 @@
911
922
  }
912
923
  };
913
924
  const handleClickOutsideAnchors = (event) => {
925
+ var _a;
914
926
  const anchorById = document.querySelector(`[id='${anchorId}']`);
915
- if (anchorById == null ? void 0 : anchorById.contains(event.target)) {
927
+ const anchors = [anchorById, ...anchorsBySelect];
928
+ if (anchors.some((anchor) => anchor == null ? void 0 : anchor.contains(event.target))) {
916
929
  return;
917
930
  }
918
- if (anchorsBySelect.some((anchor) => anchor.contains(event.target))) {
931
+ if ((_a = tooltipRef.current) == null ? void 0 : _a.contains(event.target)) {
919
932
  return;
920
933
  }
921
934
  handleShow(false);
@@ -942,11 +955,10 @@
942
955
  window.addEventListener("keydown", handleEsc);
943
956
  }
944
957
  const enabledEvents = [];
945
- if (events.find((event) => event === "click")) {
958
+ if (shouldOpenOnClick) {
946
959
  window.addEventListener("click", handleClickOutsideAnchors);
947
960
  enabledEvents.push({ event: "click", listener: handleClickTooltipAnchor });
948
- }
949
- if (events.find((event) => event === "hover")) {
961
+ } else {
950
962
  enabledEvents.push(
951
963
  { event: "mouseenter", listener: debouncedHandleShowTooltip },
952
964
  { event: "mouseleave", listener: debouncedHandleHideTooltip },
@@ -967,7 +979,7 @@
967
979
  hoveringTooltip.current = false;
968
980
  handleHideTooltip();
969
981
  };
970
- if (clickable) {
982
+ if (clickable && !shouldOpenOnClick) {
971
983
  (_a = tooltipRef.current) == null ? void 0 : _a.addEventListener("mouseenter", handleMouseEnterTooltip);
972
984
  (_b = tooltipRef.current) == null ? void 0 : _b.addEventListener("mouseleave", handleMouseLeaveTooltip);
973
985
  }
@@ -979,13 +991,13 @@
979
991
  });
980
992
  return () => {
981
993
  var _a2, _b2;
982
- if (events.find((event) => event === "click")) {
994
+ if (shouldOpenOnClick) {
983
995
  window.removeEventListener("click", handleClickOutsideAnchors);
984
996
  }
985
997
  if (closeOnEsc) {
986
998
  window.removeEventListener("keydown", handleEsc);
987
999
  }
988
- if (clickable) {
1000
+ if (clickable && !shouldOpenOnClick) {
989
1001
  (_a2 = tooltipRef.current) == null ? void 0 : _a2.removeEventListener("mouseenter", handleMouseEnterTooltip);
990
1002
  (_b2 = tooltipRef.current) == null ? void 0 : _b2.removeEventListener("mouseleave", handleMouseLeaveTooltip);
991
1003
  }
@@ -1090,7 +1102,7 @@
1090
1102
  }
1091
1103
  setActualPlacement(computedStylesData.place);
1092
1104
  });
1093
- }, [show, activeAnchor, content, place, offset, positionStrategy, position]);
1105
+ }, [show, activeAnchor, content, html, place, offset, positionStrategy, position]);
1094
1106
  (0, import_react4.useEffect)(() => {
1095
1107
  var _a;
1096
1108
  const anchorById = document.querySelector(`[id='${anchorId}']`);
@@ -1124,8 +1136,9 @@
1124
1136
  setAnchorsBySelect([]);
1125
1137
  }
1126
1138
  }, [id, anchorSelect]);
1127
- const canShow = content && show && Object.keys(inlineStyles).length > 0;
1128
- return rendered ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
1139
+ const hasContentOrChildren = Boolean(html || content || children);
1140
+ const canShow = hasContentOrChildren && show && Object.keys(inlineStyles).length > 0;
1141
+ return rendered ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
1129
1142
  WrapperElement,
1130
1143
  {
1131
1144
  id,
@@ -1145,8 +1158,8 @@
1145
1158
  style: { ...externalStyles, ...inlineStyles },
1146
1159
  ref: tooltipRef,
1147
1160
  children: [
1148
- content,
1149
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1161
+ html && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(TooltipContent_default, { content: html }) || content || children,
1162
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1150
1163
  WrapperElement,
1151
1164
  {
1152
1165
  className: (0, import_classnames2.default)("react-tooltip-arrow", styles_module_default["arrow"], classNameArrow, {
@@ -1166,13 +1179,6 @@
1166
1179
  };
1167
1180
  var Tooltip_default = Tooltip;
1168
1181
 
1169
- // src/components/TooltipContent/TooltipContent.tsx
1170
- var import_jsx_runtime4 = __require("react/jsx-runtime");
1171
- var TooltipContent = ({ content }) => {
1172
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { dangerouslySetInnerHTML: { __html: content } });
1173
- };
1174
- var TooltipContent_default = TooltipContent;
1175
-
1176
1182
  // src/components/TooltipController/TooltipController.tsx
1177
1183
  var import_jsx_runtime5 = __require("react/jsx-runtime");
1178
1184
  var TooltipController = ({
@@ -1181,7 +1187,6 @@
1181
1187
  anchorSelect,
1182
1188
  content,
1183
1189
  html,
1184
- render,
1185
1190
  className,
1186
1191
  classNameArrow,
1187
1192
  variant = "dark",
@@ -1190,6 +1195,7 @@
1190
1195
  wrapper = "div",
1191
1196
  children = null,
1192
1197
  events = ["hover"],
1198
+ openOnClick = false,
1193
1199
  positionStrategy = "absolute",
1194
1200
  middlewares,
1195
1201
  delayShow = 0,
@@ -1329,27 +1335,20 @@
1329
1335
  observer.disconnect();
1330
1336
  };
1331
1337
  }, [anchorRefs, providerActiveAnchor, activeAnchor, anchorId, anchorSelect]);
1332
- let renderedContent = children;
1333
- if (render) {
1334
- renderedContent = render({ content: tooltipContent != null ? tooltipContent : null, activeAnchor });
1335
- } else if (tooltipContent) {
1336
- renderedContent = tooltipContent;
1337
- }
1338
- if (tooltipHtml) {
1339
- renderedContent = /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(TooltipContent_default, { content: tooltipHtml });
1340
- }
1341
1338
  const props = {
1342
1339
  id,
1343
1340
  anchorId,
1344
1341
  anchorSelect,
1345
1342
  className,
1346
1343
  classNameArrow,
1347
- content: renderedContent,
1344
+ content: tooltipContent,
1345
+ html: tooltipHtml,
1348
1346
  place: tooltipPlace,
1349
1347
  variant: tooltipVariant,
1350
1348
  offset: tooltipOffset,
1351
1349
  wrapper: tooltipWrapper,
1352
1350
  events: tooltipEvents,
1351
+ openOnClick,
1353
1352
  positionStrategy: tooltipPositionStrategy,
1354
1353
  middlewares,
1355
1354
  delayShow: tooltipDelayShow,
@@ -1367,7 +1366,7 @@
1367
1366
  activeAnchor,
1368
1367
  setActiveAnchor: (anchor) => setActiveAnchor(anchor)
1369
1368
  };
1370
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Tooltip_default, { ...props });
1369
+ return children ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Tooltip_default, { ...props, children }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Tooltip_default, { ...props });
1371
1370
  };
1372
1371
  var TooltipController_default = TooltipController;
1373
1372
  })();