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) • 6.2 kB
JavaScript
;Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),n=require("primereact/hooks"),r=require("primereact/utils");function t(e){if(e&&e.__esModule)return e;var n=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var t=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(n,r,t.get?t:{enumerable:!0,get:function(){return e[r]}})}})),n.default=e,Object.freeze(n)}var a=t(e);function i(){return i=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])}return e},i.apply(this,arguments)}function l(e,n){(null==n||n>e.length)&&(n=e.length);for(var r=0,t=new Array(n);r<n;r++)t[r]=e[r];return t}function o(e){if(Array.isArray(e))return l(e)}function u(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function c(e,n){if(e){if("string"==typeof e)return l(e,n);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)?l(e,n):void 0}}function s(){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 f(e){if(Array.isArray(e))return e}function d(e,n){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var t,a,i,l,o=[],u=!0,c=!1;try{if(i=(r=r.call(e)).next,0===n){if(Object(r)!==r)return;u=!1}else for(;!(u=(t=i.call(r)).done)&&(o.push(t.value),o.length!==n);u=!0);}catch(e){c=!0,a=e}finally{try{if(!u&&null!=r.return&&(l=r.return(),Object(l)!==l))return}finally{if(c)throw a}}return o}}function m(){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 p(e,n){return f(e)||d(e,n)||c(e,n)||m()}var v={defaultProps:{__TYPE:"Slider",id:null,value:null,min:0,max:100,orientation:"horizontal",step:null,range:!1,style:null,className:null,disabled:!1,tabIndex:0,onChange:null,onSlideEnd:null,children:void 0},getProps:function(e){return r.ObjectUtils.getMergedProps(e,v.defaultProps)},getOtherProps:function(e){return r.ObjectUtils.getDiffProps(e,v.defaultProps)}},g=a.memo(a.forwardRef((function(e,t){var l=v.getProps(e),f=a.useRef(null),d=a.useRef(0),m=a.useRef(!1),g=a.useRef(!1),h=a.useRef(0),y=a.useRef(0),b=a.useRef(0),E=a.useRef(0),x=l.range?l.value||[l.min,l.max]:l.value||0,w="horizontal"===l.orientation,O="vertical"===l.orientation,S=p(n.useEventListener({type:"mousemove",listener:function(e){return U(e)}}),2),j=S[0],P=S[1],A=p(n.useEventListener({type:"mouseup",listener:function(e){return k(e)}}),2),R=A[0],D=A[1],I=p(n.useEventListener({type:"touchmove",listener:function(e){return U(e)}}),2),N=I[0],C=I[1],M=p(n.useEventListener({type:"touchend",listener:function(e){return k(e)}}),2),_=M[0],L=M[1],H=function(e,n){K(e,(l.range?x[d.current]:x)+(l.step||1)*n),e.preventDefault()},T=function(e,n){l.disabled||(g.current=!0,W(),m.current=!0,d.current=n)},U=function(e){g.current&&(Y(e),e.preventDefault())},k=function(e){g.current&&(g.current=!1,l.onSlideEnd&&l.onSlideEnd({originalEvent:e,value:l.value}),P(),D(),C(),L())},z=function(e,n){j(),R(),T(0,n)},F=function(e,n){N(),_(),T(0,n)},q=function(e,n){if(!l.disabled){d.current=n;var r=e.key;"ArrowRight"===r||"ArrowUp"===r?H(e,1):"ArrowLeft"!==r&&"ArrowDown"!==r||H(e,-1)}},W=function(){var e=f.current.getBoundingClientRect();h.current=e.left+r.DomHandler.getWindowScrollLeft(),y.current=e.top+r.DomHandler.getWindowScrollTop(),b.current=f.current.offsetWidth,E.current=f.current.offsetHeight},Y=function(e){var n=(w?100*((e.touches?e.touches[0].pageX:e.pageX)-h.current)/b.current:100*(y.current+E.current-(e.touches?e.touches[0].pageY:e.pageY))/E.current)/100*(l.max-l.min)+l.min;if(l.step){var r=l.range?x[d.current]:x,t=n-r;t<0?n=r+Math.ceil(n/l.step-r/l.step)*l.step:t>0&&(n=r+Math.floor(n/l.step-r/l.step)*l.step)}else n=Math.floor(n);return K(e,n)},K=function(e,n){var r,t=parseFloat(n.toFixed(10)),a=t;return l.range?(0===d.current?t<l.min?t=l.min:t>x[1]&&(t=x[1]):t>l.max?t=l.max:t<x[0]&&(t=x[0]),(a=o(r=x)||u(r)||c(r)||s())[d.current]=t,l.onChange&&l.onChange({originalEvent:e,value:a})):(t<l.min?t=l.min:t>l.max&&(t=l.max),a=t,l.onChange&&l.onChange({originalEvent:e,value:a})),a},X=function(e,n,t){var o={transition:g.current?"none":null,left:null!==e&&e+"%",bottom:n&&n+"%"},u=r.classNames("p-slider-handle",{"p-slider-handle-start":0===t,"p-slider-handle-end":1===t,"p-slider-handle-active":d.current===t});return a.createElement("span",i({className:u,style:o,tabIndex:l.tabIndex,role:"slider",onMouseDown:function(e){return z(0,t)},onTouchStart:function(e){return F(0,t)},onKeyDown:function(e){return q(e,t)},"aria-valuemin":l.min,"aria-valuemax":l.max,"aria-valuenow":e||n,"aria-orientation":l.orientation},V))};a.useImperativeHandle(t,(function(){return{props:l,getElement:function(){return f.current}}}));var B,$,G,J,Q=v.getOtherProps(l),V=r.ObjectUtils.reduceKeys(Q,r.DomHandler.ARIA_PROPS),Z=r.classNames("p-slider p-component",l.className,{"p-disabled":l.disabled,"p-slider-horizontal":w,"p-slider-vertical":O}),ee=l.range?(B=100*(x[0]<l.min?l.min:x[0]-l.min)/(l.max-l.min),$=100*(x[1]>l.max?l.max:x[1]-l.min)/(l.max-l.min),G=w?X(B,null,0):X(null,B,0),J=w?X($,null,1):X(null,$,1),a.createElement(a.Fragment,null,a.createElement("span",{className:"p-slider-range",style:w?{left:B+"%",width:$-B+"%"}:{bottom:B+"%",height:$-B+"%"}}),G,J)):function(){var e;e=x<l.min?l.min:x>l.max?l.max:100*(x-l.min)/(l.max-l.min);var n=w?{width:e+"%"}:{height:e+"%"},r=w?X(e,null,null):X(null,e,null);return a.createElement(a.Fragment,null,a.createElement("span",{className:"p-slider-range",style:n}),r)}();return a.createElement("div",i({ref:f,id:l.id,style:l.style,className:Z},Q,{onClick:function(e){if(!l.disabled){if(!m.current){W();var n=Y(e);l.onSlideEnd&&l.onSlideEnd({originalEvent:e,value:n})}m.current=!1}}}),ee)})));g.displayName="Slider",exports.Slider=g;