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