UNPKG

@tarojs/components

Version:
1 lines 1.99 kB
import{r as t,c as i,h as s,H as e,g as h}from"./p-f05e1558.js";let r=class{constructor(s){t(this,s),this.onChange=i(this,"radiochange",7),this.value="",this.checked=!1,this.disabled=!1,this.nativeProps={},this.isWillLoadCalled=!1,this.handleClick=()=>{this.disabled||this.checked||(this.checked=!0)}}watchChecked(t){this.isWillLoadCalled&&t&&this.onChange.emit({value:this.value})}watchId(t){this.isWillLoadCalled&&t&&this.inputEl.setAttribute("id",t)}componentDidRender(){this.id&&this.el.removeAttribute("id")}componentWillLoad(){this.isWillLoadCalled=!0}render(){const{checked:t,name:i,value:h,disabled:r,nativeProps:c}=this;return s(e,{className:"weui-cells_checkbox",onClick:this.handleClick},s("input",Object.assign({ref:t=>{t&&(this.inputEl=t,this.id&&t.setAttribute("id",this.id))},type:"radio",name:i,value:h,class:"weui-check",checked:t,disabled:r,onChange:t=>t.stopPropagation()},c)),s("i",{class:"weui-icon-checked"}),s("slot",null))}get el(){return h(this)}static get watchers(){return{checked:["watchChecked"],id:["watchId"]}}},c=class{constructor(s){t(this,s),this.onChange=i(this,"change",7),this.uniqueName=Date.now().toString(36)}function(t){if(t.stopPropagation(),"TARO-RADIO-CORE"!==t.target.tagName)return;const i=t.target;i.checked&&(this.el.querySelectorAll("taro-radio-core").forEach((t=>{t!==i&&(t.checked=!1)})),this.value=t.detail.value,this.onChange.emit({value:this.value}))}componentDidLoad(){this.el.querySelectorAll("taro-radio-core").forEach((t=>{t.setAttribute("name",this.name||this.uniqueName)})),Object.defineProperty(this.el,"value",{get:()=>{if(!this.value){const t=this.el.querySelectorAll("taro-radio-core");this.value=this.getValues(t)}return this.value},configurable:!0})}getValues(t){let i="";return Array.from(t).forEach((t=>{const s=t.querySelector("input");(null==s?void 0:s.checked)&&(i=s.value||"")})),i}render(){return s(e,{class:"weui-cells_radiogroup"})}get el(){return h(this)}};export{r as taro_radio_core,c as taro_radio_group_core}