nodality
Version:
A lightweight library for declarative UI elements.
2 lines • 3.69 kB
JavaScript
/*! For license information please see datalist.esm.js.LICENSE.txt */
var t={d:(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},e={};function r(t,e){return r=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},r(t,e)}function n(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(n=function(){return!!t})()}function i(t){return i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},i(t)}function a(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,o(n.key),n)}}function o(t){var e=function(t){if("object"!=i(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=i(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==i(e)?e:e+""}t.d(e,{T:()=>s});var s=function(){return t=function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.res=null,this.currentItem=""},(e=[{key:"set",value:function(t){var e=this,r=t;this.options=t;var n=document.createElement("input");n.setAttribute("list","dlCities"),n.setAttribute("id","my");var i=t.data,a=0,o=i.length,s=document.createElement("datalist");for(s.id="dlCities",a=0;a<o;a+=1){var l=document.createElement("option");l.value=i[a],s.appendChild(l)}return n.appendChild(s),n.addEventListener("change",(function(){var t=document.querySelector("#my").value;console.log(t),e.currentItem=t})),n.setAttribute("placeholder","Type value"),n.style.padding=".4rem .75rem",n.style.fontSize="1rem",this.res=n,this.responsive(),r.arrayPadding&&this.arrayPadding(r.arrayPadding.sides,r.arrayPadding.value),r.arrayMargin&&this.arrayMargin(r.arrayMargin.sides,r.arrayMargin.value),r.pad&&this.pad(r.pad),r.mar&&this.mar(r.mar),this}},{key:"toCode",value:function(){var t=JSON.stringify(this.options,null,4);return["new DataList().set(".concat(t,")")]}},{key:"getValue",value:function(){return this.res.value}},{key:"arrayPadding",value:function(t,e){return console.log(t),t.includes("left")&&(this.res.style.paddingLeft=e),t.includes("right")&&(this.res.style.paddingRight=e),t.includes("top")&&(this.res.style.paddingTop=e),t.includes("bottom")&&(this.res.style.paddingBottom=e),t.includes("all")&&(this.res.style.padding=e),this}},{key:"arrayMargin",value:function(t,e){return console.log(t),t.includes("left")&&(this.res.style.marginLeft=e),t.includes("right")&&(this.res.style.marginRight=e),t.includes("top")&&(this.res.style.marginTop=e),t.includes("bottom")&&(this.res.style.marginBottom=e),t.includes("all")&&(this.res.style.margin=e),this}},{key:"margin",value:function(t){return this.res.style.margin=t,this}},{key:"responsive",value:function(){return window.matchMedia("(max-device-width: 415px)").matches&&(this.res.style.width="100%"),this}},{key:"render",value:function(t){if(!t)return this.res;document.querySelector(t).appendChild(this.res)}}])&&a(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}(),l=s;s=function(){for(var t=arguments.length,e=new Array(t),i=0;i<t;i++)e[i]=arguments[i];return function(t,e,i){if(n())return Reflect.construct.apply(null,arguments);var a=[null];a.push.apply(a,e);var o=new(t.bind.apply(t,a));return i&&r(o,i.prototype),o}(l,e)},window.DataList=s;var u=e.T;export{u as DataList};