@tarojs/components
Version:
Taro 组件库。
1 lines • 1.54 kB
JavaScript
import{r as registerInstance,c as createEvent,h,g as getElement}from"./index-5bd7cbab.js";var indexCss="taro-switch-core{display:inline-block;width:52px;height:32px}taro-switch-core .weui-switch{display:block;width:100%;height:100%}";var Switch=function(){function e(e){var t=this;registerInstance(this,e);this.onChange=createEvent(this,"change",7);this.type="switch";this.checked=false;this.color="#04BE02";this.disabled=false;this.nativeProps={};this.isWillLoadCalled=false;this.switchChange=function(e){e.stopPropagation();var i=e.target.checked;t.isChecked=i;t.onChange.emit({value:i})}}e.prototype.function=function(e,t){if(!this.isWillLoadCalled)return;if(e!==t)this.isChecked=e};e.prototype.componentWillLoad=function(){this.isWillLoadCalled=true;this.isChecked=this.checked};e.prototype.componentDidLoad=function(){var e=this;Object.defineProperty(this.el,"value",{get:function(){return e.isChecked},configurable:true})};e.prototype.render=function(){var e=this,t=e.type,i=e.color,n=e.isChecked,r=e.name,s=e.disabled,o=e.nativeProps;var c=n?{borderColor:i||"04BE02",backgroundColor:i||"04BE02"}:{};return h("input",Object.assign({type:"checkbox",class:"weui-"+t,style:c,checked:n,name:r,disabled:s,onChange:this.switchChange},o))};Object.defineProperty(e.prototype,"el",{get:function(){return getElement(this)},enumerable:false,configurable:true});Object.defineProperty(e,"watchers",{get:function(){return{checked:["function"]}},enumerable:false,configurable:true});return e}();Switch.style=indexCss;export{Switch as taro_switch_core};