react-tooltip 5.10.2-beta.3 → 5.10.2-beta.4

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.
@@ -1,918 +0,0 @@
1
- // src/components/TooltipController/TooltipController.tsx
2
- import { useEffect as useEffect4, useRef as useRef3, useState as useState3 } from "react";
3
-
4
- // src/components/Tooltip/Tooltip.tsx
5
- import { useEffect as useEffect3, useState as useState2, useRef as useRef2 } from "react";
6
- import classNames2 from "classnames";
7
-
8
- // src/utils/debounce.ts
9
- var debounce = (func, wait, immediate) => {
10
- let timeout = null;
11
- return function debounced(...args) {
12
- const later = () => {
13
- timeout = null;
14
- if (!immediate) {
15
- func.apply(this, args);
16
- }
17
- };
18
- if (timeout) {
19
- clearTimeout(timeout);
20
- }
21
- timeout = setTimeout(later, wait);
22
- };
23
- };
24
- var debounce_default = debounce;
25
-
26
- // src/components/TooltipProvider/TooltipProvider.tsx
27
- import {
28
- createContext,
29
- useCallback,
30
- useContext,
31
- useMemo,
32
- useState
33
- } from "react";
34
- import { jsx } from "react/jsx-runtime";
35
- var DEFAULT_TOOLTIP_ID = "DEFAULT_TOOLTIP_ID";
36
- var DEFAULT_CONTEXT_DATA = {
37
- anchorRefs: /* @__PURE__ */ new Set(),
38
- activeAnchor: { current: null },
39
- attach: () => {
40
- },
41
- detach: () => {
42
- },
43
- setActiveAnchor: () => {
44
- }
45
- };
46
- var DEFAULT_CONTEXT_DATA_WRAPPER = {
47
- getTooltipData: () => DEFAULT_CONTEXT_DATA
48
- };
49
- var TooltipContext = createContext(DEFAULT_CONTEXT_DATA_WRAPPER);
50
- var TooltipProvider = ({ children }) => {
51
- const [anchorRefMap, setAnchorRefMap] = useState({
52
- [DEFAULT_TOOLTIP_ID]: /* @__PURE__ */ new Set()
53
- });
54
- const [activeAnchorMap, setActiveAnchorMap] = useState({
55
- [DEFAULT_TOOLTIP_ID]: { current: null }
56
- });
57
- const attach = (tooltipId, ...refs) => {
58
- setAnchorRefMap((oldMap) => {
59
- var _a;
60
- const tooltipRefs = (_a = oldMap[tooltipId]) != null ? _a : /* @__PURE__ */ new Set();
61
- refs.forEach((ref) => tooltipRefs.add(ref));
62
- return { ...oldMap, [tooltipId]: new Set(tooltipRefs) };
63
- });
64
- };
65
- const detach = (tooltipId, ...refs) => {
66
- setAnchorRefMap((oldMap) => {
67
- const tooltipRefs = oldMap[tooltipId];
68
- if (!tooltipRefs) {
69
- return oldMap;
70
- }
71
- refs.forEach((ref) => tooltipRefs.delete(ref));
72
- return { ...oldMap };
73
- });
74
- };
75
- const setActiveAnchor = (tooltipId, ref) => {
76
- setActiveAnchorMap((oldMap) => {
77
- var _a;
78
- if (((_a = oldMap[tooltipId]) == null ? void 0 : _a.current) === ref.current) {
79
- return oldMap;
80
- }
81
- return { ...oldMap, [tooltipId]: ref };
82
- });
83
- };
84
- const getTooltipData = useCallback(
85
- (tooltipId = DEFAULT_TOOLTIP_ID) => {
86
- var _a, _b;
87
- return {
88
- anchorRefs: (_a = anchorRefMap[tooltipId]) != null ? _a : /* @__PURE__ */ new Set(),
89
- activeAnchor: (_b = activeAnchorMap[tooltipId]) != null ? _b : { current: null },
90
- attach: (...refs) => attach(tooltipId, ...refs),
91
- detach: (...refs) => detach(tooltipId, ...refs),
92
- setActiveAnchor: (ref) => setActiveAnchor(tooltipId, ref)
93
- };
94
- },
95
- [anchorRefMap, activeAnchorMap, attach, detach]
96
- );
97
- const context = useMemo(() => {
98
- return {
99
- getTooltipData
100
- };
101
- }, [getTooltipData]);
102
- return /* @__PURE__ */ jsx(TooltipContext.Provider, { value: context, children });
103
- };
104
- function useTooltip(tooltipId = DEFAULT_TOOLTIP_ID) {
105
- return useContext(TooltipContext).getTooltipData(tooltipId);
106
- }
107
- var TooltipProvider_default = TooltipProvider;
108
-
109
- // src/components/TooltipProvider/TooltipWrapper.tsx
110
- import { useEffect, useRef } from "react";
111
- import classNames from "classnames";
112
- import { jsx as jsx2 } from "react/jsx-runtime";
113
- var TooltipWrapper = ({
114
- tooltipId,
115
- children,
116
- className,
117
- place,
118
- content,
119
- html,
120
- variant,
121
- offset: offset2,
122
- wrapper,
123
- events,
124
- positionStrategy,
125
- delayShow,
126
- delayHide
127
- }) => {
128
- const { attach, detach } = useTooltip(tooltipId);
129
- const anchorRef = useRef(null);
130
- useEffect(() => {
131
- attach(anchorRef);
132
- return () => {
133
- detach(anchorRef);
134
- };
135
- }, []);
136
- return /* @__PURE__ */ jsx2(
137
- "span",
138
- {
139
- ref: anchorRef,
140
- className: classNames("react-tooltip-wrapper", className),
141
- "data-tooltip-place": place,
142
- "data-tooltip-content": content,
143
- "data-tooltip-html": html,
144
- "data-tooltip-variant": variant,
145
- "data-tooltip-offset": offset2,
146
- "data-tooltip-wrapper": wrapper,
147
- "data-tooltip-events": events,
148
- "data-tooltip-position-strategy": positionStrategy,
149
- "data-tooltip-delay-show": delayShow,
150
- "data-tooltip-delay-hide": delayHide,
151
- children
152
- }
153
- );
154
- };
155
- var TooltipWrapper_default = TooltipWrapper;
156
-
157
- // src/utils/use-isomorphic-layout-effect.ts
158
- import { useLayoutEffect, useEffect as useEffect2 } from "react";
159
- var useIsomorphicLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect2;
160
- var use_isomorphic_layout_effect_default = useIsomorphicLayoutEffect;
161
-
162
- // src/utils/compute-positions.ts
163
- import { computePosition, offset, shift, arrow, flip } from "@floating-ui/dom";
164
- var computeTooltipPosition = async ({
165
- elementReference = null,
166
- tooltipReference = null,
167
- tooltipArrowReference = null,
168
- place = "top",
169
- offset: offsetValue = 10,
170
- strategy = "absolute",
171
- middlewares = [offset(Number(offsetValue)), flip(), shift({ padding: 5 })]
172
- }) => {
173
- if (!elementReference) {
174
- return { tooltipStyles: {}, tooltipArrowStyles: {}, place };
175
- }
176
- if (tooltipReference === null) {
177
- return { tooltipStyles: {}, tooltipArrowStyles: {}, place };
178
- }
179
- const middleware = middlewares;
180
- if (tooltipArrowReference) {
181
- middleware.push(arrow({ element: tooltipArrowReference, padding: 5 }));
182
- return computePosition(elementReference, tooltipReference, {
183
- placement: place,
184
- strategy,
185
- middleware
186
- }).then(({ x, y, placement, middlewareData }) => {
187
- var _a, _b;
188
- const styles = { left: `${x}px`, top: `${y}px` };
189
- const { x: arrowX, y: arrowY } = (_a = middlewareData.arrow) != null ? _a : { x: 0, y: 0 };
190
- const staticSide = (_b = {
191
- top: "bottom",
192
- right: "left",
193
- bottom: "top",
194
- left: "right"
195
- }[placement.split("-")[0]]) != null ? _b : "bottom";
196
- const arrowStyle = {
197
- left: arrowX != null ? `${arrowX}px` : "",
198
- top: arrowY != null ? `${arrowY}px` : "",
199
- right: "",
200
- bottom: "",
201
- [staticSide]: "-4px"
202
- };
203
- return { tooltipStyles: styles, tooltipArrowStyles: arrowStyle, place: placement };
204
- });
205
- }
206
- return computePosition(elementReference, tooltipReference, {
207
- placement: "bottom",
208
- strategy,
209
- middleware
210
- }).then(({ x, y, placement }) => {
211
- const styles = { left: `${x}px`, top: `${y}px` };
212
- return { tooltipStyles: styles, tooltipArrowStyles: {}, place: placement };
213
- });
214
- };
215
-
216
- // esbuild-css-modules-plugin-namespace:./src/components/Tooltip/styles.module.css?esbuild-css-modules-plugin-building
217
- 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" };
218
-
219
- // src/components/Tooltip/Tooltip.tsx
220
- import { jsx as jsx3, jsxs } from "react/jsx-runtime";
221
- var Tooltip = ({
222
- // props
223
- id,
224
- className,
225
- classNameArrow,
226
- variant = "dark",
227
- anchorId,
228
- anchorSelect,
229
- place = "top",
230
- offset: offset2 = 10,
231
- events = ["hover"],
232
- openOnClick = false,
233
- positionStrategy = "absolute",
234
- middlewares,
235
- wrapper: WrapperElement,
236
- delayShow = 0,
237
- delayHide = 0,
238
- float = false,
239
- noArrow = false,
240
- clickable = false,
241
- closeOnEsc = false,
242
- style: externalStyles,
243
- position,
244
- afterShow,
245
- afterHide,
246
- // props handled by controller
247
- content,
248
- contentRef,
249
- isOpen,
250
- setIsOpen,
251
- activeAnchor,
252
- setActiveAnchor
253
- }) => {
254
- const tooltipRef = useRef2(null);
255
- const tooltipArrowRef = useRef2(null);
256
- const tooltipShowDelayTimerRef = useRef2(null);
257
- const tooltipHideDelayTimerRef = useRef2(null);
258
- const [actualPlacement, setActualPlacement] = useState2(place);
259
- const [inlineStyles, setInlineStyles] = useState2({});
260
- const [inlineArrowStyles, setInlineArrowStyles] = useState2({});
261
- const [show, setShow] = useState2(false);
262
- const [rendered, setRendered] = useState2(false);
263
- const wasShowing = useRef2(false);
264
- const lastFloatPosition = useRef2(null);
265
- const { anchorRefs, setActiveAnchor: setProviderActiveAnchor } = useTooltip(id);
266
- const hoveringTooltip = useRef2(false);
267
- const [anchorsBySelect, setAnchorsBySelect] = useState2([]);
268
- const mounted = useRef2(false);
269
- const shouldOpenOnClick = openOnClick || events.includes("click");
270
- use_isomorphic_layout_effect_default(() => {
271
- mounted.current = true;
272
- return () => {
273
- mounted.current = false;
274
- };
275
- }, []);
276
- useEffect3(() => {
277
- if (!show) {
278
- const timeout = setTimeout(() => {
279
- setRendered(false);
280
- }, 150);
281
- return () => {
282
- clearTimeout(timeout);
283
- };
284
- }
285
- return () => null;
286
- }, [show]);
287
- const handleShow = (value) => {
288
- if (!mounted.current) {
289
- return;
290
- }
291
- if (value) {
292
- setRendered(true);
293
- }
294
- setTimeout(() => {
295
- if (!mounted.current) {
296
- return;
297
- }
298
- setIsOpen == null ? void 0 : setIsOpen(value);
299
- if (isOpen === void 0) {
300
- setShow(value);
301
- }
302
- }, 10);
303
- };
304
- useEffect3(() => {
305
- if (isOpen === void 0) {
306
- return () => null;
307
- }
308
- if (isOpen) {
309
- setRendered(true);
310
- }
311
- const timeout = setTimeout(() => {
312
- setShow(isOpen);
313
- }, 10);
314
- return () => {
315
- clearTimeout(timeout);
316
- };
317
- }, [isOpen]);
318
- useEffect3(() => {
319
- if (show === wasShowing.current) {
320
- return;
321
- }
322
- wasShowing.current = show;
323
- if (show) {
324
- afterShow == null ? void 0 : afterShow();
325
- } else {
326
- afterHide == null ? void 0 : afterHide();
327
- }
328
- }, [show]);
329
- const handleShowTooltipDelayed = () => {
330
- if (tooltipShowDelayTimerRef.current) {
331
- clearTimeout(tooltipShowDelayTimerRef.current);
332
- }
333
- tooltipShowDelayTimerRef.current = setTimeout(() => {
334
- handleShow(true);
335
- }, delayShow);
336
- };
337
- const handleHideTooltipDelayed = (delay = delayHide) => {
338
- if (tooltipHideDelayTimerRef.current) {
339
- clearTimeout(tooltipHideDelayTimerRef.current);
340
- }
341
- tooltipHideDelayTimerRef.current = setTimeout(() => {
342
- if (hoveringTooltip.current) {
343
- return;
344
- }
345
- handleShow(false);
346
- }, delay);
347
- };
348
- const handleShowTooltip = (event) => {
349
- var _a;
350
- if (!event) {
351
- return;
352
- }
353
- if (delayShow) {
354
- handleShowTooltipDelayed();
355
- } else {
356
- handleShow(true);
357
- }
358
- const target = (_a = event.currentTarget) != null ? _a : event.target;
359
- setActiveAnchor(target);
360
- setProviderActiveAnchor({ current: target });
361
- if (tooltipHideDelayTimerRef.current) {
362
- clearTimeout(tooltipHideDelayTimerRef.current);
363
- }
364
- };
365
- const handleHideTooltip = () => {
366
- if (clickable) {
367
- handleHideTooltipDelayed(delayHide || 100);
368
- } else if (delayHide) {
369
- handleHideTooltipDelayed();
370
- } else {
371
- handleShow(false);
372
- }
373
- if (tooltipShowDelayTimerRef.current) {
374
- clearTimeout(tooltipShowDelayTimerRef.current);
375
- }
376
- };
377
- const handleTooltipPosition = ({ x, y }) => {
378
- const virtualElement = {
379
- getBoundingClientRect() {
380
- return {
381
- x,
382
- y,
383
- width: 0,
384
- height: 0,
385
- top: y,
386
- left: x,
387
- right: x,
388
- bottom: y
389
- };
390
- }
391
- };
392
- computeTooltipPosition({
393
- place,
394
- offset: offset2,
395
- elementReference: virtualElement,
396
- tooltipReference: tooltipRef.current,
397
- tooltipArrowReference: tooltipArrowRef.current,
398
- strategy: positionStrategy,
399
- middlewares
400
- }).then((computedStylesData) => {
401
- if (Object.keys(computedStylesData.tooltipStyles).length) {
402
- setInlineStyles(computedStylesData.tooltipStyles);
403
- }
404
- if (Object.keys(computedStylesData.tooltipArrowStyles).length) {
405
- setInlineArrowStyles(computedStylesData.tooltipArrowStyles);
406
- }
407
- setActualPlacement(computedStylesData.place);
408
- });
409
- };
410
- const handleMouseMove = (event) => {
411
- if (!event) {
412
- return;
413
- }
414
- const mouseEvent = event;
415
- const mousePosition = {
416
- x: mouseEvent.clientX,
417
- y: mouseEvent.clientY
418
- };
419
- handleTooltipPosition(mousePosition);
420
- lastFloatPosition.current = mousePosition;
421
- };
422
- const handleClickTooltipAnchor = (event) => {
423
- handleShowTooltip(event);
424
- if (delayHide) {
425
- handleHideTooltipDelayed();
426
- }
427
- };
428
- const handleClickOutsideAnchors = (event) => {
429
- var _a;
430
- const anchorById = document.querySelector(`[id='${anchorId}']`);
431
- const anchors = [anchorById, ...anchorsBySelect];
432
- if (anchors.some((anchor) => anchor == null ? void 0 : anchor.contains(event.target))) {
433
- return;
434
- }
435
- if ((_a = tooltipRef.current) == null ? void 0 : _a.contains(event.target)) {
436
- return;
437
- }
438
- handleShow(false);
439
- };
440
- const handleEsc = (event) => {
441
- if (event.key !== "Escape") {
442
- return;
443
- }
444
- handleShow(false);
445
- };
446
- const debouncedHandleShowTooltip = debounce_default(handleShowTooltip, 50);
447
- const debouncedHandleHideTooltip = debounce_default(handleHideTooltip, 50);
448
- useEffect3(() => {
449
- var _a, _b;
450
- const elementRefs = new Set(anchorRefs);
451
- anchorsBySelect.forEach((anchor) => {
452
- elementRefs.add({ current: anchor });
453
- });
454
- const anchorById = document.querySelector(`[id='${anchorId}']`);
455
- if (anchorById) {
456
- elementRefs.add({ current: anchorById });
457
- }
458
- if (closeOnEsc) {
459
- window.addEventListener("keydown", handleEsc);
460
- }
461
- const enabledEvents = [];
462
- if (shouldOpenOnClick) {
463
- window.addEventListener("click", handleClickOutsideAnchors);
464
- enabledEvents.push({ event: "click", listener: handleClickTooltipAnchor });
465
- } else {
466
- enabledEvents.push(
467
- { event: "mouseenter", listener: debouncedHandleShowTooltip },
468
- { event: "mouseleave", listener: debouncedHandleHideTooltip },
469
- { event: "focus", listener: debouncedHandleShowTooltip },
470
- { event: "blur", listener: debouncedHandleHideTooltip }
471
- );
472
- if (float) {
473
- enabledEvents.push({
474
- event: "mousemove",
475
- listener: handleMouseMove
476
- });
477
- }
478
- }
479
- const handleMouseEnterTooltip = () => {
480
- hoveringTooltip.current = true;
481
- };
482
- const handleMouseLeaveTooltip = () => {
483
- hoveringTooltip.current = false;
484
- handleHideTooltip();
485
- };
486
- if (clickable && !shouldOpenOnClick) {
487
- (_a = tooltipRef.current) == null ? void 0 : _a.addEventListener("mouseenter", handleMouseEnterTooltip);
488
- (_b = tooltipRef.current) == null ? void 0 : _b.addEventListener("mouseleave", handleMouseLeaveTooltip);
489
- }
490
- enabledEvents.forEach(({ event, listener }) => {
491
- elementRefs.forEach((ref) => {
492
- var _a2;
493
- (_a2 = ref.current) == null ? void 0 : _a2.addEventListener(event, listener);
494
- });
495
- });
496
- return () => {
497
- var _a2, _b2;
498
- if (shouldOpenOnClick) {
499
- window.removeEventListener("click", handleClickOutsideAnchors);
500
- }
501
- if (closeOnEsc) {
502
- window.removeEventListener("keydown", handleEsc);
503
- }
504
- if (clickable && !shouldOpenOnClick) {
505
- (_a2 = tooltipRef.current) == null ? void 0 : _a2.removeEventListener("mouseenter", handleMouseEnterTooltip);
506
- (_b2 = tooltipRef.current) == null ? void 0 : _b2.removeEventListener("mouseleave", handleMouseLeaveTooltip);
507
- }
508
- enabledEvents.forEach(({ event, listener }) => {
509
- elementRefs.forEach((ref) => {
510
- var _a3;
511
- (_a3 = ref.current) == null ? void 0 : _a3.removeEventListener(event, listener);
512
- });
513
- });
514
- };
515
- }, [rendered, anchorRefs, anchorsBySelect, closeOnEsc, events]);
516
- useEffect3(() => {
517
- let selector = anchorSelect != null ? anchorSelect : "";
518
- if (!selector && id) {
519
- selector = `[data-tooltip-id='${id}']`;
520
- }
521
- const documentObserverCallback = (mutationList) => {
522
- const newAnchors = [];
523
- mutationList.forEach((mutation) => {
524
- if (mutation.type === "attributes" && mutation.attributeName === "data-tooltip-id") {
525
- const newId = mutation.target.getAttribute("data-tooltip-id");
526
- if (newId === id) {
527
- newAnchors.push(mutation.target);
528
- }
529
- }
530
- if (mutation.type !== "childList") {
531
- return;
532
- }
533
- if (activeAnchor) {
534
- ;
535
- [...mutation.removedNodes].some((node) => {
536
- var _a;
537
- if ((_a = node == null ? void 0 : node.contains) == null ? void 0 : _a.call(node, activeAnchor)) {
538
- setRendered(false);
539
- handleShow(false);
540
- setActiveAnchor(null);
541
- return true;
542
- }
543
- return false;
544
- });
545
- }
546
- if (!selector) {
547
- return;
548
- }
549
- try {
550
- const elements = [...mutation.addedNodes].filter((node) => node.nodeType === 1);
551
- newAnchors.push(
552
- ...elements.filter(
553
- (element) => element.matches(selector)
554
- )
555
- );
556
- newAnchors.push(
557
- ...elements.flatMap(
558
- (element) => [...element.querySelectorAll(selector)]
559
- )
560
- );
561
- } catch (e) {
562
- }
563
- });
564
- if (newAnchors.length) {
565
- setAnchorsBySelect((anchors) => [...anchors, ...newAnchors]);
566
- }
567
- };
568
- const documentObserver = new MutationObserver(documentObserverCallback);
569
- documentObserver.observe(document.body, {
570
- childList: true,
571
- subtree: true,
572
- attributes: true,
573
- attributeFilter: ["data-tooltip-id"]
574
- });
575
- return () => {
576
- documentObserver.disconnect();
577
- };
578
- }, [id, anchorSelect, activeAnchor]);
579
- const updateTooltipPosition = () => {
580
- if (position) {
581
- handleTooltipPosition(position);
582
- return;
583
- }
584
- if (float) {
585
- if (lastFloatPosition.current) {
586
- handleTooltipPosition(lastFloatPosition.current);
587
- }
588
- return;
589
- }
590
- computeTooltipPosition({
591
- place,
592
- offset: offset2,
593
- elementReference: activeAnchor,
594
- tooltipReference: tooltipRef.current,
595
- tooltipArrowReference: tooltipArrowRef.current,
596
- strategy: positionStrategy,
597
- middlewares
598
- }).then((computedStylesData) => {
599
- if (!mounted.current) {
600
- return;
601
- }
602
- if (Object.keys(computedStylesData.tooltipStyles).length) {
603
- setInlineStyles(computedStylesData.tooltipStyles);
604
- }
605
- if (Object.keys(computedStylesData.tooltipArrowStyles).length) {
606
- setInlineArrowStyles(computedStylesData.tooltipArrowStyles);
607
- }
608
- setActualPlacement(computedStylesData.place);
609
- });
610
- };
611
- useEffect3(() => {
612
- updateTooltipPosition();
613
- }, [show, activeAnchor, content, externalStyles, place, offset2, positionStrategy, position]);
614
- useEffect3(() => {
615
- if (!(contentRef == null ? void 0 : contentRef.current)) {
616
- return () => null;
617
- }
618
- const documentObserver = new MutationObserver(() => {
619
- updateTooltipPosition();
620
- });
621
- documentObserver.observe(contentRef.current, {
622
- attributes: true,
623
- childList: true,
624
- subtree: true
625
- });
626
- return () => {
627
- documentObserver.disconnect();
628
- };
629
- }, [content, contentRef == null ? void 0 : contentRef.current]);
630
- useEffect3(() => {
631
- var _a;
632
- const anchorById = document.querySelector(`[id='${anchorId}']`);
633
- const anchors = [...anchorsBySelect, anchorById];
634
- if (!activeAnchor || !anchors.includes(activeAnchor)) {
635
- setActiveAnchor((_a = anchorsBySelect[0]) != null ? _a : anchorById);
636
- }
637
- }, [anchorId, anchorsBySelect, activeAnchor]);
638
- useEffect3(() => {
639
- return () => {
640
- if (tooltipShowDelayTimerRef.current) {
641
- clearTimeout(tooltipShowDelayTimerRef.current);
642
- }
643
- if (tooltipHideDelayTimerRef.current) {
644
- clearTimeout(tooltipHideDelayTimerRef.current);
645
- }
646
- };
647
- }, []);
648
- useEffect3(() => {
649
- let selector = anchorSelect;
650
- if (!selector && id) {
651
- selector = `[data-tooltip-id='${id}']`;
652
- }
653
- if (!selector) {
654
- return;
655
- }
656
- try {
657
- const anchors = Array.from(document.querySelectorAll(selector));
658
- setAnchorsBySelect(anchors);
659
- } catch (e) {
660
- setAnchorsBySelect([]);
661
- }
662
- }, [id, anchorSelect]);
663
- const canShow = content && show && Object.keys(inlineStyles).length > 0;
664
- return rendered ? /* @__PURE__ */ jsxs(
665
- WrapperElement,
666
- {
667
- id,
668
- role: "tooltip",
669
- className: classNames2(
670
- "react-tooltip",
671
- styles_module_default["tooltip"],
672
- styles_module_default[variant],
673
- className,
674
- `react-tooltip__place-${actualPlacement}`,
675
- {
676
- [styles_module_default["show"]]: canShow,
677
- [styles_module_default["fixed"]]: positionStrategy === "fixed",
678
- [styles_module_default["clickable"]]: clickable
679
- }
680
- ),
681
- style: { ...externalStyles, ...inlineStyles },
682
- ref: tooltipRef,
683
- children: [
684
- content,
685
- /* @__PURE__ */ jsx3(
686
- WrapperElement,
687
- {
688
- className: classNames2("react-tooltip-arrow", styles_module_default["arrow"], classNameArrow, {
689
- /**
690
- * changed from dash `no-arrow` to camelcase because of:
691
- * https://github.com/indooorsman/esbuild-css-modules-plugin/issues/42
692
- */
693
- [styles_module_default["noArrow"]]: noArrow
694
- }),
695
- style: inlineArrowStyles,
696
- ref: tooltipArrowRef
697
- }
698
- )
699
- ]
700
- }
701
- ) : null;
702
- };
703
- var Tooltip_default = Tooltip;
704
-
705
- // src/components/TooltipContent/TooltipContent.tsx
706
- import { jsx as jsx4 } from "react/jsx-runtime";
707
- var TooltipContent = ({ content }) => {
708
- return /* @__PURE__ */ jsx4("span", { dangerouslySetInnerHTML: { __html: content } });
709
- };
710
- var TooltipContent_default = TooltipContent;
711
-
712
- // src/components/TooltipController/TooltipController.tsx
713
- import { jsx as jsx5 } from "react/jsx-runtime";
714
- var TooltipController = ({
715
- id,
716
- anchorId,
717
- anchorSelect,
718
- content,
719
- html,
720
- render,
721
- className,
722
- classNameArrow,
723
- variant = "dark",
724
- place = "top",
725
- offset: offset2 = 10,
726
- wrapper = "div",
727
- children = null,
728
- events = ["hover"],
729
- openOnClick = false,
730
- positionStrategy = "absolute",
731
- middlewares,
732
- delayShow = 0,
733
- delayHide = 0,
734
- float = false,
735
- noArrow = false,
736
- clickable = false,
737
- closeOnEsc = false,
738
- style,
739
- position,
740
- isOpen,
741
- setIsOpen,
742
- afterShow,
743
- afterHide
744
- }) => {
745
- const [tooltipContent, setTooltipContent] = useState3(content);
746
- const [tooltipHtml, setTooltipHtml] = useState3(html);
747
- const [tooltipPlace, setTooltipPlace] = useState3(place);
748
- const [tooltipVariant, setTooltipVariant] = useState3(variant);
749
- const [tooltipOffset, setTooltipOffset] = useState3(offset2);
750
- const [tooltipDelayShow, setTooltipDelayShow] = useState3(delayShow);
751
- const [tooltipDelayHide, setTooltipDelayHide] = useState3(delayHide);
752
- const [tooltipFloat, setTooltipFloat] = useState3(float);
753
- const [tooltipWrapper, setTooltipWrapper] = useState3(wrapper);
754
- const [tooltipEvents, setTooltipEvents] = useState3(events);
755
- const [tooltipPositionStrategy, setTooltipPositionStrategy] = useState3(positionStrategy);
756
- const [activeAnchor, setActiveAnchor] = useState3(null);
757
- const { anchorRefs, activeAnchor: providerActiveAnchor } = useTooltip(id);
758
- const getDataAttributesFromAnchorElement = (elementReference) => {
759
- const dataAttributes = elementReference == null ? void 0 : elementReference.getAttributeNames().reduce((acc, name) => {
760
- var _a;
761
- if (name.startsWith("data-tooltip-")) {
762
- const parsedAttribute = name.replace(/^data-tooltip-/, "");
763
- acc[parsedAttribute] = (_a = elementReference == null ? void 0 : elementReference.getAttribute(name)) != null ? _a : null;
764
- }
765
- return acc;
766
- }, {});
767
- return dataAttributes;
768
- };
769
- const applyAllDataAttributesFromAnchorElement = (dataAttributes) => {
770
- const handleDataAttributes = {
771
- place: (value) => {
772
- setTooltipPlace(value != null ? value : place);
773
- },
774
- content: (value) => {
775
- setTooltipContent(value != null ? value : content);
776
- },
777
- html: (value) => {
778
- setTooltipHtml(value != null ? value : html);
779
- },
780
- variant: (value) => {
781
- setTooltipVariant(value != null ? value : variant);
782
- },
783
- offset: (value) => {
784
- setTooltipOffset(value === null ? offset2 : Number(value));
785
- },
786
- wrapper: (value) => {
787
- setTooltipWrapper(value != null ? value : wrapper);
788
- },
789
- events: (value) => {
790
- const parsed = value == null ? void 0 : value.split(" ");
791
- setTooltipEvents(parsed != null ? parsed : events);
792
- },
793
- "position-strategy": (value) => {
794
- setTooltipPositionStrategy(value != null ? value : positionStrategy);
795
- },
796
- "delay-show": (value) => {
797
- setTooltipDelayShow(value === null ? delayShow : Number(value));
798
- },
799
- "delay-hide": (value) => {
800
- setTooltipDelayHide(value === null ? delayHide : Number(value));
801
- },
802
- float: (value) => {
803
- setTooltipFloat(value === null ? float : value === "true");
804
- }
805
- };
806
- Object.values(handleDataAttributes).forEach((handler) => handler(null));
807
- Object.entries(dataAttributes).forEach(([key, value]) => {
808
- var _a;
809
- (_a = handleDataAttributes[key]) == null ? void 0 : _a.call(handleDataAttributes, value);
810
- });
811
- };
812
- useEffect4(() => {
813
- setTooltipContent(content);
814
- }, [content]);
815
- useEffect4(() => {
816
- setTooltipHtml(html);
817
- }, [html]);
818
- useEffect4(() => {
819
- setTooltipPlace(place);
820
- }, [place]);
821
- useEffect4(() => {
822
- var _a;
823
- const elementRefs = new Set(anchorRefs);
824
- let selector = anchorSelect;
825
- if (!selector && id) {
826
- selector = `[data-tooltip-id='${id}']`;
827
- }
828
- if (selector) {
829
- try {
830
- const anchorsBySelect = document.querySelectorAll(selector);
831
- anchorsBySelect.forEach((anchor) => {
832
- elementRefs.add({ current: anchor });
833
- });
834
- } catch (e) {
835
- if (true) {
836
- console.warn(`[react-tooltip] "${anchorSelect}" is not a valid CSS selector`);
837
- }
838
- }
839
- }
840
- const anchorById = document.querySelector(`[id='${anchorId}']`);
841
- if (anchorById) {
842
- elementRefs.add({ current: anchorById });
843
- }
844
- if (!elementRefs.size) {
845
- return () => null;
846
- }
847
- const anchorElement = (_a = activeAnchor != null ? activeAnchor : anchorById) != null ? _a : providerActiveAnchor.current;
848
- const observerCallback = (mutationList) => {
849
- mutationList.forEach((mutation) => {
850
- var _a2;
851
- if (!anchorElement || mutation.type !== "attributes" || !((_a2 = mutation.attributeName) == null ? void 0 : _a2.startsWith("data-tooltip-"))) {
852
- return;
853
- }
854
- const dataAttributes = getDataAttributesFromAnchorElement(anchorElement);
855
- applyAllDataAttributesFromAnchorElement(dataAttributes);
856
- });
857
- };
858
- const observer = new MutationObserver(observerCallback);
859
- const observerConfig = { attributes: true, childList: false, subtree: false };
860
- if (anchorElement) {
861
- const dataAttributes = getDataAttributesFromAnchorElement(anchorElement);
862
- applyAllDataAttributesFromAnchorElement(dataAttributes);
863
- observer.observe(anchorElement, observerConfig);
864
- }
865
- return () => {
866
- observer.disconnect();
867
- };
868
- }, [anchorRefs, providerActiveAnchor, activeAnchor, anchorId, anchorSelect]);
869
- let renderedContent = children;
870
- const contentRef = useRef3(null);
871
- if (render) {
872
- renderedContent = render({ ref: contentRef, content: tooltipContent != null ? tooltipContent : null, activeAnchor });
873
- } else if (tooltipContent) {
874
- renderedContent = tooltipContent;
875
- }
876
- if (tooltipHtml) {
877
- renderedContent = /* @__PURE__ */ jsx5(TooltipContent_default, { content: tooltipHtml });
878
- }
879
- const props = {
880
- id,
881
- anchorId,
882
- anchorSelect,
883
- className,
884
- classNameArrow,
885
- content: renderedContent,
886
- contentRef,
887
- place: tooltipPlace,
888
- variant: tooltipVariant,
889
- offset: tooltipOffset,
890
- wrapper: tooltipWrapper,
891
- events: tooltipEvents,
892
- openOnClick,
893
- positionStrategy: tooltipPositionStrategy,
894
- middlewares,
895
- delayShow: tooltipDelayShow,
896
- delayHide: tooltipDelayHide,
897
- float: tooltipFloat,
898
- noArrow,
899
- clickable,
900
- closeOnEsc,
901
- style,
902
- position,
903
- isOpen,
904
- setIsOpen,
905
- afterShow,
906
- afterHide,
907
- activeAnchor,
908
- setActiveAnchor: (anchor) => setActiveAnchor(anchor)
909
- };
910
- return /* @__PURE__ */ jsx5(Tooltip_default, { ...props });
911
- };
912
- var TooltipController_default = TooltipController;
913
- export {
914
- TooltipController_default as Tooltip,
915
- TooltipProvider_default as TooltipProvider,
916
- TooltipWrapper_default as TooltipWrapper
917
- };
918
- //# sourceMappingURL=react-tooltip.esm.js.map