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.5 kB
JavaScript
Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react"),e=require("primereact/api"),r=require("primereact/componentbase"),n=require("primereact/hooks"),o=require("primereact/portal"),i=require("primereact/utils");function a(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 l=u(t),c=a(e);function s(){return s=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},s.apply(this,arguments)}function p(t){return p="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},p(t)}function f(t,e){if("object"!==p(t)||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e||"default");if("object"!==p(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}function d(t){var e=f(t,"string");return"symbol"===p(e)?e:String(e)}function m(t,e,r){return(e=d(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function h(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 v(t){if(Array.isArray(t))return h(t)}function y(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}function b(t,e){if(t){if("string"==typeof t)return h(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)?h(t,e):void 0}}function g(){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 w(t){if(Array.isArray(t))return t}function E(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,o,i,a,u=[],l=!0,c=!1;try{if(i=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;l=!1}else for(;!(l=(n=i.call(r)).done)&&(u.push(n.value),u.length!==e);l=!0);}catch(t){c=!0,o=t}finally{try{if(!l&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(c)throw o}}return u}}function O(){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 x(t,e){return w(t)||E(t,e)||b(t,e)||O()}var S=r.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 i.classNames("p-tooltip p-component",m({},"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 T(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 j(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?T(Object(r),!0).forEach((function(e){m(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):T(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}var D=l.memo(l.forwardRef((function(t,a){var u=n.useMergeProps(),p=l.useContext(e.PrimeReactContext),f=S.getProps(t,p),d=x(l.useState(!1),2),m=d[0],h=d[1],w=x(l.useState(f.position||"right"),2),E=w[0],O=w[1],T=x(l.useState(""),2),D=T[0],H=T[1],P=x(l.useState(!1),2),I=P[0],k=P[1],N={props:f,state:{visible:m,position:E,className:D},context:{right:"right"===E,left:"left"===E,top:"top"===E,bottom:"bottom"===E}},C=S.setMetaData(N),A=C.ptm,L=C.cx,R=C.sx;r.useHandleStyle(S.css.styles,C.isUnstyled,{name:"tooltip"}),n.useGlobalOnEscapeKey({callback:function(){lt()},when:f.closeOnEscape,priority:[n.ESC_KEY_HANDLING_PRIORITIES.TOOLTIP,0]});var U=l.useRef(null),M=l.useRef(null),Z=l.useRef(null),_=l.useRef(null),W=l.useRef(!0),q=l.useRef({}),B=l.useRef(null),z=x(n.useResizeListener({listener:function(t){!i.DomHandler.isTouchDevice()&<(t)}}),2),F=z[0],Y=z[1],G=x(n.useOverlayScrollListener({target:Z.current,listener:function(t){lt(t)},when:m}),2),K=G[0],X=G[1],$=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($(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=B.current,r=e.pageX,n=e.pageY;f.autoZIndex&&!i.ZIndexUtils.get(U.current)&&i.ZIndexUtils.set("tooltip",U.current,p&&p.autoZIndex||c.default.autoZIndex,f.baseZIndex||p&&p.zIndex.tooltip||c.default.zIndex.tooltip),U.current.style.left="",U.current.style.top="",V()&&(U.current.style.pointerEvents="none");var o=$(Z.current)||"mouse"===t;(o&&!_.current||o)&&(_.current={width:i.DomHandler.getOuterWidth(U.current),height:i.DomHandler.getOuterHeight(U.current)}),ct(Z.current,{x:r,y:n},t)}))},ut=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||(B.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})})))},lt=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)&&(i.ZIndexUtils.clear(U.current),i.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,a=r||E;if(($(t)||"mouse"==a)&&e){var u={width:i.DomHandler.getOuterWidth(U.current),height:i.DomHandler.getOuterHeight(U.current)};n=e.x,o=e.y;var l=ot(t),c=l.top,s=l.left;switch(a){case"left":n-=u.width+s,o-=u.height/2-c;break;case"right":case"mouse":n+=s,o-=u.height/2-c;break;case"top":n-=u.width/2-s,o-=u.height+c;break;case"bottom":n-=u.width/2-s,o+=c}n<=0||_.current.width>u.width?(U.current.style.left="0px",U.current.style.right=window.innerWidth-u.width-n+"px"):(U.current.style.right="",U.current.style.left=n+"px"),U.current.style.top=o+"px",i.DomHandler.addClass(U.current,"p-tooltip-active")}else{var p=i.DomHandler.findCollisionPosition(a),d=tt(t,"my")||f.my||p.my,m=tt(t,"at")||f.at||p.at;U.current.style.padding="0px",i.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),i.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,lt(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,ut)})),n.forEach((function(t){return null==o?void 0:o.addEventListener(t,lt)}))}},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,ut)})),n.forEach((function(t){return null==o?void 0:o.removeEventListener(t,lt)}))}},mt=function(t,e){vt();var r=tt(Z.current,t.toLowerCase())||f[t];r?q.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(q.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?i.DomHandler.addMultipleClasses(e,"p-tooltip-target-wrapper p-inputwrapper"):i.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,v(n=t.parentElement.childNodes)||y(n)||b(n)||g()),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=i.ObjectUtils.getRefElement(t))if(i.DomHandler.isElement(t))e(t);else{var r=function(t){i.DomHandler.find(document,t).forEach((function(t){e(t)}))};t instanceof Array?t.forEach((function(t){r(t)})):r(t)}};n.useMountEffect((function(){m&&Z.current&&J(Z.current)&<()})),n.useUpdateEffect((function(){return gt(),function(){wt()}}),[ut,lt,f.target]),n.useUpdateEffect((function(){if(m){var t=nt(Z.current),e=tt(Z.current,"classname");O(t),H(e),at(t),F(),K()}else O(f.position||"right"),H(""),Z.current=null,_.current=null,W.current=!0;return function(){Y(),X()}}),[m]),n.useUpdateEffect((function(){var t=nt(Z.current);m&&"mouse"!==t&&mt("updateDelay",(function(){it(Z.current,(function(){ct(Z.current)}))}))}),[f.content]),n.useUnmountEffect((function(){lt(),i.ZIndexUtils.clear(U.current)})),l.useImperativeHandle(a,(function(){return{props:f,updateTargetEvents:bt,loadTargetEvents:gt,unloadTargetEvents:wt,show:ut,hide:lt,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=u({id:f.id,className:i.classNames(f.className,L("root",{positionState:E,classNameState:D})),style:f.style,role:"tooltip","aria-hidden":m,onMouseEnter:function(t){V()||(W.current=!1)},onMouseLeave:function(t){return pt(t)}},S.getOtherProps(f),A("root")),Tt=u({className:L("arrow"),style:R("arrow",j({},N))},A("arrow")),jt=u({className:L("text")},A("text")),l.createElement("div",s({ref:U},St),l.createElement("div",Tt),l.createElement("div",s({ref:M},jt),xt&&f.children)));return l.createElement(o.Portal,{element:Dt,appendTo:f.appendTo,visible:!0})}return null})));D.displayName="Tooltip",exports.Tooltip=D;
;