UNPKG

yylib-quick-mobile

Version:

yylib-quick-mobile

51 lines (48 loc) 1.65 kB
import React from 'react'; import {List, Checkbox} from 'antd-mobile'; const CheckboxItem = Checkbox.CheckboxItem; const AgreeItem = Checkbox.AgreeItem; import classnames from 'classnames'; import {isFunction} from '../../utils/FunctionUtil'; class YYCheckbox extends React.Component { _onChange = (event) => { if (event && event.target) { // 赋值value,以在表单里统一通过value取值处理 event.target.value = event.target.checked; } if (isFunction(this.props.onChange)) { this.props.onChange(event); } } render() { const {custom, label, children,visible, ...restProps} = this.props; let wrapClz = classnames('yy-checkbox',(!visible&&'hidden'), this.props.className); return ( <div> {custom ? <AgreeItem {...restProps} className={wrapClz} onChange={this._onChange} > {label ? label : children} </AgreeItem> : <CheckboxItem {...restProps} className={wrapClz} onChange={this._onChange} > {label ? label : children} </CheckboxItem> } </div> ) } } YYCheckbox.defaultProps = { custom: false, label: '',//有则优先于children使用, visible:true, }; export default YYCheckbox;