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) • 4.45 kB
JavaScript
;Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),r=require("primereact/hooks"),n=require("primereact/utils");function t(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var t=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(r,n,t.get?t:{enumerable:!0,get:function(){return e[n]}})}})),r.default=e,Object.freeze(r)}var l=t(e);function c(){return c=Object.assign?Object.assign.bind():function(e){for(var r=1;r<arguments.length;r++){var n=arguments[r];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(e[t]=n[t])}return e},c.apply(this,arguments)}var u=l.forwardRef((function(e,t){var a=l.useRef(null),o=l.useRef(null),s=l.useRef(null),i=l.useRef(null),d=l.useRef(!1),p=l.useRef(!1),m=l.useRef(null),f=l.useRef(null),g=l.useRef(null),h=l.useRef(null),v=l.useRef(null),b=l.useRef(!1),y=function(){var e=o.current.scrollWidth,r=-1*(a.current.clientHeight-s.current.clientHeight);g.current=o.current.clientWidth/e;var t=o.current.scrollHeight,l=-1*(a.current.clientWidth-i.current.clientWidth);h.current=o.current.clientHeight/t,v.current=window.requestAnimationFrame((function(){g.current>=1?n.DomHandler.addClass(s.current,"p-scrollpanel-hidden"):(n.DomHandler.removeClass(s.current,"p-scrollpanel-hidden"),s.current.style.cssText="width:"+Math.max(100*g.current,10)+"%; left:"+o.current.scrollLeft/e*100+"%;bottom:"+r+"px;"),h.current>=1?n.DomHandler.addClass(i.current,"p-scrollpanel-hidden"):(n.DomHandler.removeClass(i.current,"p-scrollpanel-hidden"),i.current.style.cssText="height:"+Math.max(100*h.current,10)+"%; top: calc("+o.current.scrollTop/t*100+"% - "+s.current.clientHeight+"px);right:"+l+"px;")}))},H=function(e){d.current?w(e):(p.current||w(e),E(e))},w=function(e){var r=e.pageX-m.current;m.current=e.pageX,v.current=window.requestAnimationFrame((function(){o.current.scrollLeft+=r/g.current}))},E=function(e){var r=e.pageY-f.current;f.current=e.pageY,v.current=window.requestAnimationFrame((function(){o.current.scrollTop+=r/h.current}))},D=function e(r){n.DomHandler.removeClass(i.current,"p-scrollpanel-grabbed"),n.DomHandler.removeClass(s.current,"p-scrollpanel-grabbed"),n.DomHandler.removeClass(document.body,"p-scrollpanel-grabbed"),document.removeEventListener("mousemove",H),document.removeEventListener("mouseup",e),d.current=!1,p.current=!1},x=function(){y()};r.useMountEffect((function(){var e,r,t;y(),window.addEventListener("resize",y),e=getComputedStyle(a.current),r=getComputedStyle(s.current),t=n.DomHandler.getHeight(a.current)-parseInt(r.height,10),"none"!==e["max-height"]&&0===t&&(a.current.style.height=o.current.offsetHeight+parseInt(r.height,10)>parseInt(e["max-height"],10)?e["max-height"]:o.current.offsetHeight+parseFloat(e.paddingTop)+parseFloat(e.paddingBottom)+parseFloat(e.borderTopWidth)+parseFloat(e.borderBottomWidth)+"px"),b.current=!0})),r.useUnmountEffect((function(){b.current&&window.removeEventListener("resize",y),v.current&&window.cancelAnimationFrame(v.current)})),l.useImperativeHandle(t,(function(){return{props:e,refresh:x,getElement:function(){return a.current},getContent:function(){return o.current},getXBar:function(){return s.current},getYBar:function(){return i.current}}}));var C=n.ObjectUtils.findDiffKeys(e,u.defaultProps),R=n.classNames("p-scrollpanel p-component",e.className);return l.createElement("div",c({ref:a,id:e.id,className:R,style:e.style},C),l.createElement("div",{className:"p-scrollpanel-wrapper"},l.createElement("div",{ref:o,className:"p-scrollpanel-content",onScroll:y,onMouseEnter:y},e.children)),l.createElement("div",{ref:s,className:"p-scrollpanel-bar p-scrollpanel-bar-x",onMouseDown:function(e){d.current=!0,m.current=e.pageX,n.DomHandler.addClass(s.current,"p-scrollpanel-grabbed"),n.DomHandler.addClass(document.body,"p-scrollpanel-grabbed"),document.addEventListener("mousemove",H),document.addEventListener("mouseup",D),e.preventDefault()}}),l.createElement("div",{ref:i,className:"p-scrollpanel-bar p-scrollpanel-bar-y",onMouseDown:function(e){p.current=!0,f.current=e.pageY,n.DomHandler.addClass(i.current,"p-scrollpanel-grabbed"),n.DomHandler.addClass(document.body,"p-scrollpanel-grabbed"),document.addEventListener("mousemove",H),document.addEventListener("mouseup",D),e.preventDefault()}}))}));u.displayName="ScrollPanel",u.defaultProps={__TYPE:"ScrollPanel",id:null,style:null,className:null},exports.ScrollPanel=u;