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.4 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 l(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 u=l(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,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 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=u.memo(u.forwardRef((function(t,a){var l=n.useMergeProps(),p=u.useContext(e.PrimeReactContext),f=S.getProps(t,p),d=x(u.useState(!1),2),m=d[0],h=d[1],w=x(u.useState(f.position||"right"),2),E=w[0],O=w[1],T=x(u.useState(""),2),D=T[0],H=T[1],P={props:f,state:{visible:m,position:E,className:D},context:{right:"right"===E,left:"left"===E,top:"top"===E,bottom:"bottom"===E}},I=S.setMetaData(P),k=I.ptm,N=I.cx,C=I.sx;r.useHandleStyle(S.css.styles,I.isUnstyled,{name:"tooltip"}),n.useGlobalOnEscapeKey({callback:function(){it()},when:f.closeOnEscape,priority:[n.ESC_KEY_HANDLING_PRIORITIES.TOOLTIP,0]});var A=u.useRef(null),L=u.useRef(null),R=u.useRef(null),U=u.useRef(null),M=u.useRef(!0),Z=u.useRef({}),_=u.useRef(null),W=x(n.useResizeListener({listener:function(t){!i.DomHandler.isTouchDevice()&&it(t)}}),2),q=W[0],B=W[1],z=x(n.useOverlayScrollListener({target:R.current,listener:function(t){it(t)},when:m}),2),F=z[0],Y=z[1],G=function(t){return J(t,"mousetrack")||f.mouseTrack},K=function(t){return"true"===J(t,"disabled")||Q(t,"disabled")||f.disabled},X=function(t){return J(t,"showondisabled")||f.showOnDisabled},$=function(){return J(R.current,"autohide")||f.autoHide},J=function(t,e){return Q(t,"data-pr-".concat(e))?t.getAttribute("data-pr-".concat(e)):null},Q=function(t,e){return t&&t.hasAttribute(e)},V=function(t){var e=[J(t,"showevent")||f.showEvent],r=[J(t,"hideevent")||f.hideEvent];if(G(t))e=["mousemove"],r=["mouseleave"];else{var n=J(t,"event")||f.event;"focus"===n&&(e=["focus"],r=["blur"]),"both"===n&&(e=["focus","mouseenter"],r=["blur","mouseleave"])}return{showEvents:e,hideEvents:r}},tt=function(t){return J(t,"position")||E},et=function(t){return{top:J(t,"mousetracktop")||f.mouseTrackTop,left:J(t,"mousetrackleft")||f.mouseTrackLeft}},rt=function(t,e){if(L.current){var r=J(t,"tooltip")||f.content;r?(L.current.innerHTML="",L.current.appendChild(document.createTextNode(r)),e()):f.children&&e()}},nt=function(t){rt(R.current,(function(){var e=_.current,r=e.pageX,n=e.pageY;f.autoZIndex&&!i.ZIndexUtils.get(A.current)&&i.ZIndexUtils.set("tooltip",A.current,p&&p.autoZIndex||c.default.autoZIndex,f.baseZIndex||p&&p.zIndex.tooltip||c.default.zIndex.tooltip),A.current.style.left="",A.current.style.top="",$()&&(A.current.style.pointerEvents="none");var o=G(R.current)||"mouse"===t;(o&&!U.current||o)&&(U.current={width:i.DomHandler.getOuterWidth(A.current),height:i.DomHandler.getOuterHeight(A.current)}),at(R.current,{x:r,y:n},t)}))},ot=function(t){R.current=t.currentTarget;var e,r=K(R.current);(e=X(R.current)&&r?R.current.firstChild:R.current,!(f.content||J(e,"tooltip")||f.children))||r||(_.current=t,m?pt("updateDelay",nt):ft(f.onBeforeShow,{originalEvent:t,target:R.current})&&pt("showDelay",(function(){h(!0),ft(f.onShow,{originalEvent:t,target:R.current})})))},it=function(t){(dt(),m)&&(ft(f.onBeforeHide,{originalEvent:t,target:R.current})&&pt("hideDelay",(function(){($()||!1!==M.current)&&(i.ZIndexUtils.clear(A.current),i.DomHandler.removeClass(A.current,"p-tooltip-active"),h(!1),ft(f.onHide,{originalEvent:t,target:R.current}))})))},at=function(t,e,r){var n=0,o=0,a=r||E;if((G(t)||"mouse"==a)&&e){var l={width:i.DomHandler.getOuterWidth(A.current),height:i.DomHandler.getOuterHeight(A.current)};n=e.x,o=e.y;var u=et(t),c=u.top,s=u.left;switch(a){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||U.current.width>l.width?(A.current.style.left="0px",A.current.style.right=window.innerWidth-l.width-n+"px"):(A.current.style.right="",A.current.style.left=n+"px"),A.current.style.top=o+"px",i.DomHandler.addClass(A.current,"p-tooltip-active")}else{var p=i.DomHandler.findCollisionPosition(a),d=J(t,"my")||f.my||p.my,m=J(t,"at")||f.at||p.at;A.current.style.padding="0px",i.DomHandler.flipfitCollision(A.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)];A.current.style.padding="",O(n),lt(n),i.DomHandler.addClass(A.current,"p-tooltip-active")}))}},lt=function(t){if(A.current){var e=getComputedStyle(A.current);"left"===t?A.current.style.left=parseFloat(e.left)-2*parseFloat(e.paddingLeft)+"px":"top"===t&&(A.current.style.top=parseFloat(e.top)-2*parseFloat(e.paddingTop)+"px")}},ut=function(t){$()||(M.current=!0,it(t))},ct=function(t){if(t){var e=V(t),r=e.showEvents,n=e.hideEvents,o=mt(t);r.forEach((function(t){return null==o?void 0:o.addEventListener(t,ot)})),n.forEach((function(t){return null==o?void 0:o.addEventListener(t,it)}))}},st=function(t){if(t){var e=V(t),r=e.showEvents,n=e.hideEvents,o=mt(t);r.forEach((function(t){return null==o?void 0:o.removeEventListener(t,ot)})),n.forEach((function(t){return null==o?void 0:o.removeEventListener(t,it)}))}},pt=function(t,e){dt();var r=J(R.current,t.toLowerCase())||f[t];r?Z.current["".concat(t)]=setTimeout((function(){return e()}),r):e()},ft=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},dt=function(){Object.values(Z.current).forEach((function(t){return clearTimeout(t)}))},mt=function(t){if(t){if(X(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},ht=function(t){yt(t),vt(t)},vt=function(t){bt(t||f.target,ct)},yt=function(t){bt(t||f.target,st)},bt=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&&R.current&&K(R.current)&&it()})),n.useUpdateEffect((function(){return vt(),function(){yt()}}),[ot,it,f.target]),n.useUpdateEffect((function(){if(m){var t=tt(R.current),e=J(R.current,"classname");O(t),H(e),nt(t),q(),F()}else O(f.position||"right"),H(""),R.current=null,U.current=null,M.current=!0;return function(){B(),Y()}}),[m]),n.useUpdateEffect((function(){var t=tt(R.current);m&&"mouse"!==t&&pt("updateDelay",(function(){rt(R.current,(function(){at(R.current)}))}))}),[f.content]),n.useUnmountEffect((function(){it(),i.ZIndexUtils.clear(A.current)})),u.useImperativeHandle(a,(function(){return{props:f,updateTargetEvents:ht,loadTargetEvents:vt,unloadTargetEvents:yt,show:ot,hide:it,getElement:function(){return A.current},getTarget:function(){return R.current}}}));var gt,wt,Et,Ot,xt;if(m){var St=(gt=R.current,wt=!(f.content||J(gt,"tooltip")),Et=l({id:f.id,className:i.classNames(f.className,N("root",{positionState:E,classNameState:D})),style:f.style,role:"tooltip","aria-hidden":m,onMouseEnter:function(t){$()||(M.current=!1)},onMouseLeave:function(t){return ut(t)}},S.getOtherProps(f),k("root")),Ot=l({className:N("arrow"),style:C("arrow",j({},P))},k("arrow")),xt=l({className:N("text")},k("text")),u.createElement("div",s({ref:A},Et),u.createElement("div",Ot),u.createElement("div",s({ref:L},xt),wt&&f.children)));return u.createElement(o.Portal,{element:St,appendTo:f.appendTo,visible:!0})}return null})));D.displayName="Tooltip",exports.Tooltip=D;
;