UNPKG

primereact

Version:

PrimeReact is an open source UI library for React featuring a rich set of 80+ 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.23 kB
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{DomHandler as a,ZIndexUtils as c,ObjectUtils 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=!0,a=!1;try{for(r=r.call(t);!(i=(n=r.next()).done)&&(l.push(n.value),!e||l.length!==e);i=!0);}catch(t){a=!0,o=t}finally{try{i||null==r.return||r.return()}finally{if(a)throw o}}return l}}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 h(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 g(){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 w(t,e){return m(t)||d(t,e)||h(t,e)||g()}var v=t.memo(t.forwardRef((function(m,d){var y=w(t.useState(!1),2),h=y[0],g=y[1],b=t.useRef(null),E=t.useRef(null),S="parent"===m.target,O=w(n({target:function(){return E.current&&E.current.parentElement},type:"scroll",listener:function(t){I(t.currentTarget.scrollTop)}}),1)[0],x=w(n({target:"window",type:"scroll",listener:function(){I(a.getWindowScrollTop())}}),1)[0],I=function(t){g(t>m.threshold)};t.useImperativeHandle(d,(function(){return{props:m,getElement:function(){return elementRef.current}}})),o((function(){"window"===m.target?x():"parent"===m.target&&O()})),l((function(){c.clear(b.current)}));var N=u.findDiffKeys(m,v.defaultProps),T=s("p-scrolltop p-link p-component",{"p-scrolltop-sticky":"window"!==m.target},m.className);return t.createElement(t.Fragment,null,t.createElement(r,{nodeRef:b,classNames:"p-scrolltop",in:h,timeout:{enter:150,exit:150},options:m.transitionOptions,unmountOnExit:!0,onEnter:function(){c.set("overlay",b.current,e.autoZIndex,e.zIndex.overlay)},onEntered:function(){m.onShow&&m.onShow()},onExited:function(){c.clear(b.current),m.onHide&&m.onHide()}},t.createElement("button",f({ref:b,type:"button",className:T,style:m.style},N,{onClick:function(){("window"===m.target?window:E.current.parentElement).scroll({top:0,behavior:m.behavior})}}),p.getJSXIcon(m.icon,{className:"p-scrolltop-icon"},{props:m}),t.createElement(i,null))),S&&t.createElement("span",{ref:E,className:"p-scrolltop-helper"}))})));v.displayName="ScrollTop",v.defaultProps={__TYPE:"ScrollTop",target:"window",threshold:400,icon:"pi pi-chevron-up",behavior:"smooth",className:null,style:null,transitionOptions:null,onShow:null,onHide:null};export{v as ScrollTop};