UNPKG

nodality

Version:

A lightweight library for declarative UI elements.

2 lines 3.68 kB
/*! For license information please see radio.esm.js.LICENSE.txt */ var t={d:(e,o)=>{for(var n in o)t.o(o,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:o[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},e={};function o(t){return o="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},o(t)}function n(t,e){for(var o=0;o<e.length;o++){var n=e[o];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,r(n.key),n)}}function r(t){var e=function(t){if("object"!=o(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=o(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==o(e)?e:e+""}t.d(e,{z:()=>i});var i=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.el=null,this.radioCount=0},(e=[{key:"set",value:function(t){this.options=t,console.log("ORARA"),console.log(this.options),this.radioCount=t.items.length;for(var e=document.createElement("div"),o=t.items,n=0;n<o.length;n++){var r=document.createElement("label");o.font&&(r.style.font=o.font),o.color&&(r.style.color=o.color),o.exact&&(r.style.fontSize=o.exact);var i=document.createTextNode(o[n]);r.appendChild(i),r.setAttribute("for",o[n]);var l=document.createElement("input");l.setAttribute("type","radio"),l.setAttribute("id","S".concat(n)),l.setAttribute("value",o[n].split(" ").join("")),l.style.appearance="none",l.style.width="20px",l.style.height="20px",l.style.border=this.options.tint?"2px solid ".concat(this.options.tint):"2px solid #007BFF",l.style.borderRadius="50%",l.style.outline="none",l.style.cursor="pointer",l.style.transition="0.3s",this.options.font&&(r.style.fontFamily=this.options.font),t.multiple?l.setAttribute("name",o[n].split(" ").join("")):l.setAttribute("name",t.name),e.appendChild(l),e.appendChild(r),e.innerHTML+="</br>"}return this.el=e,this.responsive(),this}},{key:"padding",value:function(t){return this.el.style.padding=t,this}},{key:"getCheckedValues",value:function(){console.log("NOW");for(var t=[],e=0;e<this.radioCount;e++)if(document.querySelector("#S".concat(e)).checked){var o=document.querySelector("#S".concat(e));console.log("VALUE IS "+o.value),t.push(o.value)}return t}},{key:"toCode",value:function(){var t=JSON.stringify(this.options,null,4);return t=t.replace(/"(\w+)"(?=\s*:)/g,"$1"),["new RadioGroup().set(".concat(t,")")]}},{key:"responsive",value:function(){return window.matchMedia("(max-device-width: 415px)").matches&&(this.el.style.fontSize="1.7em"),this}},{key:"render",value:function(t){var e=this;if(!t){console.log("MULA");for(var o=function(){var t=e.el.children[n];"[object HTMLInputElement]"===t.toString()&&t.addEventListener("change",(function(){if(t.checked){t.style.backgroundColor=e.options.tint?e.options.tint:"#007BFF",t.style.boxShadow=e.options.tint?"0 0 0 2px ".concat(e.options.tint," inset"):"0 0 0 2px #0056b3 inset";for(var o=0;o<e.el.children.length;o++){var n=e.el.children[o];"INPUT"===n.tagName&&"radio"===n.type&&!1===e.options.multiple&&n!==t&&(n.style.backgroundColor="transparent",n.style.boxShadow="none")}}else t.style.backgroundColor="transparent",t.style.boxShadow="none"}))},n=0;n<this.el.children.length;n++)o();return this.el}document.querySelector(t).appendChild(this.el)}}])&&n(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}();window.RadioGroup=i;var l=e.z;export{l as RadioGroup};