react-tooltip 5.22.0-beta.1109.1 → 5.22.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.
- package/dist/react-tooltip-tokens.css +2 -0
- package/dist/react-tooltip.cjs +141 -127
- package/dist/react-tooltip.cjs.map +1 -1
- package/dist/react-tooltip.css +9 -4
- package/dist/react-tooltip.d.ts +35 -37
- package/dist/react-tooltip.min.cjs +2 -2
- package/dist/react-tooltip.min.cjs.map +1 -1
- package/dist/react-tooltip.min.css +1 -1
- package/dist/react-tooltip.min.mjs +2 -2
- package/dist/react-tooltip.min.mjs.map +1 -1
- package/dist/react-tooltip.mjs +142 -128
- package/dist/react-tooltip.mjs.map +1 -1
- package/dist/react-tooltip.umd.js +141 -127
- package/dist/react-tooltip.umd.js.map +1 -1
- package/dist/react-tooltip.umd.min.js +2 -2
- package/dist/react-tooltip.umd.min.js.map +1 -1
- package/package.json +1 -1
package/dist/react-tooltip.mjs
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @copyright ReactTooltip Team
|
|
6
6
|
* @license MIT
|
|
7
7
|
*/
|
|
8
|
-
import React, { createContext, useState, useCallback, useMemo, useContext, useRef, useEffect, useLayoutEffect
|
|
8
|
+
import React, { createContext, useState, useCallback, useMemo, useContext, useRef, useEffect, useLayoutEffect } from 'react';
|
|
9
9
|
import { arrow, computePosition, offset, flip, shift, autoUpdate } from '@floating-ui/dom';
|
|
10
10
|
import classNames from 'classnames';
|
|
11
11
|
|
|
@@ -318,16 +318,15 @@ const computeTooltipPosition = async ({ elementReference = null, tooltipReferenc
|
|
|
318
318
|
});
|
|
319
319
|
};
|
|
320
320
|
|
|
321
|
-
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"};
|
|
321
|
+
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"};
|
|
322
322
|
|
|
323
323
|
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"};
|
|
324
324
|
|
|
325
325
|
const Tooltip = ({
|
|
326
326
|
// props
|
|
327
|
-
|
|
327
|
+
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, openEvents, closeEvents, globalCloseEvents, style: externalStyles, position, afterShow, afterHide,
|
|
328
328
|
// props handled by controller
|
|
329
329
|
content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, border, opacity, arrowColor, }) => {
|
|
330
|
-
var _a;
|
|
331
330
|
const tooltipRef = useRef(null);
|
|
332
331
|
const tooltipArrowRef = useRef(null);
|
|
333
332
|
const tooltipShowDelayTimerRef = useRef(null);
|
|
@@ -337,7 +336,6 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
337
336
|
const [inlineArrowStyles, setInlineArrowStyles] = useState({});
|
|
338
337
|
const [show, setShow] = useState(false);
|
|
339
338
|
const [rendered, setRendered] = useState(false);
|
|
340
|
-
const [imperativeOptions, setImperativeOptions] = useState(null);
|
|
341
339
|
const wasShowing = useRef(false);
|
|
342
340
|
const lastFloatPosition = useRef(null);
|
|
343
341
|
/**
|
|
@@ -347,7 +345,48 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
347
345
|
const hoveringTooltip = useRef(false);
|
|
348
346
|
const [anchorsBySelect, setAnchorsBySelect] = useState([]);
|
|
349
347
|
const mounted = useRef(false);
|
|
348
|
+
/**
|
|
349
|
+
* @todo Update when deprecated stuff gets removed.
|
|
350
|
+
*/
|
|
350
351
|
const shouldOpenOnClick = openOnClick || events.includes('click');
|
|
352
|
+
const hasClickEvent = shouldOpenOnClick || (openEvents === null || openEvents === void 0 ? void 0 : openEvents.click) || (openEvents === null || openEvents === void 0 ? void 0 : openEvents.dblclick) || (openEvents === null || openEvents === void 0 ? void 0 : openEvents.mousedown);
|
|
353
|
+
const actualOpenEvents = openEvents
|
|
354
|
+
? { ...openEvents }
|
|
355
|
+
: {
|
|
356
|
+
mouseenter: true,
|
|
357
|
+
focus: true,
|
|
358
|
+
click: false,
|
|
359
|
+
dblclick: false,
|
|
360
|
+
mousedown: false,
|
|
361
|
+
};
|
|
362
|
+
if (!openEvents && shouldOpenOnClick) {
|
|
363
|
+
Object.assign(actualOpenEvents, {
|
|
364
|
+
mouseenter: false,
|
|
365
|
+
focus: false,
|
|
366
|
+
click: true,
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
const actualCloseEvents = closeEvents
|
|
370
|
+
? { ...closeEvents }
|
|
371
|
+
: {
|
|
372
|
+
mouseleave: true,
|
|
373
|
+
blur: true,
|
|
374
|
+
click: false,
|
|
375
|
+
};
|
|
376
|
+
if (!closeEvents && shouldOpenOnClick) {
|
|
377
|
+
Object.assign(actualCloseEvents, {
|
|
378
|
+
mouseleave: false,
|
|
379
|
+
blur: false,
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
const actualGlobalCloseEvents = globalCloseEvents
|
|
383
|
+
? { ...globalCloseEvents }
|
|
384
|
+
: {
|
|
385
|
+
escape: closeOnEsc || false,
|
|
386
|
+
scroll: closeOnScroll || false,
|
|
387
|
+
resize: closeOnResize || false,
|
|
388
|
+
clickOutsideAnchor: hasClickEvent || false,
|
|
389
|
+
};
|
|
351
390
|
/**
|
|
352
391
|
* useLayoutEffect runs before useEffect,
|
|
353
392
|
* but should be used carefully because of caveats
|
|
@@ -359,23 +398,6 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
359
398
|
mounted.current = false;
|
|
360
399
|
};
|
|
361
400
|
}, []);
|
|
362
|
-
useEffect(() => {
|
|
363
|
-
if (!show) {
|
|
364
|
-
/**
|
|
365
|
-
* this fixes weird behavior when switching between two anchor elements very quickly
|
|
366
|
-
* remove the timeout and switch quickly between two adjancent anchor elements to see it
|
|
367
|
-
*
|
|
368
|
-
* in practice, this means the tooltip is not immediately removed from the DOM on hide
|
|
369
|
-
*/
|
|
370
|
-
const timeout = setTimeout(() => {
|
|
371
|
-
setRendered(false);
|
|
372
|
-
}, 150);
|
|
373
|
-
return () => {
|
|
374
|
-
clearTimeout(timeout);
|
|
375
|
-
};
|
|
376
|
-
}
|
|
377
|
-
return () => null;
|
|
378
|
-
}, [show]);
|
|
379
401
|
const handleShow = (value) => {
|
|
380
402
|
if (!mounted.current) {
|
|
381
403
|
return;
|
|
@@ -424,17 +446,16 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
424
446
|
afterShow === null || afterShow === void 0 ? void 0 : afterShow();
|
|
425
447
|
}
|
|
426
448
|
else {
|
|
427
|
-
setImperativeOptions(null);
|
|
428
449
|
afterHide === null || afterHide === void 0 ? void 0 : afterHide();
|
|
429
450
|
}
|
|
430
451
|
}, [show]);
|
|
431
|
-
const handleShowTooltipDelayed = (
|
|
452
|
+
const handleShowTooltipDelayed = () => {
|
|
432
453
|
if (tooltipShowDelayTimerRef.current) {
|
|
433
454
|
clearTimeout(tooltipShowDelayTimerRef.current);
|
|
434
455
|
}
|
|
435
456
|
tooltipShowDelayTimerRef.current = setTimeout(() => {
|
|
436
457
|
handleShow(true);
|
|
437
|
-
},
|
|
458
|
+
}, delayShow);
|
|
438
459
|
};
|
|
439
460
|
const handleHideTooltipDelayed = (delay = delayHide) => {
|
|
440
461
|
if (tooltipHideDelayTimerRef.current) {
|
|
@@ -490,7 +511,6 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
490
511
|
}
|
|
491
512
|
};
|
|
492
513
|
const handleTooltipPosition = ({ x, y }) => {
|
|
493
|
-
var _a;
|
|
494
514
|
const virtualElement = {
|
|
495
515
|
getBoundingClientRect() {
|
|
496
516
|
return {
|
|
@@ -506,7 +526,7 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
506
526
|
},
|
|
507
527
|
};
|
|
508
528
|
computeTooltipPosition({
|
|
509
|
-
place
|
|
529
|
+
place,
|
|
510
530
|
offset,
|
|
511
531
|
elementReference: virtualElement,
|
|
512
532
|
tooltipReference: tooltipRef.current,
|
|
@@ -536,17 +556,8 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
536
556
|
handleTooltipPosition(mousePosition);
|
|
537
557
|
lastFloatPosition.current = mousePosition;
|
|
538
558
|
};
|
|
539
|
-
const handleClickTooltipAnchor = (event) => {
|
|
540
|
-
handleShowTooltip(event);
|
|
541
|
-
if (delayHide) {
|
|
542
|
-
handleHideTooltipDelayed();
|
|
543
|
-
}
|
|
544
|
-
};
|
|
545
559
|
const handleClickOutsideAnchors = (event) => {
|
|
546
560
|
var _a;
|
|
547
|
-
if (!show) {
|
|
548
|
-
return;
|
|
549
|
-
}
|
|
550
561
|
const anchorById = document.querySelector(`[id='${anchorId}']`);
|
|
551
562
|
const anchors = [anchorById, ...anchorsBySelect];
|
|
552
563
|
if (anchors.some((anchor) => anchor === null || anchor === void 0 ? void 0 : anchor.contains(event.target))) {
|
|
@@ -565,11 +576,9 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
565
576
|
const debouncedHandleShowTooltip = debounce(handleShowTooltip, 50, true);
|
|
566
577
|
const debouncedHandleHideTooltip = debounce(handleHideTooltip, 50, true);
|
|
567
578
|
const updateTooltipPosition = useCallback(() => {
|
|
568
|
-
|
|
569
|
-
const actualPosition = (_a = imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.position) !== null && _a !== void 0 ? _a : position;
|
|
570
|
-
if (actualPosition) {
|
|
579
|
+
if (position) {
|
|
571
580
|
// if `position` is set, override regular and `float` positioning
|
|
572
|
-
handleTooltipPosition(
|
|
581
|
+
handleTooltipPosition(position);
|
|
573
582
|
return;
|
|
574
583
|
}
|
|
575
584
|
if (float) {
|
|
@@ -590,7 +599,7 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
590
599
|
return;
|
|
591
600
|
}
|
|
592
601
|
computeTooltipPosition({
|
|
593
|
-
place
|
|
602
|
+
place,
|
|
594
603
|
offset,
|
|
595
604
|
elementReference: activeAnchor,
|
|
596
605
|
tooltipReference: tooltipRef.current,
|
|
@@ -617,11 +626,9 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
617
626
|
content,
|
|
618
627
|
externalStyles,
|
|
619
628
|
place,
|
|
620
|
-
imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.place,
|
|
621
629
|
offset,
|
|
622
630
|
positionStrategy,
|
|
623
631
|
position,
|
|
624
|
-
imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.position,
|
|
625
632
|
float,
|
|
626
633
|
]);
|
|
627
634
|
useEffect(() => {
|
|
@@ -639,13 +646,13 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
639
646
|
};
|
|
640
647
|
const anchorScrollParent = getScrollParent(activeAnchor);
|
|
641
648
|
const tooltipScrollParent = getScrollParent(tooltipRef.current);
|
|
642
|
-
if (
|
|
649
|
+
if (actualGlobalCloseEvents.scroll) {
|
|
643
650
|
window.addEventListener('scroll', handleScrollResize);
|
|
644
651
|
anchorScrollParent === null || anchorScrollParent === void 0 ? void 0 : anchorScrollParent.addEventListener('scroll', handleScrollResize);
|
|
645
652
|
tooltipScrollParent === null || tooltipScrollParent === void 0 ? void 0 : tooltipScrollParent.addEventListener('scroll', handleScrollResize);
|
|
646
653
|
}
|
|
647
654
|
let updateTooltipCleanup = null;
|
|
648
|
-
if (
|
|
655
|
+
if (actualGlobalCloseEvents.resize) {
|
|
649
656
|
window.addEventListener('resize', handleScrollResize);
|
|
650
657
|
}
|
|
651
658
|
else if (activeAnchor && tooltipRef.current) {
|
|
@@ -661,22 +668,56 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
661
668
|
}
|
|
662
669
|
handleShow(false);
|
|
663
670
|
};
|
|
664
|
-
if (
|
|
671
|
+
if (actualGlobalCloseEvents.escape) {
|
|
665
672
|
window.addEventListener('keydown', handleEsc);
|
|
666
673
|
}
|
|
667
|
-
|
|
668
|
-
if (shouldOpenOnClick) {
|
|
674
|
+
if (actualGlobalCloseEvents.clickOutsideAnchor) {
|
|
669
675
|
window.addEventListener('click', handleClickOutsideAnchors);
|
|
670
|
-
enabledEvents.push({ event: 'click', listener: handleClickTooltipAnchor });
|
|
671
676
|
}
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
if (
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
677
|
+
const enabledEvents = [];
|
|
678
|
+
const handleClickOpenTooltipAnchor = (event) => {
|
|
679
|
+
if (show) {
|
|
680
|
+
return;
|
|
681
|
+
}
|
|
682
|
+
handleShowTooltip(event);
|
|
683
|
+
};
|
|
684
|
+
const handleClickCloseTooltipAnchor = () => {
|
|
685
|
+
if (!show) {
|
|
686
|
+
return;
|
|
687
|
+
}
|
|
688
|
+
handleHideTooltip();
|
|
689
|
+
};
|
|
690
|
+
const regularEvents = ['mouseenter', 'mouseleave', 'focus', 'blur'];
|
|
691
|
+
const clickEvents = ['click', 'dblclick', 'mousedown', 'mouseup'];
|
|
692
|
+
Object.entries(actualOpenEvents).forEach(([event, enabled]) => {
|
|
693
|
+
if (!enabled) {
|
|
694
|
+
return;
|
|
679
695
|
}
|
|
696
|
+
if (regularEvents.includes(event)) {
|
|
697
|
+
enabledEvents.push({ event, listener: debouncedHandleShowTooltip });
|
|
698
|
+
}
|
|
699
|
+
else if (clickEvents.includes(event)) {
|
|
700
|
+
enabledEvents.push({ event, listener: handleClickOpenTooltipAnchor });
|
|
701
|
+
}
|
|
702
|
+
else ;
|
|
703
|
+
});
|
|
704
|
+
Object.entries(actualCloseEvents).forEach(([event, enabled]) => {
|
|
705
|
+
if (!enabled) {
|
|
706
|
+
return;
|
|
707
|
+
}
|
|
708
|
+
if (regularEvents.includes(event)) {
|
|
709
|
+
enabledEvents.push({ event, listener: debouncedHandleHideTooltip });
|
|
710
|
+
}
|
|
711
|
+
else if (clickEvents.includes(event)) {
|
|
712
|
+
enabledEvents.push({ event, listener: handleClickCloseTooltipAnchor });
|
|
713
|
+
}
|
|
714
|
+
else ;
|
|
715
|
+
});
|
|
716
|
+
if (float) {
|
|
717
|
+
enabledEvents.push({
|
|
718
|
+
event: 'mousemove',
|
|
719
|
+
listener: handleMouseMove,
|
|
720
|
+
});
|
|
680
721
|
}
|
|
681
722
|
const handleMouseEnterTooltip = () => {
|
|
682
723
|
hoveringTooltip.current = true;
|
|
@@ -685,7 +726,9 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
685
726
|
hoveringTooltip.current = false;
|
|
686
727
|
handleHideTooltip();
|
|
687
728
|
};
|
|
688
|
-
if (clickable && !
|
|
729
|
+
if (clickable && !hasClickEvent) {
|
|
730
|
+
// used to keep the tooltip open when hovering content.
|
|
731
|
+
// not needed if using click events.
|
|
689
732
|
(_a = tooltipRef.current) === null || _a === void 0 ? void 0 : _a.addEventListener('mouseenter', handleMouseEnterTooltip);
|
|
690
733
|
(_b = tooltipRef.current) === null || _b === void 0 ? void 0 : _b.addEventListener('mouseleave', handleMouseLeaveTooltip);
|
|
691
734
|
}
|
|
@@ -697,24 +740,24 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
697
740
|
});
|
|
698
741
|
return () => {
|
|
699
742
|
var _a, _b;
|
|
700
|
-
if (
|
|
743
|
+
if (actualGlobalCloseEvents.scroll) {
|
|
701
744
|
window.removeEventListener('scroll', handleScrollResize);
|
|
702
745
|
anchorScrollParent === null || anchorScrollParent === void 0 ? void 0 : anchorScrollParent.removeEventListener('scroll', handleScrollResize);
|
|
703
746
|
tooltipScrollParent === null || tooltipScrollParent === void 0 ? void 0 : tooltipScrollParent.removeEventListener('scroll', handleScrollResize);
|
|
704
747
|
}
|
|
705
|
-
if (
|
|
748
|
+
if (actualGlobalCloseEvents.resize) {
|
|
706
749
|
window.removeEventListener('resize', handleScrollResize);
|
|
707
750
|
}
|
|
708
751
|
else {
|
|
709
752
|
updateTooltipCleanup === null || updateTooltipCleanup === void 0 ? void 0 : updateTooltipCleanup();
|
|
710
753
|
}
|
|
711
|
-
if (
|
|
754
|
+
if (actualGlobalCloseEvents.clickOutsideAnchor) {
|
|
712
755
|
window.removeEventListener('click', handleClickOutsideAnchors);
|
|
713
756
|
}
|
|
714
|
-
if (
|
|
757
|
+
if (actualGlobalCloseEvents.escape) {
|
|
715
758
|
window.removeEventListener('keydown', handleEsc);
|
|
716
759
|
}
|
|
717
|
-
if (clickable && !
|
|
760
|
+
if (clickable && !hasClickEvent) {
|
|
718
761
|
(_a = tooltipRef.current) === null || _a === void 0 ? void 0 : _a.removeEventListener('mouseenter', handleMouseEnterTooltip);
|
|
719
762
|
(_b = tooltipRef.current) === null || _b === void 0 ? void 0 : _b.removeEventListener('mouseleave', handleMouseLeaveTooltip);
|
|
720
763
|
}
|
|
@@ -735,12 +778,14 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
735
778
|
rendered,
|
|
736
779
|
anchorRefs,
|
|
737
780
|
anchorsBySelect,
|
|
738
|
-
|
|
739
|
-
|
|
781
|
+
// the effect uses the `actual*Events` objects, but this should work
|
|
782
|
+
openEvents,
|
|
783
|
+
closeEvents,
|
|
784
|
+
globalCloseEvents,
|
|
785
|
+
shouldOpenOnClick,
|
|
740
786
|
]);
|
|
741
787
|
useEffect(() => {
|
|
742
|
-
|
|
743
|
-
let selector = (_b = (_a = imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.anchorSelect) !== null && _a !== void 0 ? _a : anchorSelect) !== null && _b !== void 0 ? _b : '';
|
|
788
|
+
let selector = anchorSelect !== null && anchorSelect !== void 0 ? anchorSelect : '';
|
|
744
789
|
if (!selector && id) {
|
|
745
790
|
selector = `[data-tooltip-id='${id}']`;
|
|
746
791
|
}
|
|
@@ -813,7 +858,7 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
813
858
|
});
|
|
814
859
|
if (newAnchors.length || removedAnchors.length) {
|
|
815
860
|
setAnchorsBySelect((anchors) => [
|
|
816
|
-
...anchors.filter((anchor) => removedAnchors.includes(anchor)),
|
|
861
|
+
...anchors.filter((anchor) => !removedAnchors.includes(anchor)),
|
|
817
862
|
...newAnchors,
|
|
818
863
|
]);
|
|
819
864
|
}
|
|
@@ -829,7 +874,7 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
829
874
|
return () => {
|
|
830
875
|
documentObserver.disconnect();
|
|
831
876
|
};
|
|
832
|
-
}, [id, anchorSelect,
|
|
877
|
+
}, [id, anchorSelect, activeAnchor]);
|
|
833
878
|
useEffect(() => {
|
|
834
879
|
updateTooltipPosition();
|
|
835
880
|
}, [updateTooltipPosition]);
|
|
@@ -869,8 +914,7 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
869
914
|
};
|
|
870
915
|
}, []);
|
|
871
916
|
useEffect(() => {
|
|
872
|
-
|
|
873
|
-
let selector = (_a = imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.anchorSelect) !== null && _a !== void 0 ? _a : anchorSelect;
|
|
917
|
+
let selector = anchorSelect;
|
|
874
918
|
if (!selector && id) {
|
|
875
919
|
selector = `[data-tooltip-id='${id}']`;
|
|
876
920
|
}
|
|
@@ -881,65 +925,28 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
881
925
|
const anchors = Array.from(document.querySelectorAll(selector));
|
|
882
926
|
setAnchorsBySelect(anchors);
|
|
883
927
|
}
|
|
884
|
-
catch (
|
|
928
|
+
catch (_a) {
|
|
885
929
|
// warning was already issued in the controller
|
|
886
930
|
setAnchorsBySelect([]);
|
|
887
931
|
}
|
|
888
|
-
}, [id, anchorSelect
|
|
889
|
-
const
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
catch (_a) {
|
|
898
|
-
{
|
|
899
|
-
// eslint-disable-next-line no-console
|
|
900
|
-
console.warn(`[react-tooltip] "${options.anchorSelect}" is not a valid CSS selector`);
|
|
901
|
-
}
|
|
902
|
-
return;
|
|
903
|
-
}
|
|
904
|
-
}
|
|
905
|
-
setImperativeOptions(options !== null && options !== void 0 ? options : null);
|
|
906
|
-
if (options === null || options === void 0 ? void 0 : options.delay) {
|
|
907
|
-
handleShowTooltipDelayed(options.delay);
|
|
908
|
-
}
|
|
909
|
-
else {
|
|
910
|
-
handleShow(true);
|
|
911
|
-
}
|
|
912
|
-
},
|
|
913
|
-
close: (options) => {
|
|
914
|
-
if (options === null || options === void 0 ? void 0 : options.delay) {
|
|
915
|
-
handleHideTooltipDelayed(options.delay);
|
|
916
|
-
}
|
|
917
|
-
else {
|
|
918
|
-
handleShow(false);
|
|
932
|
+
}, [id, anchorSelect]);
|
|
933
|
+
const canShow = !hidden && content && show && Object.keys(inlineStyles).length > 0;
|
|
934
|
+
return rendered ? (React.createElement(WrapperElement, { id: id, role: "tooltip", className: classNames('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) => {
|
|
935
|
+
/**
|
|
936
|
+
* @warning if `--rt-transition-closing-delay` is set to 0,
|
|
937
|
+
* the tooltip will be stuck (but not visible) on the DOM
|
|
938
|
+
*/
|
|
939
|
+
if (show || event.propertyName !== 'opacity') {
|
|
940
|
+
return;
|
|
919
941
|
}
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
place: actualPlacement,
|
|
923
|
-
isOpen: rendered && canShow,
|
|
924
|
-
}));
|
|
925
|
-
return rendered ? (React.createElement(WrapperElement, { id: id, role: "tooltip", className: classNames('react-tooltip', coreStyles['tooltip'], styles['tooltip'], styles[variant], className, `react-tooltip__place-${actualPlacement}`, {
|
|
926
|
-
'react-tooltip__show': canShow,
|
|
927
|
-
[coreStyles['show']]: canShow,
|
|
928
|
-
[coreStyles['fixed']]: positionStrategy === 'fixed',
|
|
929
|
-
[coreStyles['clickable']]: clickable,
|
|
930
|
-
}), style: {
|
|
942
|
+
setRendered(false);
|
|
943
|
+
}, style: {
|
|
931
944
|
...externalStyles,
|
|
932
945
|
...inlineStyles,
|
|
933
946
|
opacity: opacity !== undefined && canShow ? opacity : undefined,
|
|
934
947
|
}, ref: tooltipRef },
|
|
935
|
-
|
|
936
|
-
React.createElement(WrapperElement, { className: classNames('react-tooltip-arrow', coreStyles['arrow'], styles['arrow'], classNameArrow, {
|
|
937
|
-
/**
|
|
938
|
-
* changed from dash `no-arrow` to camelcase because of:
|
|
939
|
-
* https://github.com/indooorsman/esbuild-css-modules-plugin/issues/42
|
|
940
|
-
*/
|
|
941
|
-
[coreStyles['noArrow']]: noArrow,
|
|
942
|
-
}), style: {
|
|
948
|
+
content,
|
|
949
|
+
React.createElement(WrapperElement, { className: classNames('react-tooltip-arrow', coreStyles['arrow'], styles['arrow'], classNameArrow, noArrow && coreStyles['noArrow']), style: {
|
|
943
950
|
...inlineArrowStyles,
|
|
944
951
|
background: arrowColor
|
|
945
952
|
? `linear-gradient(to right bottom, transparent 50%, ${arrowColor} 50%)`
|
|
@@ -952,7 +959,7 @@ const TooltipContent = ({ content }) => {
|
|
|
952
959
|
return React.createElement("span", { dangerouslySetInnerHTML: { __html: content } });
|
|
953
960
|
};
|
|
954
961
|
|
|
955
|
-
const TooltipController =
|
|
962
|
+
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, openEvents, closeEvents, globalCloseEvents, style, position, isOpen, disableStyleInjection = false, border, opacity, arrowColor, setIsOpen, afterShow, afterHide, }) => {
|
|
956
963
|
const [tooltipContent, setTooltipContent] = useState(content);
|
|
957
964
|
const [tooltipHtml, setTooltipHtml] = useState(html);
|
|
958
965
|
const [tooltipPlace, setTooltipPlace] = useState(place);
|
|
@@ -1176,7 +1183,6 @@ const TooltipController = React.forwardRef(({ id, anchorId, anchorSelect, conten
|
|
|
1176
1183
|
renderedContent = React.createElement(TooltipContent, { content: tooltipHtml });
|
|
1177
1184
|
}
|
|
1178
1185
|
const props = {
|
|
1179
|
-
forwardRef: ref,
|
|
1180
1186
|
id,
|
|
1181
1187
|
anchorId,
|
|
1182
1188
|
anchorSelect,
|
|
@@ -1201,6 +1207,9 @@ const TooltipController = React.forwardRef(({ id, anchorId, anchorSelect, conten
|
|
|
1201
1207
|
closeOnEsc,
|
|
1202
1208
|
closeOnScroll,
|
|
1203
1209
|
closeOnResize,
|
|
1210
|
+
openEvents,
|
|
1211
|
+
closeEvents,
|
|
1212
|
+
globalCloseEvents,
|
|
1204
1213
|
style,
|
|
1205
1214
|
position,
|
|
1206
1215
|
isOpen,
|
|
@@ -1214,7 +1223,7 @@ const TooltipController = React.forwardRef(({ id, anchorId, anchorSelect, conten
|
|
|
1214
1223
|
setActiveAnchor: (anchor) => setActiveAnchor(anchor),
|
|
1215
1224
|
};
|
|
1216
1225
|
return React.createElement(Tooltip, { ...props });
|
|
1217
|
-
}
|
|
1226
|
+
};
|
|
1218
1227
|
|
|
1219
1228
|
// those content will be replaced in build time with the `react-tooltip.css` builded content
|
|
1220
1229
|
const TooltipCoreStyles = `:root {
|
|
@@ -1225,17 +1234,17 @@ const TooltipCoreStyles = `:root {
|
|
|
1225
1234
|
--rt-color-warning: #f0ad4e;
|
|
1226
1235
|
--rt-color-info: #337ab7;
|
|
1227
1236
|
--rt-opacity: 0.9;
|
|
1237
|
+
--rt-transition-show-delay: 0.15s;
|
|
1238
|
+
--rt-transition-closing-delay: 0.15s;
|
|
1228
1239
|
}
|
|
1229
1240
|
|
|
1230
1241
|
.core-styles-module_tooltip__3vRRp {
|
|
1231
|
-
visibility: hidden;
|
|
1232
1242
|
position: absolute;
|
|
1233
1243
|
top: 0;
|
|
1234
1244
|
left: 0;
|
|
1235
1245
|
pointer-events: none;
|
|
1236
1246
|
opacity: 0;
|
|
1237
|
-
|
|
1238
|
-
will-change: opacity, visibility;
|
|
1247
|
+
will-change: opacity;
|
|
1239
1248
|
}
|
|
1240
1249
|
|
|
1241
1250
|
.core-styles-module_fixed__pcSol {
|
|
@@ -1256,8 +1265,13 @@ const TooltipCoreStyles = `:root {
|
|
|
1256
1265
|
}
|
|
1257
1266
|
|
|
1258
1267
|
.core-styles-module_show__Nt9eE {
|
|
1259
|
-
visibility: visible;
|
|
1260
1268
|
opacity: var(--rt-opacity);
|
|
1269
|
+
transition: opacity var(--rt-transition-show-delay) ease-out;
|
|
1270
|
+
}
|
|
1271
|
+
|
|
1272
|
+
.core-styles-module_closing__sGnxF {
|
|
1273
|
+
opacity: 0;
|
|
1274
|
+
transition: opacity var(--rt-transition-closing-delay) ease-in;
|
|
1261
1275
|
}
|
|
1262
1276
|
|
|
1263
1277
|
`;
|