reactjs-query-builder
Version:
48 lines (40 loc) • 1.35 kB
JavaScript
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import ReactDOM from 'react-dom';
import { Switch, Icon } from 'antd';
import shallowCompare from 'react-addons-shallow-compare';
export default class BooleanWidget extends Component {
static propTypes = {
setValue: PropTypes.func.isRequired,
labelYes: PropTypes.string,
labelNo: PropTypes.string,
value: PropTypes.bool,
config: PropTypes.object.isRequired,
field: PropTypes.string.isRequired,
customProps: PropTypes.object,
}
shouldComponentUpdate = shallowCompare;
handleChange = (val) => {
this.props.setValue(val);
}
constructor(props) {
super(props);
}
static defaultProps = {
labelYes: null, //(<Icon type="check" />),
labelNo: null, //(<Icon type="cross" />),
}
render() {
let customProps = this.props.customProps || {};
return (
<Switch
ref="switch"
checkedChildren={this.props.labelYes || null}
unCheckedChildren={this.props.labelNo || null}
checked={this.props.value || null}
onChange={this.handleChange}
{...customProps}
/>
);
}
}