react-tooltip 5.0.0-beta.2 → 5.1.0-beta.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/CONTRIBUTION.md +38 -0
- package/README.md +9 -4
- package/dist/react-tooltip.cjs.js +15 -5
- package/dist/react-tooltip.cjs.min.js +1 -1
- package/dist/react-tooltip.css +11 -13
- package/dist/react-tooltip.d.ts +17 -3
- package/dist/react-tooltip.esm.js +15 -5
- package/dist/react-tooltip.esm.min.js +2 -2
- package/dist/react-tooltip.min.css +1 -1
- package/dist/react-tooltip.umd.js +15 -5
- package/dist/react-tooltip.umd.min.js +1 -1
- package/package.json +2 -4
- package/rollup.config.types.js +6 -2
- package/src/App.tsx +79 -0
- package/src/components/Tooltip/Tooltip.tsx +191 -0
- package/src/components/Tooltip/TooltipTypes.d.ts +35 -0
- package/src/components/Tooltip/index.ts +1 -0
- package/src/components/Tooltip/styles.module.css +62 -0
- package/src/components/TooltipContent/TooltipContent.tsx +8 -0
- package/src/components/TooltipContent/TooltipContentTypes.d.ts +3 -0
- package/src/components/TooltipContent/index.ts +1 -0
- package/src/components/TooltipController/TooltipController.tsx +203 -0
- package/src/components/TooltipController/TooltipControllerTypes.d.ts +32 -0
- package/src/components/TooltipController/constants.ts +11 -0
- package/src/components/TooltipController/index.ts +1 -0
- package/src/index-dev.tsx +15 -0
- package/src/index.tsx +3 -0
- package/src/styles.module.css +5 -0
- package/src/test/__snapshots__/index.spec.js.snap +107 -0
- package/src/test/index.spec.js +142 -0
- package/src/tokens.css +8 -0
- package/src/utils/compute-positions-types.d.ts +8 -0
- package/src/utils/compute-positions.ts +66 -0
- package/src/utils/debounce.ts +32 -0
- package/.editorconfig +0 -25
- package/coverage/clover.xml +0 -610
- package/coverage/coverage-final.json +0 -11
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/components/Tooltip/Tooltip.tsx.html +0 -646
- package/coverage/lcov-report/components/Tooltip/index.html +0 -146
- package/coverage/lcov-report/components/Tooltip/index.ts.html +0 -88
- package/coverage/lcov-report/components/Tooltip/styles.module.css.html +0 -277
- package/coverage/lcov-report/components/TooltipContent/TooltipContent.tsx.html +0 -109
- package/coverage/lcov-report/components/TooltipContent/index.html +0 -131
- package/coverage/lcov-report/components/TooltipContent/index.ts.html +0 -88
- package/coverage/lcov-report/components/TooltipController/TooltipController.tsx.html +0 -664
- package/coverage/lcov-report/components/TooltipController/constants.ts.html +0 -118
- package/coverage/lcov-report/components/TooltipController/index.html +0 -146
- package/coverage/lcov-report/components/TooltipController/index.ts.html +0 -88
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -161
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -196
- package/coverage/lcov-report/sum.js.html +0 -97
- package/coverage/lcov-report/sum.ts.html +0 -100
- package/coverage/lcov-report/test/index.html +0 -116
- package/coverage/lcov-report/test/sum.ts.html +0 -100
- package/coverage/lcov-report/utils/compute-positions.ts.html +0 -277
- package/coverage/lcov-report/utils/debounce.ts.html +0 -181
- package/coverage/lcov-report/utils/index.html +0 -131
- package/coverage/lcov.info +0 -729
|
@@ -1 +1 @@
|
|
|
1
|
-
:root{--rt-color-white:#fff;--rt-color-dark:#222;--rt-color-success:#8dc572;--rt-color-error:#be6464;--rt-color-warning:#f0ad4e;--rt-color-info:#337ab7}.styles-module_tooltip__mnnfp{border-radius:3px;font-size:90%;left:0;opacity:0;padding:8px 16px;pointer-events:none;position:absolute;top:0;transition:opacity .3s ease-out;visibility:hidden;width:max-content;will-change:opacity,visibility}.styles-module_arrow__K0L3T{background:
|
|
1
|
+
:root{--rt-color-white:#fff;--rt-color-dark:#222;--rt-color-success:#8dc572;--rt-color-error:#be6464;--rt-color-warning:#f0ad4e;--rt-color-info:#337ab7}.styles-module_tooltip__mnnfp{border-radius:3px;font-size:90%;left:0;opacity:0;padding:8px 16px;pointer-events:none;position:absolute;top:0;transition:opacity .3s ease-out;visibility:hidden;width:max-content;will-change:opacity,visibility}.styles-module_fixed__7ciUi{position:fixed}.styles-module_arrow__K0L3T{background:inherit;height:8px;position:absolute;transform:rotate(45deg);width:8px}.styles-module_show__2NboJ{opacity:.9;visibility:visible}.styles-module_dark__xNqje{background:var(--rt-color-dark);color:var(--rt-color-white)}.styles-module_light__Z6W-X{background-color:var(--rt-color-white);color:var(--rt-color-dark)}.styles-module_success__A2AKt{background-color:var(--rt-color-success);color:var(--rt-color-white)}.styles-module_warning__SCK0X{background-color:var(--rt-color-warning);color:var(--rt-color-white)}.styles-module_error__JvumD{background-color:var(--rt-color-error);color:var(--rt-color-white)}.styles-module_info__BWdHW{background-color:var(--rt-color-info);color:var(--rt-color-white)}
|
|
@@ -2608,7 +2608,7 @@
|
|
|
2608
2608
|
...options
|
|
2609
2609
|
});
|
|
2610
2610
|
|
|
2611
|
-
const computeToolTipPosition = async ({ elementReference = null, tooltipReference = null, tooltipArrowReference = null, place = 'top', offset: offsetValue = 10, }) => {
|
|
2611
|
+
const computeToolTipPosition = async ({ elementReference = null, tooltipReference = null, tooltipArrowReference = null, place = 'top', offset: offsetValue = 10, strategy = 'absolute', }) => {
|
|
2612
2612
|
if (!elementReference) {
|
|
2613
2613
|
// elementReference can be null or undefined and we will not compute the position
|
|
2614
2614
|
// eslint-disable-next-line no-console
|
|
@@ -2623,6 +2623,7 @@
|
|
|
2623
2623
|
middleware.push(arrow({ element: tooltipArrowReference }));
|
|
2624
2624
|
return computePosition(elementReference, tooltipReference, {
|
|
2625
2625
|
placement: place,
|
|
2626
|
+
strategy,
|
|
2626
2627
|
middleware,
|
|
2627
2628
|
}).then(({ x, y, placement, middlewareData }) => {
|
|
2628
2629
|
const styles = { left: `${x}px`, top: `${y}px` };
|
|
@@ -2647,6 +2648,7 @@
|
|
|
2647
2648
|
}
|
|
2648
2649
|
return computePosition(elementReference, tooltipReference, {
|
|
2649
2650
|
placement: 'bottom',
|
|
2651
|
+
strategy,
|
|
2650
2652
|
middleware,
|
|
2651
2653
|
}).then(({ x, y }) => {
|
|
2652
2654
|
const styles = { left: `${x}px`, top: `${y}px` };
|
|
@@ -2654,11 +2656,11 @@
|
|
|
2654
2656
|
});
|
|
2655
2657
|
};
|
|
2656
2658
|
|
|
2657
|
-
var styles = {"tooltip":"styles-module_tooltip__mnnfp","arrow":"styles-module_arrow__K0L3T","show":"styles-module_show__2NboJ","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"};
|
|
2659
|
+
var styles = {"tooltip":"styles-module_tooltip__mnnfp","fixed":"styles-module_fixed__7ciUi","arrow":"styles-module_arrow__K0L3T","show":"styles-module_show__2NboJ","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"};
|
|
2658
2660
|
|
|
2659
2661
|
const Tooltip = ({
|
|
2660
2662
|
// props
|
|
2661
|
-
id = require$$0.useId(), className, classNameArrow, variant = 'dark', anchorId, place = 'top', offset = 10, events = ['hover'], wrapper: WrapperElement = 'div', children = null, delayShow = 0, delayHide = 0,
|
|
2663
|
+
id = require$$0.useId(), className, classNameArrow, variant = 'dark', anchorId, place = 'top', offset = 10, events = ['hover'], positionStrategy = 'absolute', wrapper: WrapperElement = 'div', children = null, delayShow = 0, delayHide = 0, style: externalStyles,
|
|
2662
2664
|
// props handled by controller
|
|
2663
2665
|
isHtmlContent = false, content, isOpen, setIsOpen, }) => {
|
|
2664
2666
|
const tooltipRef = require$$0.createRef();
|
|
@@ -2763,6 +2765,7 @@
|
|
|
2763
2765
|
elementReference,
|
|
2764
2766
|
tooltipReference: tooltipRef.current,
|
|
2765
2767
|
tooltipArrowReference: tooltipArrowRef.current,
|
|
2768
|
+
strategy: positionStrategy,
|
|
2766
2769
|
}).then((computedStylesData) => {
|
|
2767
2770
|
if (Object.keys(computedStylesData.tooltipStyles).length) {
|
|
2768
2771
|
setInlineStyles(computedStylesData.tooltipStyles);
|
|
@@ -2778,7 +2781,8 @@
|
|
|
2778
2781
|
}, [show, isOpen, anchorId]);
|
|
2779
2782
|
return (jsxRuntime.exports.jsxs(WrapperElement, { id: id, role: "tooltip", className: classNames(styles['tooltip'], styles[variant], className, {
|
|
2780
2783
|
[styles['show']]: isOpen || show,
|
|
2781
|
-
|
|
2784
|
+
[styles['fixed']]: positionStrategy === 'fixed',
|
|
2785
|
+
}), style: { ...externalStyles, ...inlineStyles }, ref: tooltipRef, children: [children || (isHtmlContent ? jsxRuntime.exports.jsx(TooltipContent, { content: content }) : content), jsxRuntime.exports.jsx("div", { className: classNames(styles['arrow'], classNameArrow), style: inlineArrowStyles, ref: tooltipArrowRef })] }));
|
|
2782
2786
|
};
|
|
2783
2787
|
|
|
2784
2788
|
const dataAttributesKeys = [
|
|
@@ -2793,7 +2797,7 @@
|
|
|
2793
2797
|
'delay-hide', // delay to hide tooltip
|
|
2794
2798
|
];
|
|
2795
2799
|
|
|
2796
|
-
const TooltipController = ({ id, anchorId, content, html, className, classNameArrow, variant = 'dark', place = 'top', offset = 10, wrapper = 'div', children = null, events = ['hover'], delayShow = 0, delayHide = 0, getContent, isOpen, setIsOpen, }) => {
|
|
2800
|
+
const TooltipController = ({ id, anchorId, content, html, className, classNameArrow, variant = 'dark', place = 'top', offset = 10, wrapper = 'div', children = null, events = ['hover'], positionStrategy = 'absolute', delayShow = 0, delayHide = 0, style, getContent, isOpen, setIsOpen, }) => {
|
|
2797
2801
|
const [tooltipContent, setTooltipContent] = require$$0.useState(content || html);
|
|
2798
2802
|
const [tooltipPlace, setTooltipPlace] = require$$0.useState(place);
|
|
2799
2803
|
const [tooltipVariant, setTooltipVariant] = require$$0.useState(variant);
|
|
@@ -2802,6 +2806,7 @@
|
|
|
2802
2806
|
const [tooltipDelayHide, setTooltipDelayHide] = require$$0.useState(delayHide);
|
|
2803
2807
|
const [tooltipWrapper, setTooltipWrapper] = require$$0.useState(wrapper);
|
|
2804
2808
|
const [tooltipEvents, setTooltipEvents] = require$$0.useState(events);
|
|
2809
|
+
const [tooltipPositionStrategy, setTooltipPositionStrategy] = require$$0.useState(positionStrategy);
|
|
2805
2810
|
const [isHtmlContent, setIsHtmlContent] = require$$0.useState(Boolean(html));
|
|
2806
2811
|
const getDataAttributesFromAnchorElement = (elementReference) => {
|
|
2807
2812
|
const dataAttributes = elementReference === null || elementReference === void 0 ? void 0 : elementReference.getAttributeNames().reduce((acc, name) => {
|
|
@@ -2850,6 +2855,9 @@
|
|
|
2850
2855
|
const parsedEvents = value.split(' ');
|
|
2851
2856
|
setTooltipEvents(parsedEvents);
|
|
2852
2857
|
},
|
|
2858
|
+
positionStrategy: (value) => {
|
|
2859
|
+
setTooltipPositionStrategy(value);
|
|
2860
|
+
},
|
|
2853
2861
|
'delay-show': (value) => {
|
|
2854
2862
|
setTooltipDelayShow(Number(value));
|
|
2855
2863
|
},
|
|
@@ -2918,8 +2926,10 @@
|
|
|
2918
2926
|
offset: tooltipOffset,
|
|
2919
2927
|
wrapper: tooltipWrapper,
|
|
2920
2928
|
events: tooltipEvents,
|
|
2929
|
+
positionStrategy: tooltipPositionStrategy,
|
|
2921
2930
|
delayShow: tooltipDelayShow,
|
|
2922
2931
|
delayHide: tooltipDelayHide,
|
|
2932
|
+
style,
|
|
2923
2933
|
isOpen,
|
|
2924
2934
|
setIsOpen,
|
|
2925
2935
|
};
|
|
@@ -3,4 +3,4 @@
|
|
|
3
3
|
Copyright (c) 2018 Jed Watson.
|
|
4
4
|
Licensed under the MIT License (MIT), see
|
|
5
5
|
http://jedwatson.github.io/classnames
|
|
6
|
-
*/!function(e){!function(){var t={}.hasOwnProperty;function n(){for(var e=[],r=0;r<arguments.length;r++){var o=arguments[r];if(o){var i=typeof o;if("string"===i||"number"===i)e.push(o);else if(Array.isArray(o)){if(o.length){var a=n.apply(null,o);a&&e.push(a)}}else if("object"===i){if(o.toString!==Object.prototype.toString&&!o.toString.toString().includes("[native code]")){e.push(o.toString());continue}for(var l in o)t.call(o,l)&&o[l]&&e.push(l)}}}return e.join(" ")}e.exports?(n.default=n,e.exports=n):window.classNames=n}()}(a);var l=a.exports;const s=(e,t,n)=>{let r;return function(){const o=this,i=arguments,a=()=>{r=null,n||e.apply(o,i)};clearTimeout(r),r=setTimeout(a,t)}},c=({content:e})=>o.exports.jsx("span",{dangerouslySetInnerHTML:{__html:e}});function u(e){return e.split("-")[0]}function f(e){return e.split("-")[1]}function p(e){return["top","bottom"].includes(u(e))?"x":"y"}function d(e){return"y"===e?"height":"width"}function y(e,t,n){let{reference:r,floating:o}=e;const i=r.x+r.width/2-o.width/2,a=r.y+r.height/2-o.height/2,l=p(t),s=d(l),c=r[s]/2-o[s]/2,y="x"===l;let m;switch(u(t)){case"top":m={x:i,y:r.y-o.height};break;case"bottom":m={x:i,y:r.y+r.height};break;case"right":m={x:r.x+r.width,y:a};break;case"left":m={x:r.x-o.width,y:a};break;default:m={x:r.x,y:r.y}}switch(f(t)){case"start":m[l]-=c*(n&&y?-1:1);break;case"end":m[l]+=c*(n&&y?-1:1)}return m}function m(e){return"number"!=typeof e?function(e){return{top:0,right:0,bottom:0,left:0,...e}}(e):{top:e,right:e,bottom:e,left:e}}function h(e){return{...e,top:e.y,left:e.x,right:e.x+e.width,bottom:e.y+e.height}}async function g(e,t){var n;void 0===t&&(t={});const{x:r,y:o,platform:i,rects:a,elements:l,strategy:s}=e,{boundary:c="clippingAncestors",rootBoundary:u="viewport",elementContext:f="floating",altBoundary:p=!1,padding:d=0}=t,y=m(d),g=l[p?"floating"===f?"reference":"floating":f],v=h(await i.getClippingRect({element:null==(n=await(null==i.isElement?void 0:i.isElement(g)))||n?g:g.contextElement||await(null==i.getDocumentElement?void 0:i.getDocumentElement(l.floating)),boundary:c,rootBoundary:u,strategy:s})),b=h(i.convertOffsetParentRelativeRectToViewportRelativeRect?await i.convertOffsetParentRelativeRectToViewportRelativeRect({rect:"floating"===f?{...a.floating,x:r,y:o}:a.reference,offsetParent:await(null==i.getOffsetParent?void 0:i.getOffsetParent(l.floating)),strategy:s}):a[f]);return{top:v.top-b.top+y.top,bottom:b.bottom-v.bottom+y.bottom,left:v.left-b.left+y.left,right:b.right-v.right+y.right}}const v=Math.min,b=Math.max;function w(e,t,n){return b(e,v(t,n))}const x={left:"right",right:"left",bottom:"top",top:"bottom"};function S(e){return e.replace(/left|right|bottom|top/g,(e=>x[e]))}const _={start:"end",end:"start"};function R(e){return e.replace(/start|end/g,(e=>_[e]))}const k=function(e){return void 0===e&&(e={}),{name:"flip",options:e,async fn(t){var n;const{placement:r,middlewareData:o,rects:i,initialPlacement:a,platform:l,elements:s}=t,{mainAxis:c=!0,crossAxis:y=!0,fallbackPlacements:m,fallbackStrategy:h="bestFit",flipAlignment:v=!0,...b}=e,w=u(r),x=m||(w===a||!v?[S(a)]:function(e){const t=S(e);return[R(e),t,R(t)]}(a)),_=[a,...x],k=await g(t,b),T=[];let j=(null==(n=o.flip)?void 0:n.overflows)||[];if(c&&T.push(k[w]),y){const{main:e,cross:t}=function(e,t,n){void 0===n&&(n=!1);const r=f(e),o=p(e),i=d(o);let a="x"===o?r===(n?"end":"start")?"right":"left":"start"===r?"bottom":"top";return t.reference[i]>t.floating[i]&&(a=S(a)),{main:a,cross:S(a)}}(r,i,await(null==l.isRTL?void 0:l.isRTL(s.floating)));T.push(k[e],k[t])}if(j=[...j,{placement:r,overflows:T}],!T.every((e=>e<=0))){var O,E;const e=(null!=(O=null==(E=o.flip)?void 0:E.index)?O:0)+1,t=_[e];if(t)return{data:{index:e,overflows:j},reset:{placement:t}};let n="bottom";switch(h){case"bestFit":{var P;const e=null==(P=j.map((e=>[e,e.overflows.filter((e=>e>0)).reduce(((e,t)=>e+t),0)])).sort(((e,t)=>e[1]-t[1]))[0])?void 0:P[0].placement;e&&(n=e);break}case"initialPlacement":n=a}if(r!==n)return{reset:{placement:n}}}return{}}}};const T=function(e){return void 0===e&&(e=0),{name:"offset",options:e,async fn(t){const{x:n,y:r}=t,o=await async function(e,t){const{placement:n,platform:r,elements:o}=e,i=await(null==r.isRTL?void 0:r.isRTL(o.floating)),a=u(n),l=f(n),s="x"===p(n),c=["left","top"].includes(a)?-1:1,d=i&&s?-1:1,y="function"==typeof t?t(e):t;let{mainAxis:m,crossAxis:h,alignmentAxis:g}="number"==typeof y?{mainAxis:y,crossAxis:0,alignmentAxis:null}:{mainAxis:0,crossAxis:0,alignmentAxis:null,...y};return l&&"number"==typeof g&&(h="end"===l?-1*g:g),s?{x:h*d,y:m*c}:{x:m*c,y:h*d}}(t,e);return{x:n+o.x,y:r+o.y,data:o}}}};function j(e){return e&&e.document&&e.location&&e.alert&&e.setInterval}function O(e){if(null==e)return window;if(!j(e)){const t=e.ownerDocument;return t&&t.defaultView||window}return e}function E(e){return O(e).getComputedStyle(e)}function P(e){return j(e)?"":e?(e.nodeName||"").toLowerCase():""}function A(){const e=navigator.userAgentData;return null!=e&&e.brands?e.brands.map((e=>e.brand+"/"+e.version)).join(" "):navigator.userAgent}function N(e){return e instanceof O(e).HTMLElement}function L(e){return e instanceof O(e).Element}function C(e){if("undefined"==typeof ShadowRoot)return!1;return e instanceof O(e).ShadowRoot||e instanceof ShadowRoot}function $(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=E(e);return/auto|scroll|overlay|hidden/.test(t+r+n)&&!["inline","contents"].includes(o)}function D(e){return["table","td","th"].includes(P(e))}function F(e){const t=/firefox/i.test(A()),n=E(e),r=n.backdropFilter||n.WebkitBackdropFilter;return"none"!==n.transform||"none"!==n.perspective||!!r&&"none"!==r||t&&"filter"===n.willChange||t&&!!n.filter&&"none"!==n.filter||["transform","perspective"].some((e=>n.willChange.includes(e)))||["paint","layout","strict","content"].some((e=>{const t=n.contain;return null!=t&&t.includes(e)}))}function I(){return!/^((?!chrome|android).)*safari/i.test(A())}function W(e){return["html","body","#document"].includes(P(e))}const H=Math.min,M=Math.max,U=Math.round;function B(e,t,n){var r,o,i,a;void 0===t&&(t=!1),void 0===n&&(n=!1);const l=e.getBoundingClientRect();let s=1,c=1;t&&N(e)&&(s=e.offsetWidth>0&&U(l.width)/e.offsetWidth||1,c=e.offsetHeight>0&&U(l.height)/e.offsetHeight||1);const u=L(e)?O(e):window,f=!I()&&n,p=(l.left+(f&&null!=(r=null==(o=u.visualViewport)?void 0:o.offsetLeft)?r:0))/s,d=(l.top+(f&&null!=(i=null==(a=u.visualViewport)?void 0:a.offsetTop)?i:0))/c,y=l.width/s,m=l.height/c;return{width:y,height:m,top:d,right:p+y,bottom:d+m,left:p,x:p,y:d}}function V(e){return(t=e,(t instanceof O(t).Node?e.ownerDocument:e.document)||window.document).documentElement;var t}function q(e){return L(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.pageXOffset,scrollTop:e.pageYOffset}}function z(e){return B(V(e)).left+q(e).scrollLeft}function Y(e,t,n){const r=N(t),o=V(t),i=B(e,r&&function(e){const t=B(e);return U(t.width)!==e.offsetWidth||U(t.height)!==e.offsetHeight}(t),"fixed"===n);let a={scrollLeft:0,scrollTop:0};const l={x:0,y:0};if(r||!r&&"fixed"!==n)if(("body"!==P(t)||$(o))&&(a=q(t)),N(t)){const e=B(t,!0);l.x=e.x+t.clientLeft,l.y=e.y+t.clientTop}else o&&(l.x=z(o));return{x:i.left+a.scrollLeft-l.x,y:i.top+a.scrollTop-l.y,width:i.width,height:i.height}}function X(e){if("html"===P(e))return e;const t=e.assignedSlot||e.parentNode||(C(e)?e.host:null)||V(e);return C(t)?t.host:t}function J(e){return N(e)&&"fixed"!==E(e).position?e.offsetParent:null}function K(e){const t=O(e);let n=J(e);for(;n&&D(n)&&"static"===E(n).position;)n=J(n);return n&&("html"===P(n)||"body"===P(n)&&"static"===E(n).position&&!F(n))?t:n||function(e){let t=X(e);for(;N(t)&&!W(t);){if(F(t))return t;t=X(t)}return null}(e)||t}function Z(e){if(N(e))return{width:e.offsetWidth,height:e.offsetHeight};const t=B(e);return{width:t.width,height:t.height}}function G(e){const t=X(e);return W(t)?e.ownerDocument.body:N(t)&&$(t)?t:G(t)}function Q(e,t){var n;void 0===t&&(t=[]);const r=G(e),o=r===(null==(n=e.ownerDocument)?void 0:n.body),i=O(r),a=o?[i].concat(i.visualViewport||[],$(r)?r:[]):r,l=t.concat(a);return o?l:l.concat(Q(a))}function ee(e,t,n){return"viewport"===t?h(function(e,t){const n=O(e),r=V(e),o=n.visualViewport;let i=r.clientWidth,a=r.clientHeight,l=0,s=0;if(o){i=o.width,a=o.height;const e=I();(e||!e&&"fixed"===t)&&(l=o.offsetLeft,s=o.offsetTop)}return{width:i,height:a,x:l,y:s}}(e,n)):L(t)?function(e,t){const n=B(e,!1,"fixed"===t),r=n.top+e.clientTop,o=n.left+e.clientLeft;return{top:r,left:o,x:o,y:r,right:o+e.clientWidth,bottom:r+e.clientHeight,width:e.clientWidth,height:e.clientHeight}}(t,n):h(function(e){var t;const n=V(e),r=q(e),o=null==(t=e.ownerDocument)?void 0:t.body,i=M(n.scrollWidth,n.clientWidth,o?o.scrollWidth:0,o?o.clientWidth:0),a=M(n.scrollHeight,n.clientHeight,o?o.scrollHeight:0,o?o.clientHeight:0);let l=-r.scrollLeft+z(e);const s=-r.scrollTop;return"rtl"===E(o||n).direction&&(l+=M(n.clientWidth,o?o.clientWidth:0)-i),{width:i,height:a,x:l,y:s}}(V(e)))}const te={getClippingRect:function(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i="clippingAncestors"===n?function(e){let t=Q(e).filter((e=>L(e)&&"body"!==P(e))),n=e,r=null;for(;L(n)&&!W(n);){const e=E(n);"static"===e.position&&r&&["absolute","fixed"].includes(r.position)&&!F(n)?t=t.filter((e=>e!==n)):r=e,n=X(n)}return t}(t):[].concat(n),a=[...i,r],l=a[0],s=a.reduce(((e,n)=>{const r=ee(t,n,o);return e.top=M(r.top,e.top),e.right=H(r.right,e.right),e.bottom=H(r.bottom,e.bottom),e.left=M(r.left,e.left),e}),ee(t,l,o));return{width:s.right-s.left,height:s.bottom-s.top,x:s.left,y:s.top}},convertOffsetParentRelativeRectToViewportRelativeRect:function(e){let{rect:t,offsetParent:n,strategy:r}=e;const o=N(n),i=V(n);if(n===i)return t;let a={scrollLeft:0,scrollTop:0};const l={x:0,y:0};if((o||!o&&"fixed"!==r)&&(("body"!==P(n)||$(i))&&(a=q(n)),N(n))){const e=B(n,!0);l.x=e.x+n.clientLeft,l.y=e.y+n.clientTop}return{...t,x:t.x-a.scrollLeft+l.x,y:t.y-a.scrollTop+l.y}},isElement:L,getDimensions:Z,getOffsetParent:K,getDocumentElement:V,getElementRects:e=>{let{reference:t,floating:n,strategy:r}=e;return{reference:Y(t,K(n),r),floating:{...Z(n),x:0,y:0}}},getClientRects:e=>Array.from(e.getClientRects()),isRTL:e=>"rtl"===E(e).direction},ne=(e,t,n)=>(async(e,t,n)=>{const{placement:r="bottom",strategy:o="absolute",middleware:i=[],platform:a}=n,l=i.filter(Boolean),s=await(null==a.isRTL?void 0:a.isRTL(t));if(null==a&&console.error(["Floating UI: `platform` property was not passed to config. If you","want to use Floating UI on the web, install @floating-ui/dom","instead of the /core package. Otherwise, you can create your own","`platform`: https://floating-ui.com/docs/platform"].join(" ")),l.filter((e=>{let{name:t}=e;return"autoPlacement"===t||"flip"===t})).length>1)throw new Error(["Floating UI: duplicate `flip` and/or `autoPlacement` middleware","detected. This will lead to an infinite loop. Ensure only one of","either has been passed to the `middleware` array."].join(" "));e&&t||console.error(["Floating UI: The reference and/or floating element was not defined","when `computePosition()` was called. Ensure that both elements have","been created and can be measured."].join(" "));let c=await a.getElementRects({reference:e,floating:t,strategy:o}),{x:u,y:f}=y(c,r,s),p=r,d={},m=0;for(let n=0;n<l.length;n++){const{name:i,fn:h}=l[n],{x:g,y:v,data:b,reset:w}=await h({x:u,y:f,initialPlacement:r,placement:p,strategy:o,middlewareData:d,rects:c,platform:a,elements:{reference:e,floating:t}});u=null!=g?g:u,f=null!=v?v:f,d={...d,[i]:{...d[i],...b}},m>50&&console.warn(["Floating UI: The middleware lifecycle appears to be running in an","infinite loop. This is usually caused by a `reset` continually","being returned without a break condition."].join(" ")),w&&m<=50&&(m++,"object"==typeof w&&(w.placement&&(p=w.placement),w.rects&&(c=!0===w.rects?await a.getElementRects({reference:e,floating:t,strategy:o}):w.rects),({x:u,y:f}=y(c,p,s))),n=-1)}return{x:u,y:f,placement:p,strategy:o,middlewareData:d}})(e,t,{platform:te,...n}),re=async({elementReference:e=null,tooltipReference:t=null,tooltipArrowReference:n=null,place:r="top",offset:o=10})=>{if(!e)return{tooltipStyles:{},tooltipArrowStyles:{}};if(null===t)return{tooltipStyles:{},tooltipArrowStyles:{}};const i=[T(Number(o)),k(),(a={padding:5},void 0===a&&(a={}),{name:"shift",options:a,async fn(e){const{x:t,y:n,placement:r}=e,{mainAxis:o=!0,crossAxis:i=!1,limiter:l={fn:e=>{let{x:t,y:n}=e;return{x:t,y:n}}},...s}=a,c={x:t,y:n},f=await g(e,s),d=p(u(r)),y="x"===d?"y":"x";let m=c[d],h=c[y];if(o){const e="y"===d?"bottom":"right";m=w(m+f["y"===d?"top":"left"],m,m-f[e])}if(i){const e="y"===y?"bottom":"right";h=w(h+f["y"===y?"top":"left"],h,h-f[e])}const v=l.fn({...e,[d]:m,[y]:h});return{...v,data:{x:v.x-t,y:v.y-n}}}})];var a;return n?(i.push((e=>({name:"arrow",options:e,async fn(t){const{element:n,padding:r=0}=null!=e?e:{},{x:o,y:i,placement:a,rects:l,platform:s}=t;if(null==n)return console.warn("Floating UI: No `element` was passed to the `arrow` middleware."),{};const c=m(r),u={x:o,y:i},y=p(a),h=f(a),g=d(y),v=await s.getDimensions(n),b="y"===y?"top":"left",x="y"===y?"bottom":"right",S=l.reference[g]+l.reference[y]-u[y]-l.floating[g],_=u[y]-l.reference[y],R=await(null==s.getOffsetParent?void 0:s.getOffsetParent(n));let k=R?"y"===y?R.clientHeight||0:R.clientWidth||0:0;0===k&&(k=l.floating[g]);const T=S/2-_/2,j=c[b],O=k-v[g]-c[x],E=k/2-v[g]/2+T,P=w(j,E,O),A=("start"===h?c[b]:c[x])>0&&E!==P&&l.reference[g]<=l.floating[g];return{[y]:u[y]-(A?E<j?j-E:O-E:0),data:{[y]:P,centerOffset:E-P}}}}))({element:n})),ne(e,t,{placement:r,middleware:i}).then((({x:e,y:t,placement:n,middlewareData:r})=>{const o={left:`${e}px`,top:`${t}px`},{x:i,y:a}=r.arrow;return{tooltipStyles:o,tooltipArrowStyles:{left:null!=i?`${i}px`:"",top:null!=a?`${a}px`:"",right:"",bottom:"",[{top:"bottom",right:"left",bottom:"top",left:"right"}[n.split("-")[0]]]:"-4px"}}}))):ne(e,t,{placement:"bottom",middleware:i}).then((({x:e,y:t})=>({tooltipStyles:{left:`${e}px`,top:`${t}px`},tooltipArrowStyles:{}})))};var oe={tooltip:"styles-module_tooltip__mnnfp",arrow:"styles-module_arrow__K0L3T",show:"styles-module_show__2NboJ",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"};const ie=({id:e=t.useId(),className:n,classNameArrow:r,variant:i="dark",anchorId:a,place:u="top",offset:f=10,events:p=["hover"],wrapper:d="div",children:y=null,delayShow:m=0,delayHide:h=0,isHtmlContent:g=!1,content:v,isOpen:b,setIsOpen:w})=>{const x=t.createRef(),S=t.createRef(),_=t.useRef(),R=t.useRef(),[k,T]=t.useState({}),[j,O]=t.useState({}),[E,P]=t.useState(!1),A=e=>{w?w(e):void 0===b&&P(e)},N=()=>{w?w(!b):void 0===b&&P((e=>!e))},L=s((()=>{m?(_.current&&clearTimeout(_.current),_.current=setTimeout((()=>{A(!0)}),m)):A(!0),R.current&&clearTimeout(R.current)}),50),C=s((()=>{h?(R.current&&clearTimeout(R.current),R.current=setTimeout((()=>{A(!1)}),h)):A(!1),E&&_.current?clearTimeout(_.current):!E&&_.current&&(R.current=setTimeout((()=>{A(!1)}),2*m))}),50);return t.useEffect((()=>{const e=document.querySelector(`#${a}`);if(!e)return()=>{};const t=[];return p.find((e=>"click"===e))&&t.push({event:"click",listener:N}),p.find((e=>"hover"===e))&&t.push({event:"mouseenter",listener:L},{event:"mouseleave",listener:C},{event:"focus",listener:L},{event:"blur",listener:C}),t.forEach((({event:t,listener:n})=>{null==e||e.addEventListener(t,n)})),()=>{t.forEach((({event:t,listener:n})=>{null==e||e.removeEventListener(t,n)}))}}),[a,p,h,m]),t.useEffect((()=>{const e=document.querySelector(`#${a}`);return re({place:u,offset:f,elementReference:e,tooltipReference:x.current,tooltipArrowReference:S.current}).then((e=>{Object.keys(e.tooltipStyles).length&&T(e.tooltipStyles),Object.keys(e.tooltipArrowStyles).length&&O(e.tooltipArrowStyles)})),()=>{_.current=void 0,R.current=void 0}}),[E,b,a]),o.exports.jsxs(d,{id:e,role:"tooltip",className:l(oe.tooltip,oe[i],n,{[oe.show]:b||E}),style:k,ref:x,children:[y||(g?o.exports.jsx(c,{content:v}):v),o.exports.jsx("div",{className:l(oe.arrow,r),style:j,ref:S})]})},ae=["place","content","html","variant","offset","wrapper","events","delay-show","delay-hide"];e.Tooltip=({id:e,anchorId:n,content:r,html:i,className:a,classNameArrow:l,variant:s="dark",place:c="top",offset:u=10,wrapper:f="div",children:p=null,events:d=["hover"],delayShow:y=0,delayHide:m=0,getContent:h,isOpen:g,setIsOpen:v})=>{const[b,w]=t.useState(r||i),[x,S]=t.useState(c),[_,R]=t.useState(s),[k,T]=t.useState(u),[j,O]=t.useState(y),[E,P]=t.useState(m),[A,N]=t.useState(f),[L,C]=t.useState(d),[$,D]=t.useState(Boolean(i)),F=e=>{const t=Object.keys(e);let n=null;const r={place:e=>{S(e)},content:e=>{D(!0),w(h?h(e):e)},html:e=>{D(!0),w(h?h(e):e)},variant:e=>{R(e)},offset:e=>{T(e)},wrapper:e=>{N(e)},events:e=>{const t=e.split(" ");C(t)},"delay-show":e=>{O(Number(e))},"delay-hide":e=>{P(Number(e))}};t.forEach((t=>{n=t.replace("data-tooltip-",""),ae.includes(n)&&r[n](e[t])}))};t.useEffect((()=>{if(!n)return()=>{};const e=document.querySelector(`#${n}`);if(!e)return()=>{};r&&h&&w(h(r));const t=new MutationObserver((t=>{t.forEach((t=>{if("attributes"===t.type){const n=(({element:e,attributeName:t})=>({[t]:e.getAttribute(t)}))({element:e,attributeName:t.attributeName});F(n)}}))}));t.observe(e,{attributes:!0,childList:!1,subtree:!1});const o=(e=>null==e?void 0:e.getAttributeNames().reduce(((t,n)=>(n.includes("data-tooltip-")&&(t[n]=null==e?void 0:e.getAttribute(n)),t)),{}))(e);return F(o),()=>{t.disconnect()}}),[n]);const I={id:e,anchorId:n,className:a,classNameArrow:l,content:b,isHtmlContent:$,place:x,variant:_,offset:k,wrapper:A,events:L,delayShow:j,delayHide:E,isOpen:g,setIsOpen:v};return p?o.exports.jsx(ie,{...I,children:p}):o.exports.jsx(ie,{...I})},Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
6
|
+
*/!function(e){!function(){var t={}.hasOwnProperty;function n(){for(var e=[],r=0;r<arguments.length;r++){var o=arguments[r];if(o){var i=typeof o;if("string"===i||"number"===i)e.push(o);else if(Array.isArray(o)){if(o.length){var a=n.apply(null,o);a&&e.push(a)}}else if("object"===i){if(o.toString!==Object.prototype.toString&&!o.toString.toString().includes("[native code]")){e.push(o.toString());continue}for(var l in o)t.call(o,l)&&o[l]&&e.push(l)}}}return e.join(" ")}e.exports?(n.default=n,e.exports=n):window.classNames=n}()}(a);var l=a.exports;const s=(e,t,n)=>{let r;return function(){const o=this,i=arguments,a=()=>{r=null,n||e.apply(o,i)};clearTimeout(r),r=setTimeout(a,t)}},c=({content:e})=>o.exports.jsx("span",{dangerouslySetInnerHTML:{__html:e}});function u(e){return e.split("-")[0]}function f(e){return e.split("-")[1]}function p(e){return["top","bottom"].includes(u(e))?"x":"y"}function d(e){return"y"===e?"height":"width"}function y(e,t,n){let{reference:r,floating:o}=e;const i=r.x+r.width/2-o.width/2,a=r.y+r.height/2-o.height/2,l=p(t),s=d(l),c=r[s]/2-o[s]/2,y="x"===l;let m;switch(u(t)){case"top":m={x:i,y:r.y-o.height};break;case"bottom":m={x:i,y:r.y+r.height};break;case"right":m={x:r.x+r.width,y:a};break;case"left":m={x:r.x-o.width,y:a};break;default:m={x:r.x,y:r.y}}switch(f(t)){case"start":m[l]-=c*(n&&y?-1:1);break;case"end":m[l]+=c*(n&&y?-1:1)}return m}function m(e){return"number"!=typeof e?function(e){return{top:0,right:0,bottom:0,left:0,...e}}(e):{top:e,right:e,bottom:e,left:e}}function h(e){return{...e,top:e.y,left:e.x,right:e.x+e.width,bottom:e.y+e.height}}async function g(e,t){var n;void 0===t&&(t={});const{x:r,y:o,platform:i,rects:a,elements:l,strategy:s}=e,{boundary:c="clippingAncestors",rootBoundary:u="viewport",elementContext:f="floating",altBoundary:p=!1,padding:d=0}=t,y=m(d),g=l[p?"floating"===f?"reference":"floating":f],v=h(await i.getClippingRect({element:null==(n=await(null==i.isElement?void 0:i.isElement(g)))||n?g:g.contextElement||await(null==i.getDocumentElement?void 0:i.getDocumentElement(l.floating)),boundary:c,rootBoundary:u,strategy:s})),b=h(i.convertOffsetParentRelativeRectToViewportRelativeRect?await i.convertOffsetParentRelativeRectToViewportRelativeRect({rect:"floating"===f?{...a.floating,x:r,y:o}:a.reference,offsetParent:await(null==i.getOffsetParent?void 0:i.getOffsetParent(l.floating)),strategy:s}):a[f]);return{top:v.top-b.top+y.top,bottom:b.bottom-v.bottom+y.bottom,left:v.left-b.left+y.left,right:b.right-v.right+y.right}}const v=Math.min,b=Math.max;function w(e,t,n){return b(e,v(t,n))}const x={left:"right",right:"left",bottom:"top",top:"bottom"};function S(e){return e.replace(/left|right|bottom|top/g,(e=>x[e]))}const _={start:"end",end:"start"};function R(e){return e.replace(/start|end/g,(e=>_[e]))}const k=function(e){return void 0===e&&(e={}),{name:"flip",options:e,async fn(t){var n;const{placement:r,middlewareData:o,rects:i,initialPlacement:a,platform:l,elements:s}=t,{mainAxis:c=!0,crossAxis:y=!0,fallbackPlacements:m,fallbackStrategy:h="bestFit",flipAlignment:v=!0,...b}=e,w=u(r),x=m||(w===a||!v?[S(a)]:function(e){const t=S(e);return[R(e),t,R(t)]}(a)),_=[a,...x],k=await g(t,b),T=[];let j=(null==(n=o.flip)?void 0:n.overflows)||[];if(c&&T.push(k[w]),y){const{main:e,cross:t}=function(e,t,n){void 0===n&&(n=!1);const r=f(e),o=p(e),i=d(o);let a="x"===o?r===(n?"end":"start")?"right":"left":"start"===r?"bottom":"top";return t.reference[i]>t.floating[i]&&(a=S(a)),{main:a,cross:S(a)}}(r,i,await(null==l.isRTL?void 0:l.isRTL(s.floating)));T.push(k[e],k[t])}if(j=[...j,{placement:r,overflows:T}],!T.every((e=>e<=0))){var O,E;const e=(null!=(O=null==(E=o.flip)?void 0:E.index)?O:0)+1,t=_[e];if(t)return{data:{index:e,overflows:j},reset:{placement:t}};let n="bottom";switch(h){case"bestFit":{var P;const e=null==(P=j.map((e=>[e,e.overflows.filter((e=>e>0)).reduce(((e,t)=>e+t),0)])).sort(((e,t)=>e[1]-t[1]))[0])?void 0:P[0].placement;e&&(n=e);break}case"initialPlacement":n=a}if(r!==n)return{reset:{placement:n}}}return{}}}};const T=function(e){return void 0===e&&(e=0),{name:"offset",options:e,async fn(t){const{x:n,y:r}=t,o=await async function(e,t){const{placement:n,platform:r,elements:o}=e,i=await(null==r.isRTL?void 0:r.isRTL(o.floating)),a=u(n),l=f(n),s="x"===p(n),c=["left","top"].includes(a)?-1:1,d=i&&s?-1:1,y="function"==typeof t?t(e):t;let{mainAxis:m,crossAxis:h,alignmentAxis:g}="number"==typeof y?{mainAxis:y,crossAxis:0,alignmentAxis:null}:{mainAxis:0,crossAxis:0,alignmentAxis:null,...y};return l&&"number"==typeof g&&(h="end"===l?-1*g:g),s?{x:h*d,y:m*c}:{x:m*c,y:h*d}}(t,e);return{x:n+o.x,y:r+o.y,data:o}}}};function j(e){return e&&e.document&&e.location&&e.alert&&e.setInterval}function O(e){if(null==e)return window;if(!j(e)){const t=e.ownerDocument;return t&&t.defaultView||window}return e}function E(e){return O(e).getComputedStyle(e)}function P(e){return j(e)?"":e?(e.nodeName||"").toLowerCase():""}function A(){const e=navigator.userAgentData;return null!=e&&e.brands?e.brands.map((e=>e.brand+"/"+e.version)).join(" "):navigator.userAgent}function N(e){return e instanceof O(e).HTMLElement}function L(e){return e instanceof O(e).Element}function C(e){if("undefined"==typeof ShadowRoot)return!1;return e instanceof O(e).ShadowRoot||e instanceof ShadowRoot}function $(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=E(e);return/auto|scroll|overlay|hidden/.test(t+r+n)&&!["inline","contents"].includes(o)}function D(e){return["table","td","th"].includes(P(e))}function F(e){const t=/firefox/i.test(A()),n=E(e),r=n.backdropFilter||n.WebkitBackdropFilter;return"none"!==n.transform||"none"!==n.perspective||!!r&&"none"!==r||t&&"filter"===n.willChange||t&&!!n.filter&&"none"!==n.filter||["transform","perspective"].some((e=>n.willChange.includes(e)))||["paint","layout","strict","content"].some((e=>{const t=n.contain;return null!=t&&t.includes(e)}))}function I(){return!/^((?!chrome|android).)*safari/i.test(A())}function W(e){return["html","body","#document"].includes(P(e))}const H=Math.min,M=Math.max,U=Math.round;function B(e,t,n){var r,o,i,a;void 0===t&&(t=!1),void 0===n&&(n=!1);const l=e.getBoundingClientRect();let s=1,c=1;t&&N(e)&&(s=e.offsetWidth>0&&U(l.width)/e.offsetWidth||1,c=e.offsetHeight>0&&U(l.height)/e.offsetHeight||1);const u=L(e)?O(e):window,f=!I()&&n,p=(l.left+(f&&null!=(r=null==(o=u.visualViewport)?void 0:o.offsetLeft)?r:0))/s,d=(l.top+(f&&null!=(i=null==(a=u.visualViewport)?void 0:a.offsetTop)?i:0))/c,y=l.width/s,m=l.height/c;return{width:y,height:m,top:d,right:p+y,bottom:d+m,left:p,x:p,y:d}}function V(e){return(t=e,(t instanceof O(t).Node?e.ownerDocument:e.document)||window.document).documentElement;var t}function q(e){return L(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.pageXOffset,scrollTop:e.pageYOffset}}function z(e){return B(V(e)).left+q(e).scrollLeft}function Y(e,t,n){const r=N(t),o=V(t),i=B(e,r&&function(e){const t=B(e);return U(t.width)!==e.offsetWidth||U(t.height)!==e.offsetHeight}(t),"fixed"===n);let a={scrollLeft:0,scrollTop:0};const l={x:0,y:0};if(r||!r&&"fixed"!==n)if(("body"!==P(t)||$(o))&&(a=q(t)),N(t)){const e=B(t,!0);l.x=e.x+t.clientLeft,l.y=e.y+t.clientTop}else o&&(l.x=z(o));return{x:i.left+a.scrollLeft-l.x,y:i.top+a.scrollTop-l.y,width:i.width,height:i.height}}function X(e){if("html"===P(e))return e;const t=e.assignedSlot||e.parentNode||(C(e)?e.host:null)||V(e);return C(t)?t.host:t}function J(e){return N(e)&&"fixed"!==E(e).position?e.offsetParent:null}function K(e){const t=O(e);let n=J(e);for(;n&&D(n)&&"static"===E(n).position;)n=J(n);return n&&("html"===P(n)||"body"===P(n)&&"static"===E(n).position&&!F(n))?t:n||function(e){let t=X(e);for(;N(t)&&!W(t);){if(F(t))return t;t=X(t)}return null}(e)||t}function Z(e){if(N(e))return{width:e.offsetWidth,height:e.offsetHeight};const t=B(e);return{width:t.width,height:t.height}}function G(e){const t=X(e);return W(t)?e.ownerDocument.body:N(t)&&$(t)?t:G(t)}function Q(e,t){var n;void 0===t&&(t=[]);const r=G(e),o=r===(null==(n=e.ownerDocument)?void 0:n.body),i=O(r),a=o?[i].concat(i.visualViewport||[],$(r)?r:[]):r,l=t.concat(a);return o?l:l.concat(Q(a))}function ee(e,t,n){return"viewport"===t?h(function(e,t){const n=O(e),r=V(e),o=n.visualViewport;let i=r.clientWidth,a=r.clientHeight,l=0,s=0;if(o){i=o.width,a=o.height;const e=I();(e||!e&&"fixed"===t)&&(l=o.offsetLeft,s=o.offsetTop)}return{width:i,height:a,x:l,y:s}}(e,n)):L(t)?function(e,t){const n=B(e,!1,"fixed"===t),r=n.top+e.clientTop,o=n.left+e.clientLeft;return{top:r,left:o,x:o,y:r,right:o+e.clientWidth,bottom:r+e.clientHeight,width:e.clientWidth,height:e.clientHeight}}(t,n):h(function(e){var t;const n=V(e),r=q(e),o=null==(t=e.ownerDocument)?void 0:t.body,i=M(n.scrollWidth,n.clientWidth,o?o.scrollWidth:0,o?o.clientWidth:0),a=M(n.scrollHeight,n.clientHeight,o?o.scrollHeight:0,o?o.clientHeight:0);let l=-r.scrollLeft+z(e);const s=-r.scrollTop;return"rtl"===E(o||n).direction&&(l+=M(n.clientWidth,o?o.clientWidth:0)-i),{width:i,height:a,x:l,y:s}}(V(e)))}const te={getClippingRect:function(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i="clippingAncestors"===n?function(e){let t=Q(e).filter((e=>L(e)&&"body"!==P(e))),n=e,r=null;for(;L(n)&&!W(n);){const e=E(n);"static"===e.position&&r&&["absolute","fixed"].includes(r.position)&&!F(n)?t=t.filter((e=>e!==n)):r=e,n=X(n)}return t}(t):[].concat(n),a=[...i,r],l=a[0],s=a.reduce(((e,n)=>{const r=ee(t,n,o);return e.top=M(r.top,e.top),e.right=H(r.right,e.right),e.bottom=H(r.bottom,e.bottom),e.left=M(r.left,e.left),e}),ee(t,l,o));return{width:s.right-s.left,height:s.bottom-s.top,x:s.left,y:s.top}},convertOffsetParentRelativeRectToViewportRelativeRect:function(e){let{rect:t,offsetParent:n,strategy:r}=e;const o=N(n),i=V(n);if(n===i)return t;let a={scrollLeft:0,scrollTop:0};const l={x:0,y:0};if((o||!o&&"fixed"!==r)&&(("body"!==P(n)||$(i))&&(a=q(n)),N(n))){const e=B(n,!0);l.x=e.x+n.clientLeft,l.y=e.y+n.clientTop}return{...t,x:t.x-a.scrollLeft+l.x,y:t.y-a.scrollTop+l.y}},isElement:L,getDimensions:Z,getOffsetParent:K,getDocumentElement:V,getElementRects:e=>{let{reference:t,floating:n,strategy:r}=e;return{reference:Y(t,K(n),r),floating:{...Z(n),x:0,y:0}}},getClientRects:e=>Array.from(e.getClientRects()),isRTL:e=>"rtl"===E(e).direction},ne=(e,t,n)=>(async(e,t,n)=>{const{placement:r="bottom",strategy:o="absolute",middleware:i=[],platform:a}=n,l=i.filter(Boolean),s=await(null==a.isRTL?void 0:a.isRTL(t));if(null==a&&console.error(["Floating UI: `platform` property was not passed to config. If you","want to use Floating UI on the web, install @floating-ui/dom","instead of the /core package. Otherwise, you can create your own","`platform`: https://floating-ui.com/docs/platform"].join(" ")),l.filter((e=>{let{name:t}=e;return"autoPlacement"===t||"flip"===t})).length>1)throw new Error(["Floating UI: duplicate `flip` and/or `autoPlacement` middleware","detected. This will lead to an infinite loop. Ensure only one of","either has been passed to the `middleware` array."].join(" "));e&&t||console.error(["Floating UI: The reference and/or floating element was not defined","when `computePosition()` was called. Ensure that both elements have","been created and can be measured."].join(" "));let c=await a.getElementRects({reference:e,floating:t,strategy:o}),{x:u,y:f}=y(c,r,s),p=r,d={},m=0;for(let n=0;n<l.length;n++){const{name:i,fn:h}=l[n],{x:g,y:v,data:b,reset:w}=await h({x:u,y:f,initialPlacement:r,placement:p,strategy:o,middlewareData:d,rects:c,platform:a,elements:{reference:e,floating:t}});u=null!=g?g:u,f=null!=v?v:f,d={...d,[i]:{...d[i],...b}},m>50&&console.warn(["Floating UI: The middleware lifecycle appears to be running in an","infinite loop. This is usually caused by a `reset` continually","being returned without a break condition."].join(" ")),w&&m<=50&&(m++,"object"==typeof w&&(w.placement&&(p=w.placement),w.rects&&(c=!0===w.rects?await a.getElementRects({reference:e,floating:t,strategy:o}):w.rects),({x:u,y:f}=y(c,p,s))),n=-1)}return{x:u,y:f,placement:p,strategy:o,middlewareData:d}})(e,t,{platform:te,...n}),re=async({elementReference:e=null,tooltipReference:t=null,tooltipArrowReference:n=null,place:r="top",offset:o=10,strategy:i="absolute"})=>{if(!e)return{tooltipStyles:{},tooltipArrowStyles:{}};if(null===t)return{tooltipStyles:{},tooltipArrowStyles:{}};const a=[T(Number(o)),k(),(l={padding:5},void 0===l&&(l={}),{name:"shift",options:l,async fn(e){const{x:t,y:n,placement:r}=e,{mainAxis:o=!0,crossAxis:i=!1,limiter:a={fn:e=>{let{x:t,y:n}=e;return{x:t,y:n}}},...s}=l,c={x:t,y:n},f=await g(e,s),d=p(u(r)),y="x"===d?"y":"x";let m=c[d],h=c[y];if(o){const e="y"===d?"bottom":"right";m=w(m+f["y"===d?"top":"left"],m,m-f[e])}if(i){const e="y"===y?"bottom":"right";h=w(h+f["y"===y?"top":"left"],h,h-f[e])}const v=a.fn({...e,[d]:m,[y]:h});return{...v,data:{x:v.x-t,y:v.y-n}}}})];var l;return n?(a.push((e=>({name:"arrow",options:e,async fn(t){const{element:n,padding:r=0}=null!=e?e:{},{x:o,y:i,placement:a,rects:l,platform:s}=t;if(null==n)return console.warn("Floating UI: No `element` was passed to the `arrow` middleware."),{};const c=m(r),u={x:o,y:i},y=p(a),h=f(a),g=d(y),v=await s.getDimensions(n),b="y"===y?"top":"left",x="y"===y?"bottom":"right",S=l.reference[g]+l.reference[y]-u[y]-l.floating[g],_=u[y]-l.reference[y],R=await(null==s.getOffsetParent?void 0:s.getOffsetParent(n));let k=R?"y"===y?R.clientHeight||0:R.clientWidth||0:0;0===k&&(k=l.floating[g]);const T=S/2-_/2,j=c[b],O=k-v[g]-c[x],E=k/2-v[g]/2+T,P=w(j,E,O),A=("start"===h?c[b]:c[x])>0&&E!==P&&l.reference[g]<=l.floating[g];return{[y]:u[y]-(A?E<j?j-E:O-E:0),data:{[y]:P,centerOffset:E-P}}}}))({element:n})),ne(e,t,{placement:r,strategy:i,middleware:a}).then((({x:e,y:t,placement:n,middlewareData:r})=>{const o={left:`${e}px`,top:`${t}px`},{x:i,y:a}=r.arrow;return{tooltipStyles:o,tooltipArrowStyles:{left:null!=i?`${i}px`:"",top:null!=a?`${a}px`:"",right:"",bottom:"",[{top:"bottom",right:"left",bottom:"top",left:"right"}[n.split("-")[0]]]:"-4px"}}}))):ne(e,t,{placement:"bottom",strategy:i,middleware:a}).then((({x:e,y:t})=>({tooltipStyles:{left:`${e}px`,top:`${t}px`},tooltipArrowStyles:{}})))};var oe={tooltip:"styles-module_tooltip__mnnfp",fixed:"styles-module_fixed__7ciUi",arrow:"styles-module_arrow__K0L3T",show:"styles-module_show__2NboJ",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"};const ie=({id:e=t.useId(),className:n,classNameArrow:r,variant:i="dark",anchorId:a,place:u="top",offset:f=10,events:p=["hover"],positionStrategy:d="absolute",wrapper:y="div",children:m=null,delayShow:h=0,delayHide:g=0,style:v,isHtmlContent:b=!1,content:w,isOpen:x,setIsOpen:S})=>{const _=t.createRef(),R=t.createRef(),k=t.useRef(),T=t.useRef(),[j,O]=t.useState({}),[E,P]=t.useState({}),[A,N]=t.useState(!1),L=e=>{S?S(e):void 0===x&&N(e)},C=()=>{S?S(!x):void 0===x&&N((e=>!e))},$=s((()=>{h?(k.current&&clearTimeout(k.current),k.current=setTimeout((()=>{L(!0)}),h)):L(!0),T.current&&clearTimeout(T.current)}),50),D=s((()=>{g?(T.current&&clearTimeout(T.current),T.current=setTimeout((()=>{L(!1)}),g)):L(!1),A&&k.current?clearTimeout(k.current):!A&&k.current&&(T.current=setTimeout((()=>{L(!1)}),2*h))}),50);return t.useEffect((()=>{const e=document.querySelector(`#${a}`);if(!e)return()=>{};const t=[];return p.find((e=>"click"===e))&&t.push({event:"click",listener:C}),p.find((e=>"hover"===e))&&t.push({event:"mouseenter",listener:$},{event:"mouseleave",listener:D},{event:"focus",listener:$},{event:"blur",listener:D}),t.forEach((({event:t,listener:n})=>{null==e||e.addEventListener(t,n)})),()=>{t.forEach((({event:t,listener:n})=>{null==e||e.removeEventListener(t,n)}))}}),[a,p,g,h]),t.useEffect((()=>{const e=document.querySelector(`#${a}`);return re({place:u,offset:f,elementReference:e,tooltipReference:_.current,tooltipArrowReference:R.current,strategy:d}).then((e=>{Object.keys(e.tooltipStyles).length&&O(e.tooltipStyles),Object.keys(e.tooltipArrowStyles).length&&P(e.tooltipArrowStyles)})),()=>{k.current=void 0,T.current=void 0}}),[A,x,a]),o.exports.jsxs(y,{id:e,role:"tooltip",className:l(oe.tooltip,oe[i],n,{[oe.show]:x||A,[oe.fixed]:"fixed"===d}),style:{...v,...j},ref:_,children:[m||(b?o.exports.jsx(c,{content:w}):w),o.exports.jsx("div",{className:l(oe.arrow,r),style:E,ref:R})]})},ae=["place","content","html","variant","offset","wrapper","events","delay-show","delay-hide"];e.Tooltip=({id:e,anchorId:n,content:r,html:i,className:a,classNameArrow:l,variant:s="dark",place:c="top",offset:u=10,wrapper:f="div",children:p=null,events:d=["hover"],positionStrategy:y="absolute",delayShow:m=0,delayHide:h=0,style:g,getContent:v,isOpen:b,setIsOpen:w})=>{const[x,S]=t.useState(r||i),[_,R]=t.useState(c),[k,T]=t.useState(s),[j,O]=t.useState(u),[E,P]=t.useState(m),[A,N]=t.useState(h),[L,C]=t.useState(f),[$,D]=t.useState(d),[F,I]=t.useState(y),[W,H]=t.useState(Boolean(i)),M=e=>{const t=Object.keys(e);let n=null;const r={place:e=>{R(e)},content:e=>{H(!0),S(v?v(e):e)},html:e=>{H(!0),S(v?v(e):e)},variant:e=>{T(e)},offset:e=>{O(e)},wrapper:e=>{C(e)},events:e=>{const t=e.split(" ");D(t)},positionStrategy:e=>{I(e)},"delay-show":e=>{P(Number(e))},"delay-hide":e=>{N(Number(e))}};t.forEach((t=>{n=t.replace("data-tooltip-",""),ae.includes(n)&&r[n](e[t])}))};t.useEffect((()=>{if(!n)return()=>{};const e=document.querySelector(`#${n}`);if(!e)return()=>{};r&&v&&S(v(r));const t=new MutationObserver((t=>{t.forEach((t=>{if("attributes"===t.type){const n=(({element:e,attributeName:t})=>({[t]:e.getAttribute(t)}))({element:e,attributeName:t.attributeName});M(n)}}))}));t.observe(e,{attributes:!0,childList:!1,subtree:!1});const o=(e=>null==e?void 0:e.getAttributeNames().reduce(((t,n)=>(n.includes("data-tooltip-")&&(t[n]=null==e?void 0:e.getAttribute(n)),t)),{}))(e);return M(o),()=>{t.disconnect()}}),[n]);const U={id:e,anchorId:n,className:a,classNameArrow:l,content:x,isHtmlContent:W,place:_,variant:k,offset:j,wrapper:L,events:$,positionStrategy:F,delayShow:E,delayHide:A,style:g,isOpen:b,setIsOpen:w};return p?o.exports.jsx(ie,{...U,children:p}):o.exports.jsx(ie,{...U})},Object.defineProperty(e,"__esModule",{value:!0})}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-tooltip",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.1.0-beta.0",
|
|
4
4
|
"description": "react tooltip component",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "node ./cli.js --env=development && node --max_old_space_size=2048 ./node_modules/rollup/dist/bin/rollup -c rollup.config.dev.js --watch",
|
|
@@ -85,7 +85,7 @@
|
|
|
85
85
|
"rollup-plugin-analyzer": "^4.0.0",
|
|
86
86
|
"rollup-plugin-browsersync": "^1.3.3",
|
|
87
87
|
"rollup-plugin-copy": "^3.4.0",
|
|
88
|
-
"rollup-plugin-dts": "
|
|
88
|
+
"rollup-plugin-dts": "^5.0.0",
|
|
89
89
|
"rollup-plugin-filesize": "^9.1.1",
|
|
90
90
|
"rollup-plugin-html-scaffold": "^0.2.0",
|
|
91
91
|
"rollup-plugin-postcss": "^4.0.1",
|
|
@@ -124,8 +124,6 @@
|
|
|
124
124
|
},
|
|
125
125
|
"dependencies": {
|
|
126
126
|
"@floating-ui/dom": "^1.0.4",
|
|
127
|
-
"@floating-ui/react-dom": "^1.0.0",
|
|
128
|
-
"@floating-ui/react-dom-interactions": "0.11.0",
|
|
129
127
|
"classnames": "^2.3.2"
|
|
130
128
|
}
|
|
131
129
|
}
|
package/rollup.config.types.js
CHANGED
|
@@ -6,12 +6,16 @@ export default {
|
|
|
6
6
|
output: [{ file: 'dist/react-tooltip.d.ts', format: 'es' }],
|
|
7
7
|
plugins: [
|
|
8
8
|
postcss({
|
|
9
|
-
extract: 'react-tooltip-tokens.css', // this will generate a specific file
|
|
9
|
+
extract: 'react-tooltip-tokens.css', // this will generate a specific file not being used, but we need this part of code
|
|
10
10
|
autoModules: true,
|
|
11
11
|
include: '**/*.css',
|
|
12
12
|
extensions: ['.css'],
|
|
13
13
|
plugins: [],
|
|
14
14
|
}),
|
|
15
|
-
dts(
|
|
15
|
+
dts({
|
|
16
|
+
compilerOptions: {
|
|
17
|
+
baseUrl: 'src',
|
|
18
|
+
},
|
|
19
|
+
}),
|
|
16
20
|
],
|
|
17
21
|
}
|
package/src/App.tsx
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { TooltipController as Tooltip } from 'components/TooltipController'
|
|
2
|
+
import { useState } from 'react'
|
|
3
|
+
import styles from './styles.module.css'
|
|
4
|
+
|
|
5
|
+
function App() {
|
|
6
|
+
const [anchorId, setAnchorId] = useState('button')
|
|
7
|
+
const [isDarkOpen, setIsDarkOpen] = useState(false)
|
|
8
|
+
|
|
9
|
+
return (
|
|
10
|
+
<main className={styles['main']}>
|
|
11
|
+
<button
|
|
12
|
+
id="button"
|
|
13
|
+
aria-describedby="tooltip"
|
|
14
|
+
onClick={() => {
|
|
15
|
+
setAnchorId('button')
|
|
16
|
+
}}
|
|
17
|
+
>
|
|
18
|
+
My button
|
|
19
|
+
</button>
|
|
20
|
+
<Tooltip
|
|
21
|
+
place="bottom"
|
|
22
|
+
anchorId={anchorId}
|
|
23
|
+
content="My big tooltip content"
|
|
24
|
+
isOpen={isDarkOpen}
|
|
25
|
+
setIsOpen={setIsDarkOpen}
|
|
26
|
+
/>
|
|
27
|
+
<Tooltip
|
|
28
|
+
place="top"
|
|
29
|
+
variant="success"
|
|
30
|
+
anchorId="button2"
|
|
31
|
+
content="My big tooltip content"
|
|
32
|
+
isOpen={isDarkOpen}
|
|
33
|
+
setIsOpen={setIsDarkOpen}
|
|
34
|
+
/>
|
|
35
|
+
<Tooltip
|
|
36
|
+
place="top"
|
|
37
|
+
variant="info"
|
|
38
|
+
anchorId="button3"
|
|
39
|
+
content="My big tooltip content"
|
|
40
|
+
isOpen={isDarkOpen}
|
|
41
|
+
setIsOpen={setIsDarkOpen}
|
|
42
|
+
/>
|
|
43
|
+
<Tooltip
|
|
44
|
+
place="right"
|
|
45
|
+
variant="info"
|
|
46
|
+
anchorId="button3"
|
|
47
|
+
content="My big tooltip content"
|
|
48
|
+
isOpen={isDarkOpen}
|
|
49
|
+
setIsOpen={setIsDarkOpen}
|
|
50
|
+
style={{ backgroundColor: '#ff00ff' }}
|
|
51
|
+
/>
|
|
52
|
+
|
|
53
|
+
<section style={{ marginTop: '100px' }}>
|
|
54
|
+
<p>
|
|
55
|
+
<button
|
|
56
|
+
id="button2"
|
|
57
|
+
data-tip="Hello World from a Tooltip"
|
|
58
|
+
onClick={() => {
|
|
59
|
+
setAnchorId('button2')
|
|
60
|
+
}}
|
|
61
|
+
>
|
|
62
|
+
Hover or focus me
|
|
63
|
+
</button>
|
|
64
|
+
<button
|
|
65
|
+
id="button3"
|
|
66
|
+
data-tip="Hello World from a Tooltip 2"
|
|
67
|
+
onClick={() => {
|
|
68
|
+
setAnchorId('button3')
|
|
69
|
+
}}
|
|
70
|
+
>
|
|
71
|
+
Hover or focus me 2
|
|
72
|
+
</button>
|
|
73
|
+
</p>
|
|
74
|
+
</section>
|
|
75
|
+
</main>
|
|
76
|
+
)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export default App
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { createRef, useEffect, useState, useId, useRef } from 'react'
|
|
2
|
+
import classNames from 'classnames'
|
|
3
|
+
import debounce from 'utils/debounce'
|
|
4
|
+
import { TooltipContent } from 'components/TooltipContent'
|
|
5
|
+
import { computeToolTipPosition } from '../../utils/compute-positions'
|
|
6
|
+
import styles from './styles.module.css'
|
|
7
|
+
import type { ITooltip } from './TooltipTypes'
|
|
8
|
+
|
|
9
|
+
const Tooltip = ({
|
|
10
|
+
// props
|
|
11
|
+
id = useId(),
|
|
12
|
+
className,
|
|
13
|
+
classNameArrow,
|
|
14
|
+
variant = 'dark',
|
|
15
|
+
anchorId,
|
|
16
|
+
place = 'top',
|
|
17
|
+
offset = 10,
|
|
18
|
+
events = ['hover'],
|
|
19
|
+
positionStrategy = 'absolute',
|
|
20
|
+
wrapper: WrapperElement = 'div',
|
|
21
|
+
children = null,
|
|
22
|
+
delayShow = 0,
|
|
23
|
+
delayHide = 0,
|
|
24
|
+
style: externalStyles,
|
|
25
|
+
// props handled by controller
|
|
26
|
+
isHtmlContent = false,
|
|
27
|
+
content,
|
|
28
|
+
isOpen,
|
|
29
|
+
setIsOpen,
|
|
30
|
+
}: ITooltip) => {
|
|
31
|
+
const tooltipRef = createRef()
|
|
32
|
+
const tooltipArrowRef = createRef()
|
|
33
|
+
const tooltipShowDelayTimerRef = useRef<ReturnType<typeof setTimeout>>()
|
|
34
|
+
const tooltipHideDelayTimerRef = useRef<ReturnType<typeof setTimeout>>()
|
|
35
|
+
const [inlineStyles, setInlineStyles] = useState({})
|
|
36
|
+
const [inlineArrowStyles, setInlineArrowStyles] = useState({})
|
|
37
|
+
const [show, setShow] = useState<boolean>(false)
|
|
38
|
+
|
|
39
|
+
const handleShow = (value: boolean) => {
|
|
40
|
+
if (setIsOpen) {
|
|
41
|
+
setIsOpen(value)
|
|
42
|
+
} else if (isOpen === undefined) {
|
|
43
|
+
setShow(value)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const handleShowTooltipDelayed = () => {
|
|
48
|
+
if (tooltipShowDelayTimerRef.current) {
|
|
49
|
+
clearTimeout(tooltipShowDelayTimerRef.current)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
tooltipShowDelayTimerRef.current = setTimeout(() => {
|
|
53
|
+
handleShow(true)
|
|
54
|
+
}, delayShow)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const handleHideTooltipDelayed = () => {
|
|
58
|
+
if (tooltipHideDelayTimerRef.current) {
|
|
59
|
+
clearTimeout(tooltipHideDelayTimerRef.current)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
tooltipHideDelayTimerRef.current = setTimeout(() => {
|
|
63
|
+
handleShow(false)
|
|
64
|
+
}, delayHide)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const handleShowTooltip = () => {
|
|
68
|
+
if (delayShow) {
|
|
69
|
+
handleShowTooltipDelayed()
|
|
70
|
+
} else {
|
|
71
|
+
handleShow(true)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (tooltipHideDelayTimerRef.current) {
|
|
75
|
+
clearTimeout(tooltipHideDelayTimerRef.current)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const handleHideTooltip = () => {
|
|
80
|
+
if (delayHide) {
|
|
81
|
+
handleHideTooltipDelayed()
|
|
82
|
+
} else {
|
|
83
|
+
handleShow(false)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (show && tooltipShowDelayTimerRef.current) {
|
|
87
|
+
clearTimeout(tooltipShowDelayTimerRef.current)
|
|
88
|
+
} else if (!show && tooltipShowDelayTimerRef.current) {
|
|
89
|
+
// workaround to prevent tooltip being show forever
|
|
90
|
+
// when we remove the mouse before show tooltip with `delayShow`
|
|
91
|
+
tooltipHideDelayTimerRef.current = setTimeout(() => {
|
|
92
|
+
handleShow(false)
|
|
93
|
+
}, delayShow * 2)
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const handleClickTooltipAnchor = () => {
|
|
98
|
+
if (setIsOpen) {
|
|
99
|
+
setIsOpen(!isOpen)
|
|
100
|
+
} else if (isOpen === undefined) {
|
|
101
|
+
setShow((currentValue) => !currentValue)
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// debounce handler to prevent call twice when
|
|
106
|
+
// mouse enter and focus events being triggered toggether
|
|
107
|
+
const debouncedHandleShowTooltip = debounce(handleShowTooltip, 50)
|
|
108
|
+
const debouncedHandleHideTooltip = debounce(handleHideTooltip, 50)
|
|
109
|
+
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
const elementReference = document.querySelector(`#${anchorId}`)
|
|
112
|
+
|
|
113
|
+
if (!elementReference) {
|
|
114
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
115
|
+
return () => {}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const enabledEvents: { event: string; listener: () => void }[] = []
|
|
119
|
+
|
|
120
|
+
if (events.find((event: string) => event === 'click')) {
|
|
121
|
+
enabledEvents.push({ event: 'click', listener: handleClickTooltipAnchor })
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (events.find((event: string) => event === 'hover')) {
|
|
125
|
+
enabledEvents.push(
|
|
126
|
+
{ event: 'mouseenter', listener: debouncedHandleShowTooltip },
|
|
127
|
+
{ event: 'mouseleave', listener: debouncedHandleHideTooltip },
|
|
128
|
+
{ event: 'focus', listener: debouncedHandleShowTooltip },
|
|
129
|
+
{ event: 'blur', listener: debouncedHandleHideTooltip },
|
|
130
|
+
)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
enabledEvents.forEach(({ event, listener }) => {
|
|
134
|
+
elementReference?.addEventListener(event, listener)
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
return () => {
|
|
138
|
+
enabledEvents.forEach(({ event, listener }) => {
|
|
139
|
+
elementReference?.removeEventListener(event, listener)
|
|
140
|
+
})
|
|
141
|
+
}
|
|
142
|
+
}, [anchorId, events, delayHide, delayShow])
|
|
143
|
+
|
|
144
|
+
useEffect(() => {
|
|
145
|
+
const elementReference = document.querySelector(`#${anchorId}`)
|
|
146
|
+
|
|
147
|
+
computeToolTipPosition({
|
|
148
|
+
place,
|
|
149
|
+
offset,
|
|
150
|
+
elementReference,
|
|
151
|
+
tooltipReference: tooltipRef.current as HTMLElement,
|
|
152
|
+
tooltipArrowReference: tooltipArrowRef.current as HTMLElement,
|
|
153
|
+
strategy: positionStrategy,
|
|
154
|
+
}).then((computedStylesData) => {
|
|
155
|
+
if (Object.keys(computedStylesData.tooltipStyles).length) {
|
|
156
|
+
setInlineStyles(computedStylesData.tooltipStyles)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (Object.keys(computedStylesData.tooltipArrowStyles).length) {
|
|
160
|
+
setInlineArrowStyles(computedStylesData.tooltipArrowStyles)
|
|
161
|
+
}
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
return () => {
|
|
165
|
+
tooltipShowDelayTimerRef.current = undefined
|
|
166
|
+
tooltipHideDelayTimerRef.current = undefined
|
|
167
|
+
}
|
|
168
|
+
}, [show, isOpen, anchorId])
|
|
169
|
+
|
|
170
|
+
return (
|
|
171
|
+
<WrapperElement
|
|
172
|
+
id={id}
|
|
173
|
+
role="tooltip"
|
|
174
|
+
className={classNames(styles['tooltip'], styles[variant], className, {
|
|
175
|
+
[styles['show']]: isOpen || show,
|
|
176
|
+
[styles['fixed']]: positionStrategy === 'fixed',
|
|
177
|
+
})}
|
|
178
|
+
style={{ ...externalStyles, ...inlineStyles }}
|
|
179
|
+
ref={tooltipRef as React.RefObject<HTMLDivElement>}
|
|
180
|
+
>
|
|
181
|
+
{children || (isHtmlContent ? <TooltipContent content={content as string} /> : content)}
|
|
182
|
+
<div
|
|
183
|
+
className={classNames(styles['arrow'], classNameArrow)}
|
|
184
|
+
style={inlineArrowStyles}
|
|
185
|
+
ref={tooltipArrowRef as React.RefObject<HTMLDivElement>}
|
|
186
|
+
/>
|
|
187
|
+
</WrapperElement>
|
|
188
|
+
)
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export default Tooltip
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ElementType, ReactNode, Element, CSSProperties } from 'react'
|
|
2
|
+
|
|
3
|
+
export type PlacesType = 'top' | 'right' | 'bottom' | 'left'
|
|
4
|
+
|
|
5
|
+
export type VariantType = 'dark' | 'light' | 'success' | 'warning' | 'error' | 'info'
|
|
6
|
+
|
|
7
|
+
export type WrapperType = ElementType | 'div' | 'span'
|
|
8
|
+
|
|
9
|
+
export type ChildrenType = Element | ElementType | ReactNode
|
|
10
|
+
|
|
11
|
+
export type EventsType = 'hover' | 'click'
|
|
12
|
+
|
|
13
|
+
export type PositionStrategy = 'absolute' | 'fixed'
|
|
14
|
+
|
|
15
|
+
export interface ITooltip {
|
|
16
|
+
className?: string
|
|
17
|
+
classNameArrow?: string
|
|
18
|
+
content?: string | number
|
|
19
|
+
html?: string
|
|
20
|
+
place?: PlacesType
|
|
21
|
+
offset?: number
|
|
22
|
+
id?: string
|
|
23
|
+
variant?: VariantType
|
|
24
|
+
anchorId?: string
|
|
25
|
+
isHtmlContent?: boolean
|
|
26
|
+
wrapper?: WrapperType
|
|
27
|
+
children?: ChildrenType
|
|
28
|
+
events?: EventsType[]
|
|
29
|
+
positionStrategy?: PositionStrategy
|
|
30
|
+
delayShow?: number
|
|
31
|
+
delayHide?: number
|
|
32
|
+
style?: CSSProperties
|
|
33
|
+
isOpen?: boolean
|
|
34
|
+
setIsOpen?: (value: boolean) => void
|
|
35
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as Tooltip } from './Tooltip'
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
.tooltip {
|
|
2
|
+
visibility: hidden;
|
|
3
|
+
width: max-content;
|
|
4
|
+
position: absolute;
|
|
5
|
+
top: 0;
|
|
6
|
+
left: 0;
|
|
7
|
+
padding: 8px 16px;
|
|
8
|
+
border-radius: 3px;
|
|
9
|
+
font-size: 90%;
|
|
10
|
+
pointer-events: none;
|
|
11
|
+
opacity: 0;
|
|
12
|
+
transition: opacity 0.3s ease-out;
|
|
13
|
+
will-change: opacity, visibility;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.fixed {
|
|
17
|
+
position: fixed;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.arrow {
|
|
21
|
+
position: absolute;
|
|
22
|
+
background: inherit;
|
|
23
|
+
width: 8px;
|
|
24
|
+
height: 8px;
|
|
25
|
+
transform: rotate(45deg);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.show {
|
|
29
|
+
visibility: visible;
|
|
30
|
+
opacity: 0.9;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Types variant **/
|
|
34
|
+
.dark {
|
|
35
|
+
background: var(--rt-color-dark);
|
|
36
|
+
color: var(--rt-color-white);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.light {
|
|
40
|
+
background-color: var(--rt-color-white);
|
|
41
|
+
color: var(--rt-color-dark);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.success {
|
|
45
|
+
background-color: var(--rt-color-success);
|
|
46
|
+
color: var(--rt-color-white);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.warning {
|
|
50
|
+
background-color: var(--rt-color-warning);
|
|
51
|
+
color: var(--rt-color-white);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.error {
|
|
55
|
+
background-color: var(--rt-color-error);
|
|
56
|
+
color: var(--rt-color-white);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.info {
|
|
60
|
+
background-color: var(--rt-color-info);
|
|
61
|
+
color: var(--rt-color-white);
|
|
62
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as TooltipContent } from './TooltipContent'
|