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