@tarojs/components
Version:
64 lines (58 loc) • 1.82 kB
JavaScript
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
const index = require('./index-e751dfe3.js');
const indexCss = "taro-switch-core{display:inline-block;width:52px;height:32px}taro-switch-core .weui-switch{display:block;width:100%;height:100%}";
const Switch = class {
constructor(hostRef) {
index.registerInstance(this, hostRef);
this.onChange = index.createEvent(this, "change", 7);
this.switchChange = e => {
e.stopPropagation();
const value = e.target.checked;
this.isChecked = value;
this.onChange.emit({
value
});
};
this.type = 'switch';
this.checked = false;
this.color = '#04BE02';
this.name = undefined;
this.disabled = false;
this.nativeProps = {};
this.isChecked = undefined;
this.isWillLoadCalled = false;
}
function(newVal, oldVal) {
if (!this.isWillLoadCalled)
return;
if (newVal !== oldVal)
this.isChecked = newVal;
}
componentWillLoad() {
this.isWillLoadCalled = true;
this.isChecked = this.checked;
}
componentDidLoad() {
Object.defineProperty(this.el, 'value', {
get: () => this.isChecked,
configurable: true
});
}
render() {
const { type, color, isChecked, name, disabled, nativeProps } = this;
const style = isChecked
? {
borderColor: color || '04BE02',
backgroundColor: color || '04BE02'
}
: {};
return (index.h("input", Object.assign({ type: 'checkbox', class: `weui-${type}`, style: style, checked: isChecked, name: name, disabled: disabled, onChange: this.switchChange }, nativeProps)));
}
get el() { return index.getElement(this); }
static get watchers() { return {
"checked": ["function"]
}; }
};
Switch.style = indexCss;
exports.taro_switch_core = Switch;