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.
- package/dist/react-tooltip.cjs.js +36 -37
- package/dist/react-tooltip.cjs.js.map +4 -4
- package/dist/react-tooltip.cjs.min.js +1 -1
- package/dist/react-tooltip.cjs.min.js.map +4 -4
- package/dist/react-tooltip.d.ts +8 -5
- package/dist/react-tooltip.esm.js +35 -36
- package/dist/react-tooltip.esm.js.map +4 -4
- package/dist/react-tooltip.esm.min.js +1 -1
- package/dist/react-tooltip.esm.min.js.map +4 -4
- package/dist/react-tooltip.iife.js +36 -37
- package/dist/react-tooltip.iife.js.map +4 -4
- package/dist/react-tooltip.iife.min.js +1 -1
- package/dist/react-tooltip.iife.min.js.map +4 -4
- package/dist/react-tooltip.min.js +1 -1
- package/dist/react-tooltip.min.js.map +4 -4
- package/package.json +1 -1
|
@@ -100,6 +100,13 @@ var debounce = (func, wait, immediate) => {
|
|
|
100
100
|
};
|
|
101
101
|
var debounce_default = debounce;
|
|
102
102
|
|
|
103
|
+
// src/components/TooltipContent/TooltipContent.tsx
|
|
104
|
+
import { jsx } from "react/jsx-runtime";
|
|
105
|
+
var TooltipContent = ({ content }) => {
|
|
106
|
+
return /* @__PURE__ */ jsx("span", { dangerouslySetInnerHTML: { __html: content } });
|
|
107
|
+
};
|
|
108
|
+
var TooltipContent_default = TooltipContent;
|
|
109
|
+
|
|
103
110
|
// src/components/TooltipProvider/TooltipProvider.tsx
|
|
104
111
|
import {
|
|
105
112
|
createContext,
|
|
@@ -108,7 +115,7 @@ import {
|
|
|
108
115
|
useMemo,
|
|
109
116
|
useState
|
|
110
117
|
} from "react";
|
|
111
|
-
import { jsx } from "react/jsx-runtime";
|
|
118
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
112
119
|
var DEFAULT_TOOLTIP_ID = "DEFAULT_TOOLTIP_ID";
|
|
113
120
|
var DEFAULT_CONTEXT_DATA = {
|
|
114
121
|
anchorRefs: /* @__PURE__ */ new Set(),
|
|
@@ -176,7 +183,7 @@ var TooltipProvider = ({ children }) => {
|
|
|
176
183
|
getTooltipData
|
|
177
184
|
};
|
|
178
185
|
}, [getTooltipData]);
|
|
179
|
-
return /* @__PURE__ */
|
|
186
|
+
return /* @__PURE__ */ jsx2(TooltipContext.Provider, { value: context, children });
|
|
180
187
|
};
|
|
181
188
|
function useTooltip(tooltipId = DEFAULT_TOOLTIP_ID) {
|
|
182
189
|
return useContext(TooltipContext).getTooltipData(tooltipId);
|
|
@@ -186,7 +193,7 @@ var TooltipProvider_default = TooltipProvider;
|
|
|
186
193
|
// src/components/TooltipProvider/TooltipWrapper.tsx
|
|
187
194
|
var import_classnames = __toESM(require_classnames());
|
|
188
195
|
import { useEffect, useRef } from "react";
|
|
189
|
-
import { jsx as
|
|
196
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
190
197
|
var TooltipWrapper = ({
|
|
191
198
|
tooltipId,
|
|
192
199
|
children,
|
|
@@ -210,7 +217,7 @@ var TooltipWrapper = ({
|
|
|
210
217
|
detach(anchorRef);
|
|
211
218
|
};
|
|
212
219
|
}, []);
|
|
213
|
-
return /* @__PURE__ */
|
|
220
|
+
return /* @__PURE__ */ jsx3(
|
|
214
221
|
"span",
|
|
215
222
|
{
|
|
216
223
|
ref: anchorRef,
|
|
@@ -702,7 +709,7 @@ var computeTooltipPosition = async ({
|
|
|
702
709
|
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" };
|
|
703
710
|
|
|
704
711
|
// src/components/Tooltip/Tooltip.tsx
|
|
705
|
-
import { jsx as
|
|
712
|
+
import { jsx as jsx4, jsxs } from "react/jsx-runtime";
|
|
706
713
|
var Tooltip = ({
|
|
707
714
|
// props
|
|
708
715
|
id,
|
|
@@ -714,9 +721,11 @@ var Tooltip = ({
|
|
|
714
721
|
place = "top",
|
|
715
722
|
offset = 10,
|
|
716
723
|
events = ["hover"],
|
|
724
|
+
openOnClick = false,
|
|
717
725
|
positionStrategy = "absolute",
|
|
718
726
|
middlewares,
|
|
719
727
|
wrapper: WrapperElement,
|
|
728
|
+
children = null,
|
|
720
729
|
delayShow = 0,
|
|
721
730
|
delayHide = 0,
|
|
722
731
|
float = false,
|
|
@@ -729,6 +738,7 @@ var Tooltip = ({
|
|
|
729
738
|
afterHide,
|
|
730
739
|
// props handled by controller
|
|
731
740
|
content,
|
|
741
|
+
html,
|
|
732
742
|
isOpen,
|
|
733
743
|
setIsOpen,
|
|
734
744
|
activeAnchor,
|
|
@@ -749,6 +759,7 @@ var Tooltip = ({
|
|
|
749
759
|
const hoveringTooltip = useRef2(false);
|
|
750
760
|
const [anchorsBySelect, setAnchorsBySelect] = useState2([]);
|
|
751
761
|
const mounted = useRef2(false);
|
|
762
|
+
const shouldOpenOnClick = openOnClick || events.includes("click");
|
|
752
763
|
use_isomorphic_layout_effect_default(() => {
|
|
753
764
|
mounted.current = true;
|
|
754
765
|
return () => {
|
|
@@ -908,11 +919,13 @@ var Tooltip = ({
|
|
|
908
919
|
}
|
|
909
920
|
};
|
|
910
921
|
const handleClickOutsideAnchors = (event) => {
|
|
922
|
+
var _a;
|
|
911
923
|
const anchorById = document.querySelector(`[id='${anchorId}']`);
|
|
912
|
-
|
|
924
|
+
const anchors = [anchorById, ...anchorsBySelect];
|
|
925
|
+
if (anchors.some((anchor) => anchor == null ? void 0 : anchor.contains(event.target))) {
|
|
913
926
|
return;
|
|
914
927
|
}
|
|
915
|
-
if (
|
|
928
|
+
if ((_a = tooltipRef.current) == null ? void 0 : _a.contains(event.target)) {
|
|
916
929
|
return;
|
|
917
930
|
}
|
|
918
931
|
handleShow(false);
|
|
@@ -939,11 +952,10 @@ var Tooltip = ({
|
|
|
939
952
|
window.addEventListener("keydown", handleEsc);
|
|
940
953
|
}
|
|
941
954
|
const enabledEvents = [];
|
|
942
|
-
if (
|
|
955
|
+
if (shouldOpenOnClick) {
|
|
943
956
|
window.addEventListener("click", handleClickOutsideAnchors);
|
|
944
957
|
enabledEvents.push({ event: "click", listener: handleClickTooltipAnchor });
|
|
945
|
-
}
|
|
946
|
-
if (events.find((event) => event === "hover")) {
|
|
958
|
+
} else {
|
|
947
959
|
enabledEvents.push(
|
|
948
960
|
{ event: "mouseenter", listener: debouncedHandleShowTooltip },
|
|
949
961
|
{ event: "mouseleave", listener: debouncedHandleHideTooltip },
|
|
@@ -964,7 +976,7 @@ var Tooltip = ({
|
|
|
964
976
|
hoveringTooltip.current = false;
|
|
965
977
|
handleHideTooltip();
|
|
966
978
|
};
|
|
967
|
-
if (clickable) {
|
|
979
|
+
if (clickable && !shouldOpenOnClick) {
|
|
968
980
|
(_a = tooltipRef.current) == null ? void 0 : _a.addEventListener("mouseenter", handleMouseEnterTooltip);
|
|
969
981
|
(_b = tooltipRef.current) == null ? void 0 : _b.addEventListener("mouseleave", handleMouseLeaveTooltip);
|
|
970
982
|
}
|
|
@@ -976,13 +988,13 @@ var Tooltip = ({
|
|
|
976
988
|
});
|
|
977
989
|
return () => {
|
|
978
990
|
var _a2, _b2;
|
|
979
|
-
if (
|
|
991
|
+
if (shouldOpenOnClick) {
|
|
980
992
|
window.removeEventListener("click", handleClickOutsideAnchors);
|
|
981
993
|
}
|
|
982
994
|
if (closeOnEsc) {
|
|
983
995
|
window.removeEventListener("keydown", handleEsc);
|
|
984
996
|
}
|
|
985
|
-
if (clickable) {
|
|
997
|
+
if (clickable && !shouldOpenOnClick) {
|
|
986
998
|
(_a2 = tooltipRef.current) == null ? void 0 : _a2.removeEventListener("mouseenter", handleMouseEnterTooltip);
|
|
987
999
|
(_b2 = tooltipRef.current) == null ? void 0 : _b2.removeEventListener("mouseleave", handleMouseLeaveTooltip);
|
|
988
1000
|
}
|
|
@@ -1087,7 +1099,7 @@ var Tooltip = ({
|
|
|
1087
1099
|
}
|
|
1088
1100
|
setActualPlacement(computedStylesData.place);
|
|
1089
1101
|
});
|
|
1090
|
-
}, [show, activeAnchor, content, place, offset, positionStrategy, position]);
|
|
1102
|
+
}, [show, activeAnchor, content, html, place, offset, positionStrategy, position]);
|
|
1091
1103
|
useEffect3(() => {
|
|
1092
1104
|
var _a;
|
|
1093
1105
|
const anchorById = document.querySelector(`[id='${anchorId}']`);
|
|
@@ -1121,7 +1133,8 @@ var Tooltip = ({
|
|
|
1121
1133
|
setAnchorsBySelect([]);
|
|
1122
1134
|
}
|
|
1123
1135
|
}, [id, anchorSelect]);
|
|
1124
|
-
const
|
|
1136
|
+
const hasContentOrChildren = Boolean(html || content || children);
|
|
1137
|
+
const canShow = hasContentOrChildren && show && Object.keys(inlineStyles).length > 0;
|
|
1125
1138
|
return rendered ? /* @__PURE__ */ jsxs(
|
|
1126
1139
|
WrapperElement,
|
|
1127
1140
|
{
|
|
@@ -1142,8 +1155,8 @@ var Tooltip = ({
|
|
|
1142
1155
|
style: { ...externalStyles, ...inlineStyles },
|
|
1143
1156
|
ref: tooltipRef,
|
|
1144
1157
|
children: [
|
|
1145
|
-
content,
|
|
1146
|
-
/* @__PURE__ */
|
|
1158
|
+
html && /* @__PURE__ */ jsx4(TooltipContent_default, { content: html }) || content || children,
|
|
1159
|
+
/* @__PURE__ */ jsx4(
|
|
1147
1160
|
WrapperElement,
|
|
1148
1161
|
{
|
|
1149
1162
|
className: (0, import_classnames2.default)("react-tooltip-arrow", styles_module_default["arrow"], classNameArrow, {
|
|
@@ -1163,13 +1176,6 @@ var Tooltip = ({
|
|
|
1163
1176
|
};
|
|
1164
1177
|
var Tooltip_default = Tooltip;
|
|
1165
1178
|
|
|
1166
|
-
// src/components/TooltipContent/TooltipContent.tsx
|
|
1167
|
-
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
1168
|
-
var TooltipContent = ({ content }) => {
|
|
1169
|
-
return /* @__PURE__ */ jsx4("span", { dangerouslySetInnerHTML: { __html: content } });
|
|
1170
|
-
};
|
|
1171
|
-
var TooltipContent_default = TooltipContent;
|
|
1172
|
-
|
|
1173
1179
|
// src/components/TooltipController/TooltipController.tsx
|
|
1174
1180
|
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
1175
1181
|
var TooltipController = ({
|
|
@@ -1178,7 +1184,6 @@ var TooltipController = ({
|
|
|
1178
1184
|
anchorSelect,
|
|
1179
1185
|
content,
|
|
1180
1186
|
html,
|
|
1181
|
-
render,
|
|
1182
1187
|
className,
|
|
1183
1188
|
classNameArrow,
|
|
1184
1189
|
variant = "dark",
|
|
@@ -1187,6 +1192,7 @@ var TooltipController = ({
|
|
|
1187
1192
|
wrapper = "div",
|
|
1188
1193
|
children = null,
|
|
1189
1194
|
events = ["hover"],
|
|
1195
|
+
openOnClick = false,
|
|
1190
1196
|
positionStrategy = "absolute",
|
|
1191
1197
|
middlewares,
|
|
1192
1198
|
delayShow = 0,
|
|
@@ -1326,27 +1332,20 @@ var TooltipController = ({
|
|
|
1326
1332
|
observer.disconnect();
|
|
1327
1333
|
};
|
|
1328
1334
|
}, [anchorRefs, providerActiveAnchor, activeAnchor, anchorId, anchorSelect]);
|
|
1329
|
-
let renderedContent = children;
|
|
1330
|
-
if (render) {
|
|
1331
|
-
renderedContent = render({ content: tooltipContent != null ? tooltipContent : null, activeAnchor });
|
|
1332
|
-
} else if (tooltipContent) {
|
|
1333
|
-
renderedContent = tooltipContent;
|
|
1334
|
-
}
|
|
1335
|
-
if (tooltipHtml) {
|
|
1336
|
-
renderedContent = /* @__PURE__ */ jsx5(TooltipContent_default, { content: tooltipHtml });
|
|
1337
|
-
}
|
|
1338
1335
|
const props = {
|
|
1339
1336
|
id,
|
|
1340
1337
|
anchorId,
|
|
1341
1338
|
anchorSelect,
|
|
1342
1339
|
className,
|
|
1343
1340
|
classNameArrow,
|
|
1344
|
-
content:
|
|
1341
|
+
content: tooltipContent,
|
|
1342
|
+
html: tooltipHtml,
|
|
1345
1343
|
place: tooltipPlace,
|
|
1346
1344
|
variant: tooltipVariant,
|
|
1347
1345
|
offset: tooltipOffset,
|
|
1348
1346
|
wrapper: tooltipWrapper,
|
|
1349
1347
|
events: tooltipEvents,
|
|
1348
|
+
openOnClick,
|
|
1350
1349
|
positionStrategy: tooltipPositionStrategy,
|
|
1351
1350
|
middlewares,
|
|
1352
1351
|
delayShow: tooltipDelayShow,
|
|
@@ -1364,7 +1363,7 @@ var TooltipController = ({
|
|
|
1364
1363
|
activeAnchor,
|
|
1365
1364
|
setActiveAnchor: (anchor) => setActiveAnchor(anchor)
|
|
1366
1365
|
};
|
|
1367
|
-
return /* @__PURE__ */ jsx5(Tooltip_default, { ...props });
|
|
1366
|
+
return children ? /* @__PURE__ */ jsx5(Tooltip_default, { ...props, children }) : /* @__PURE__ */ jsx5(Tooltip_default, { ...props });
|
|
1368
1367
|
};
|
|
1369
1368
|
var TooltipController_default = TooltipController;
|
|
1370
1369
|
export {
|