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) • 3.92 kB
JavaScript
Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("primereact/api"),r=require("primereact/csstransition"),n=require("primereact/hooks"),o=require("primereact/ripple"),l=require("primereact/utils");function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function a(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var u=a(e),c=i(t);function s(){return s=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},s.apply(this,arguments)}function p(e){if(Array.isArray(e))return e}function f(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,l,i,a=[],u=!0,c=!1;try{if(l=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;u=!1}else for(;!(u=(n=l.call(r)).done)&&(a.push(n.value),a.length!==t);u=!0);}catch(e){c=!0,o=e}finally{try{if(!u&&null!=r.return&&(i=r.return(),Object(i)!==i))return}finally{if(c)throw o}}return a}}function d(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function m(e,t){if(e){if("string"==typeof e)return d(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?d(e,t):void 0}}function y(){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 g(e,t){return p(e)||f(e,t)||m(e,t)||y()}var b={defaultProps:{__TYPE:"ScrollTop",target:"window",threshold:400,icon:"pi pi-chevron-up",behavior:"smooth",className:null,style:null,transitionOptions:null,onShow:null,onHide:null,children:void 0},getProps:function(e){return l.ObjectUtils.getMergedProps(e,b.defaultProps)},getOtherProps:function(e){return l.ObjectUtils.getDiffProps(e,b.defaultProps)}},h=u.memo(u.forwardRef((function(e,t){var i=b.getProps(e),a=g(u.useState(!1),2),p=a[0],f=a[1],d=u.useRef(null),m=u.useRef(null),y="parent"===i.target,h=g(n.useEventListener({target:function(){return m.current&&m.current.parentElement},type:"scroll",listener:function(e){w(e.currentTarget.scrollTop)}}),1)[0],v=g(n.useEventListener({target:"window",type:"scroll",listener:function(){w(l.DomHandler.getWindowScrollTop())}}),1)[0],w=function(e){f(e>i.threshold)};u.useImperativeHandle(t,(function(){return{props:i,getElement:function(){return elementRef.current}}})),n.useMountEffect((function(){"window"===i.target?v():"parent"===i.target&&h()})),n.useUnmountEffect((function(){l.ZIndexUtils.clear(d.current)}));var O=b.getOtherProps(i),E=l.classNames("p-scrolltop p-link p-component",{"p-scrolltop-sticky":"window"!==i.target},i.className);return u.createElement(u.Fragment,null,u.createElement(r.CSSTransition,{nodeRef:d,classNames:"p-scrolltop",in:p,timeout:{enter:150,exit:150},options:i.transitionOptions,unmountOnExit:!0,onEnter:function(){l.ZIndexUtils.set("overlay",d.current,c.default.autoZIndex,c.default.zIndex.overlay)},onEntered:function(){i.onShow&&i.onShow()},onExited:function(){l.ZIndexUtils.clear(d.current),i.onHide&&i.onHide()}},u.createElement("button",s({ref:d,type:"button",className:E,style:i.style},O,{onClick:function(){("window"===i.target?window:m.current.parentElement).scroll({top:0,behavior:i.behavior})}}),l.IconUtils.getJSXIcon(i.icon,{className:"p-scrolltop-icon"},{props:i}),u.createElement(o.Ripple,null))),y&&u.createElement("span",{ref:m,className:"p-scrolltop-helper"}))})));h.displayName="ScrollTop",exports.ScrollTop=h;
;