weex-nuke
Version:
基于 Rax 、Weex 的高性能组件体系 ~~
45 lines (38 loc) • 892 B
JSX
/* @jsx createElement */
;
import { Component, createElement } from 'rax';
import SwitchComponent from './view/switch';
const noop = () => {};
class Switch extends Component {
constructor(props) {
super(props);
let checked = false;
if ('checked' in props) {
checked = props.checked;
} else {
checked = props.defaultChecked;
}
this.state = {
checked,
};
this.onValueChange = this.onValueChange.bind(this);
}
onValueChange(newValue) {
this.setState({ checked: newValue });
this.props.onValueChange && this.props.onValueChange(newValue);
}
render() {
const { checked } = this.state;
return (
<SwitchComponent
{...this.props}
onValueChange={this.onValueChange}
value={checked}
/>
);
}
}
Switch.defaultProps = {
onValueChange: noop,
};
export default Switch;