UNPKG

nodality

Version:

A lightweight library for declarative UI elements.

2 lines 4.35 kB
/*! For license information please see range.esm.js.LICENSE.txt */ var e={d:(t,n)=>{for(var i in n)e.o(n,i)&&!e.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:n[i]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},t={};function n(e){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n(e)}function i(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,r(i.key),i)}}function r(e){var t=function(e){if("object"!=n(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var i=t.call(e,"string");if("object"!=n(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==n(t)?t:t+""}e.d(t,{Q:()=>a});var a=function(){return e=function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.el=null,this.minLabel=null,this.maxLabel=null,this.currentLabel=null},(t=[{key:"padding",value:function(e){return this.el.style.padding=e,this}},{key:"toCode",value:function(){var e=JSON.stringify(this.options,null,4);return["new Range().set(".concat(e,")")]}},{key:"set",value:function(e){var t,n,i=this;this.options=e;var r=document.createElement("input");if(r.setAttribute("id","slider"),r.setAttribute("type","range"),r.setAttribute("min",e.min),r.setAttribute("max",e.max),r.setAttribute("value",e.min),r.style.width=null!==(t=e.width)&&void 0!==t?t:"100%",!e.plain){var a,l;r.style.setProperty("-webkit-appearance","none"),r.style.appearance="none",r.style.height="9px",r.style.background=null!==(a=e.style.trackColor)&&void 0!==a?a:"orange",r.style.borderRadius="5px";var o="\n #slider::-webkit-slider-thumb {\n -webkit-appearance: none;\n appearance: none;\n width: 25px;\n height: 25px;\n border-radius: 50%;\n background: ".concat(null!==(l=e.style.thumbColor)&&void 0!==l?l:"4CAF50",";\n cursor: pointer;\n }\n "),u=document.createElement("style");u.appendChild(document.createTextNode(o)),document.head.appendChild(u)}var s=document.createElement("div");s.style.display="flex",s.style.flexDirection="column",s.style.alignItems="center",s.style.width="100%";var d=document.createElement("div");if(d.style.display="flex",d.style.justifyContent="space-between",d.style.width=null!==(n=e.width)&&void 0!==n?n:"100%",this.minLabel=document.createElement("span"),this.minLabel.textContent=e.min,this.maxLabel=document.createElement("span"),this.maxLabel.textContent=e.max,this.currentLabel=document.createElement("span"),this.currentLabel.textContent=r.value,e.font&&(this.currentLabel.style.fontFamily=e.font),e.font&&(this.minLabel.style.fontFamily=e.font),e.font&&(this.maxLabel.style.fontFamily=e.font),e.plain||(d.appendChild(this.minLabel),d.appendChild(this.currentLabel),d.appendChild(this.maxLabel)),r.addEventListener("input",(function(){i.currentLabel.textContent=r.value})),window.matchMedia("(max-device-width: 415px)").matches)if(e.plain)r.style.width="80%";else{var c,p;r.style.height="20px",r.style.background=null!==(c=e.style.trackColor)&&void 0!==c?c:"1abc9C",r.style.borderRadius="10px",r.style.fontSize="3rem",r.style.width="80%";var y="\n #slider::-webkit-slider-thumb {\n -webkit-appearance: none;\n appearance: none;\n width: 25px;\n height: 25px;\n border-radius: 50%;\n background: ".concat(null!==(p=e.style.thumbColor)&&void 0!==p?p:"blue",";\n cursor: pointer;\n }\n "),h=document.createElement("style");h.appendChild(document.createTextNode(y)),document.head.appendChild(h)}return s.appendChild(d),s.appendChild(r),this.el=s,this}},{key:"value",value:function(){return this.el.querySelector("#slider").value}},{key:"render",value:function(e){if(!e)return this.el;document.querySelector(e).appendChild(this.el)}}])&&i(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t}();window.Range=a;var l=t.Q;export{l as Range};