UNPKG

@tarojs/components

Version:
1 lines 2.74 kB
import{r as registerInstance,c as createEvent,h,H as Host,g as getElement}from"./index-5bd7cbab.js";var Radio=function(){function e(e){var t=this;registerInstance(this,e);this.onChange=createEvent(this,"radiochange",7);this.value="";this.checked=false;this.disabled=false;this.nativeProps={};this.isWillLoadCalled=false;this.handleClick=function(){if(t.disabled)return;if(!t.checked)t.checked=true}}e.prototype.watchChecked=function(e){if(!this.isWillLoadCalled)return;e&&this.onChange.emit({value:this.value})};e.prototype.watchId=function(e){if(!this.isWillLoadCalled)return;if(e)this.inputEl.setAttribute("id",e)};e.prototype.componentDidRender=function(){this.id&&this.el.removeAttribute("id")};e.prototype.componentWillLoad=function(){this.isWillLoadCalled=true};e.prototype.render=function(){var e=this;var t=this,i=t.checked,r=t.name,n=t.value,a=t.disabled,o=t.nativeProps;return h(Host,{className:"weui-cells_checkbox",onClick:this.handleClick},h("input",Object.assign({ref:function(t){if(!t)return;e.inputEl=t;if(e.id)t.setAttribute("id",e.id)},type:"radio",name:r,value:n,class:"weui-check",checked:i,disabled:a,onChange:function(e){return e.stopPropagation()}},o)),h("i",{class:"weui-icon-checked"}),h("slot",null))};Object.defineProperty(e.prototype,"el",{get:function(){return getElement(this)},enumerable:false,configurable:true});Object.defineProperty(e,"watchers",{get:function(){return{checked:["watchChecked"],id:["watchId"]}},enumerable:false,configurable:true});return e}();var RadioGroup=function(){function e(e){registerInstance(this,e);this.onChange=createEvent(this,"change",7);this.uniqueName=Date.now().toString(36)}e.prototype.function=function(e){e.stopPropagation();if(e.target.tagName!=="TARO-RADIO-CORE")return;var t=e.target;if(t.checked){var i=this.el.querySelectorAll("taro-radio-core");i.forEach((function(e){if(e!==t){e.checked=false}}));this.value=e.detail.value;this.onChange.emit({value:this.value})}};e.prototype.componentDidLoad=function(){var e=this;var t=this.el.querySelectorAll("taro-radio-core");t.forEach((function(t){t.setAttribute("name",e.name||e.uniqueName)}));Object.defineProperty(this.el,"value",{get:function(){if(!e.value){var t=e.el.querySelectorAll("taro-radio-core");e.value=e.getValues(t)}return e.value},configurable:true})};e.prototype.getValues=function(e){var t="";Array.from(e).forEach((function(e){var i=e.querySelector("input");if(i===null||i===void 0?void 0:i.checked){t=i.value||""}}));return t};e.prototype.render=function(){return h(Host,{class:"weui-cells_radiogroup"})};Object.defineProperty(e.prototype,"el",{get:function(){return getElement(this)},enumerable:false,configurable:true});return e}();export{Radio as taro_radio_core,RadioGroup as taro_radio_group_core};