primereact
Version:
PrimeReact is an open source UI library for React featuring a rich set of 90+ components, a theme designer, various theme alternatives such as Material, Bootstrap, Tailwind, premium templates and professional support. In addition, it integrates with Prime
2 lines (1 loc) • 13.6 kB
JavaScript
this.primereact=this.primereact||{},this.primereact.tooltip=function(t,e,r,n,o,i,a){"use strict";function l(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}function u(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(e,r,n.get?n:{enumerable:!0,get:function(){return t[r]}})}})),e.default=t,Object.freeze(e)}var c=u(e),s=l(r);function p(){return p=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},p.apply(this,arguments)}function f(t){return f="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},f(t)}function d(t,e){if("object"!==f(t)||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e||"default");if("object"!==f(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}function m(t){var e=d(t,"string");return"symbol"===f(e)?e:String(e)}function h(t,e,r){return(e=m(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function v(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function y(t){if(Array.isArray(t))return v(t)}function b(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}function g(t,e){if(t){if("string"==typeof t)return v(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?v(t,e):void 0}}function w(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function E(t){if(Array.isArray(t))return t}function O(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,o,i,a,l=[],u=!0,c=!1;try{if(i=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;u=!1}else for(;!(u=(n=i.call(r)).done)&&(l.push(n.value),l.length!==e);u=!0);}catch(t){c=!0,o=t}finally{try{if(!u&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(c)throw o}}return l}}function x(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function S(t,e){return E(t)||O(t,e)||g(t,e)||x()}var T=n.ComponentBase.extend({defaultProps:{__TYPE:"Tooltip",appendTo:null,at:null,autoHide:!0,autoZIndex:!0,baseZIndex:0,className:null,closeOnEscape:!1,content:null,disabled:!1,event:null,hideDelay:0,hideEvent:"mouseleave",id:null,mouseTrack:!1,mouseTrackLeft:5,mouseTrackTop:5,my:null,onBeforeHide:null,onBeforeShow:null,onHide:null,onShow:null,position:"right",showDelay:0,showEvent:"mouseenter",showOnDisabled:!1,style:null,target:null,updateDelay:0,children:void 0},css:{classes:{root:function(t){var e=t.classNameState;return a.classNames("p-tooltip p-component",h({},"p-tooltip-".concat(t.positionState),!0),e)},arrow:"p-tooltip-arrow",text:"p-tooltip-text"},styles:"\n@layer primereact {\n .p-tooltip {\n position: absolute;\n padding: .25em .5rem;\n /* #3687: Tooltip prevent scrollbar flickering */\n top: -9999px;\n left: -9999px;\n }\n \n .p-tooltip.p-tooltip-right,\n .p-tooltip.p-tooltip-left {\n padding: 0 .25rem;\n }\n \n .p-tooltip.p-tooltip-top,\n .p-tooltip.p-tooltip-bottom {\n padding:.25em 0;\n }\n \n .p-tooltip .p-tooltip-text {\n white-space: pre-line;\n word-break: break-word;\n }\n \n .p-tooltip-arrow {\n position: absolute;\n width: 0;\n height: 0;\n border-color: transparent;\n border-style: solid;\n }\n \n .p-tooltip-right .p-tooltip-arrow {\n top: 50%;\n left: 0;\n margin-top: -.25rem;\n border-width: .25em .25em .25em 0;\n }\n \n .p-tooltip-left .p-tooltip-arrow {\n top: 50%;\n right: 0;\n margin-top: -.25rem;\n border-width: .25em 0 .25em .25rem;\n }\n \n .p-tooltip.p-tooltip-top {\n padding: .25em 0;\n }\n \n .p-tooltip-top .p-tooltip-arrow {\n bottom: 0;\n left: 50%;\n margin-left: -.25rem;\n border-width: .25em .25em 0;\n }\n \n .p-tooltip-bottom .p-tooltip-arrow {\n top: 0;\n left: 50%;\n margin-left: -.25rem;\n border-width: 0 .25em .25rem;\n }\n\n .p-tooltip-target-wrapper {\n display: inline-flex;\n }\n}\n",inlineStyles:{arrow:function(t){var e=t.context;return{top:e.bottom?"0":e.right||e.left||!e.right&&!e.left&&!e.top&&!e.bottom?"50%":null,bottom:e.top?"0":null,left:!e.right&&(e.right||e.left||e.top||e.bottom)?e.top||e.bottom?"50%":null:"0",right:e.left?"0":null}}}}});function j(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function D(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?j(Object(r),!0).forEach((function(e){h(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):j(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}var H=c.memo(c.forwardRef((function(t,e){var l=o.useMergeProps(),u=c.useContext(r.PrimeReactContext),f=T.getProps(t,u),d=S(c.useState(!1),2),m=d[0],h=d[1],v=S(c.useState(f.position||"right"),2),E=v[0],O=v[1],x=S(c.useState(""),2),j=x[0],H=x[1],P=S(c.useState(!1),2),I=P[0],k=P[1],N={props:f,state:{visible:m,position:E,className:j},context:{right:"right"===E,left:"left"===E,top:"top"===E,bottom:"bottom"===E}},C=T.setMetaData(N),A=C.ptm,L=C.cx,R=C.sx;n.useHandleStyle(T.css.styles,C.isUnstyled,{name:"tooltip"}),o.useGlobalOnEscapeKey({callback:function(){ut()},when:f.closeOnEscape,priority:[o.ESC_KEY_HANDLING_PRIORITIES.TOOLTIP,0]});var U=c.useRef(null),M=c.useRef(null),Z=c.useRef(null),_=c.useRef(null),W=c.useRef(!0),B=c.useRef({}),z=c.useRef(null),F=S(o.useResizeListener({listener:function(t){!a.DomHandler.isTouchDevice()&&ut(t)}}),2),Y=F[0],G=F[1],K=S(o.useOverlayScrollListener({target:Z.current,listener:function(t){ut(t)},when:m}),2),X=K[0],$=K[1],q=function(t){return tt(t,"mousetrack")||f.mouseTrack},J=function(t){return"true"===tt(t,"disabled")||et(t,"disabled")||f.disabled},Q=function(t){return tt(t,"showondisabled")||f.showOnDisabled},V=function(){return tt(Z.current,"autohide")||f.autoHide},tt=function(t,e){return et(t,"data-pr-".concat(e))?t.getAttribute("data-pr-".concat(e)):null},et=function(t,e){return t&&t.hasAttribute(e)},rt=function(t){var e=[tt(t,"showevent")||f.showEvent],r=[tt(t,"hideevent")||f.hideEvent];if(q(t))e=["mousemove"],r=["mouseleave"];else{var n=tt(t,"event")||f.event;"focus"===n&&(e=["focus"],r=["blur"]),"both"===n&&(e=["focus","mouseenter"],r=I?["blur"]:["mouseleave","blur"])}return{showEvents:e,hideEvents:r}},nt=function(t){return tt(t,"position")||E},ot=function(t){return{top:tt(t,"mousetracktop")||f.mouseTrackTop,left:tt(t,"mousetrackleft")||f.mouseTrackLeft}},it=function(t,e){if(M.current){var r=tt(t,"tooltip")||f.content;r?(M.current.innerHTML="",M.current.appendChild(document.createTextNode(r)),e()):f.children&&e()}},at=function(t){it(Z.current,(function(){var e=z.current,r=e.pageX,n=e.pageY;f.autoZIndex&&!a.ZIndexUtils.get(U.current)&&a.ZIndexUtils.set("tooltip",U.current,u&&u.autoZIndex||s.default.autoZIndex,f.baseZIndex||u&&u.zIndex.tooltip||s.default.zIndex.tooltip),U.current.style.left="",U.current.style.top="",V()&&(U.current.style.pointerEvents="none");var o=q(Z.current)||"mouse"===t;(o&&!_.current||o)&&(_.current={width:a.DomHandler.getOuterWidth(U.current),height:a.DomHandler.getOuterHeight(U.current)}),ct(Z.current,{x:r,y:n},t)}))},lt=function(t){t.type&&"focus"===t.type&&k(!0),Z.current=t.currentTarget;var e,r=J(Z.current);(e=Q(Z.current)&&r?Z.current.firstChild:Z.current,!(f.content||tt(e,"tooltip")||f.children))||r||(z.current=t,m?mt("updateDelay",at):ht(f.onBeforeShow,{originalEvent:t,target:Z.current})&&mt("showDelay",(function(){h(!0),ht(f.onShow,{originalEvent:t,target:Z.current})})))},ut=function(t){(t&&"blur"===t.type&&k(!1),vt(),m)&&(ht(f.onBeforeHide,{originalEvent:t,target:Z.current})&&mt("hideDelay",(function(){(V()||!1!==W.current)&&(a.ZIndexUtils.clear(U.current),a.DomHandler.removeClass(U.current,"p-tooltip-active"),h(!1),ht(f.onHide,{originalEvent:t,target:Z.current}))})))},ct=function(t,e,r){var n=0,o=0,i=r||E;if((q(t)||"mouse"==i)&&e){var l={width:a.DomHandler.getOuterWidth(U.current),height:a.DomHandler.getOuterHeight(U.current)};n=e.x,o=e.y;var u=ot(t),c=u.top,s=u.left;switch(i){case"left":n-=l.width+s,o-=l.height/2-c;break;case"right":case"mouse":n+=s,o-=l.height/2-c;break;case"top":n-=l.width/2-s,o-=l.height+c;break;case"bottom":n-=l.width/2-s,o+=c}n<=0||_.current.width>l.width?(U.current.style.left="0px",U.current.style.right=window.innerWidth-l.width-n+"px"):(U.current.style.right="",U.current.style.left=n+"px"),U.current.style.top=o+"px",a.DomHandler.addClass(U.current,"p-tooltip-active")}else{var p=a.DomHandler.findCollisionPosition(i),d=tt(t,"my")||f.my||p.my,m=tt(t,"at")||f.at||p.at;U.current.style.padding="0px",a.DomHandler.flipfitCollision(U.current,t,d,m,(function(t){var e=t.at,r=e.x,n=f.at?"center"!==r&&r!==t.my.x?r:e.y:t.at["".concat(p.axis)];U.current.style.padding="",O(n),st(n),a.DomHandler.addClass(U.current,"p-tooltip-active")}))}},st=function(t){if(U.current){var e=getComputedStyle(U.current);"left"===t?U.current.style.left=parseFloat(e.left)-2*parseFloat(e.paddingLeft)+"px":"top"===t&&(U.current.style.top=parseFloat(e.top)-2*parseFloat(e.paddingTop)+"px")}},pt=function(t){V()||(W.current=!0,ut(t))},ft=function(t){if(t){var e=rt(t),r=e.showEvents,n=e.hideEvents,o=yt(t);r.forEach((function(t){return null==o?void 0:o.addEventListener(t,lt)})),n.forEach((function(t){return null==o?void 0:o.addEventListener(t,ut)}))}},dt=function(t){if(t){var e=rt(t),r=e.showEvents,n=e.hideEvents,o=yt(t);r.forEach((function(t){return null==o?void 0:o.removeEventListener(t,lt)})),n.forEach((function(t){return null==o?void 0:o.removeEventListener(t,ut)}))}},mt=function(t,e){vt();var r=tt(Z.current,t.toLowerCase())||f[t];r?B.current["".concat(t)]=setTimeout((function(){return e()}),r):e()},ht=function(t){if(t){for(var e=arguments.length,r=new Array(e>1?e-1:0),n=1;n<e;n++)r[n-1]=arguments[n];var o=t.apply(void 0,r);return void 0===o&&(o=!0),o}return!0},vt=function(){Object.values(B.current).forEach((function(t){return clearTimeout(t)}))},yt=function(t){if(t){if(Q(t)){if(!t.hasWrapper){var e=document.createElement("div");return"INPUT"===t.nodeName?a.DomHandler.addMultipleClasses(e,"p-tooltip-target-wrapper p-inputwrapper"):a.DomHandler.addClass(e,"p-tooltip-target-wrapper"),t.parentNode.insertBefore(e,t),e.appendChild(t),t.hasWrapper=!0,e}return t.parentElement}var r;return t.hasWrapper&&((r=t.parentElement).replaceWith.apply(r,y(n=t.parentElement.childNodes)||b(n)||g(n)||w()),delete t.hasWrapper),t}var n;return null},bt=function(t){wt(t),gt(t)},gt=function(t){Et(t||f.target,ft)},wt=function(t){Et(t||f.target,dt)},Et=function(t,e){if(t=a.ObjectUtils.getRefElement(t))if(a.DomHandler.isElement(t))e(t);else{var r=function(t){a.DomHandler.find(document,t).forEach((function(t){e(t)}))};t instanceof Array?t.forEach((function(t){r(t)})):r(t)}};o.useMountEffect((function(){m&&Z.current&&J(Z.current)&&ut()})),o.useUpdateEffect((function(){return gt(),function(){wt()}}),[lt,ut,f.target]),o.useUpdateEffect((function(){if(m){var t=nt(Z.current),e=tt(Z.current,"classname");O(t),H(e),at(t),Y(),X()}else O(f.position||"right"),H(""),Z.current=null,_.current=null,W.current=!0;return function(){G(),$()}}),[m]),o.useUpdateEffect((function(){var t=nt(Z.current);m&&"mouse"!==t&&mt("updateDelay",(function(){it(Z.current,(function(){ct(Z.current)}))}))}),[f.content]),o.useUnmountEffect((function(){ut(),a.ZIndexUtils.clear(U.current)})),c.useImperativeHandle(e,(function(){return{props:f,updateTargetEvents:bt,loadTargetEvents:gt,unloadTargetEvents:wt,show:lt,hide:ut,getElement:function(){return U.current},getTarget:function(){return Z.current}}}));var Ot,xt,St,Tt,jt;if(m){var Dt=(Ot=Z.current,xt=!(f.content||tt(Ot,"tooltip")),St=l({id:f.id,className:a.classNames(f.className,L("root",{positionState:E,classNameState:j})),style:f.style,role:"tooltip","aria-hidden":m,onMouseEnter:function(t){V()||(W.current=!1)},onMouseLeave:function(t){return pt(t)}},T.getOtherProps(f),A("root")),Tt=l({className:L("arrow"),style:R("arrow",D({},N))},A("arrow")),jt=l({className:L("text")},A("text")),c.createElement("div",p({ref:U},St),c.createElement("div",Tt),c.createElement("div",p({ref:M},jt),xt&&f.children)));return c.createElement(i.Portal,{element:Dt,appendTo:f.appendTo,visible:!0})}return null})));return H.displayName="Tooltip",t.Tooltip=H,Object.defineProperty(t,"__esModule",{value:!0}),t}({},React,primereact.api,primereact.componentbase,primereact.hooks,primereact.portal,primereact.utils);