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.46 kB
JavaScript
import*as t from"react";import e from"primereact/api";import{CSSTransition as r}from"primereact/csstransition";import{useEventListener as n,useMountEffect as o,useUnmountEffect as l}from"primereact/hooks";import{Ripple as i}from"primereact/ripple";import{ObjectUtils as a,DomHandler as c,ZIndexUtils as u,classNames as s,IconUtils as p}from"primereact/utils";function f(){return f=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},f.apply(this,arguments)}function m(t){if(Array.isArray(t))return t}function d(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,o,l,i,a=[],c=!0,u=!1;try{if(l=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;c=!1}else for(;!(c=(n=l.call(r)).done)&&(a.push(n.value),a.length!==e);c=!0);}catch(t){u=!0,o=t}finally{try{if(!c&&null!=r.return&&(i=r.return(),Object(i)!==i))return}finally{if(u)throw o}}return a}}function y(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 g(t,e){if(t){if("string"==typeof t)return y(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)?y(t,e):void 0}}function h(){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 v(t,e){return m(t)||d(t,e)||g(t,e)||h()}var w={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(t){return a.getMergedProps(t,w.defaultProps)},getOtherProps:function(t){return a.getDiffProps(t,w.defaultProps)}},b=t.memo(t.forwardRef((function(a,m){var d=w.getProps(a),y=v(t.useState(!1),2),g=y[0],h=y[1],b=t.useRef(null),E=t.useRef(null),O="parent"===d.target,S=v(n({target:function(){return E.current&&E.current.parentElement},type:"scroll",listener:function(t){j(t.currentTarget.scrollTop)}}),1)[0],P=v(n({target:"window",type:"scroll",listener:function(){j(c.getWindowScrollTop())}}),1)[0],j=function(t){h(t>d.threshold)};t.useImperativeHandle(m,(function(){return{props:d,getElement:function(){return elementRef.current}}})),o((function(){"window"===d.target?P():"parent"===d.target&&S()})),l((function(){u.clear(b.current)}));var x=w.getOtherProps(d),I=s("p-scrolltop p-link p-component",{"p-scrolltop-sticky":"window"!==d.target},d.className);return t.createElement(t.Fragment,null,t.createElement(r,{nodeRef:b,classNames:"p-scrolltop",in:g,timeout:{enter:150,exit:150},options:d.transitionOptions,unmountOnExit:!0,onEnter:function(){u.set("overlay",b.current,e.autoZIndex,e.zIndex.overlay)},onEntered:function(){d.onShow&&d.onShow()},onExited:function(){u.clear(b.current),d.onHide&&d.onHide()}},t.createElement("button",f({ref:b,type:"button",className:I,style:d.style},x,{onClick:function(){("window"===d.target?window:E.current.parentElement).scroll({top:0,behavior:d.behavior})}}),p.getJSXIcon(d.icon,{className:"p-scrolltop-icon"},{props:d}),t.createElement(i,null))),O&&t.createElement("span",{ref:E,className:"p-scrolltop-helper"}))})));b.displayName="ScrollTop";export{b as ScrollTop};