2015-12-24 15:03:06 +08:00
|
|
|
import RcCheckbox from 'rc-checkbox';
|
2016-09-21 11:54:53 +08:00
|
|
|
import React from 'react';
|
2016-03-28 23:21:47 +08:00
|
|
|
import CheckboxGroup from './Group';
|
2016-02-17 18:02:33 +08:00
|
|
|
import classNames from 'classnames';
|
2016-10-28 13:56:23 +08:00
|
|
|
import PureRenderMixin from 'rc-util/lib/PureRenderMixin';
|
2016-06-30 10:05:29 +08:00
|
|
|
|
2016-07-07 20:25:03 +08:00
|
|
|
export interface CheckboxProps {
|
2016-12-19 15:19:15 +08:00
|
|
|
prefixCls?: string;
|
2016-07-13 11:14:24 +08:00
|
|
|
/** 指定当前是否选中 */
|
|
|
|
checked?: boolean;
|
|
|
|
/** 初始是否选中 */
|
|
|
|
defaultChecked?: boolean;
|
2016-09-08 15:54:04 +08:00
|
|
|
/** indeterminate 状态,只负责样式控制 */
|
|
|
|
indeterminate?: boolean;
|
2016-07-13 11:14:24 +08:00
|
|
|
/** 变化时回调函数 */
|
2016-10-19 17:51:33 +08:00
|
|
|
onChange?: React.FormEventHandler<any>;
|
2016-12-19 15:19:15 +08:00
|
|
|
onMouseEnter?: React.MouseEventHandler<any>;
|
|
|
|
onMouseLeave?: React.MouseEventHandler<any>;
|
2016-07-13 11:14:24 +08:00
|
|
|
style?: React.CSSProperties;
|
|
|
|
disabled?: boolean;
|
|
|
|
className?: string;
|
2016-06-30 10:05:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export default class Checkbox extends React.Component<CheckboxProps, any> {
|
2016-03-28 23:21:47 +08:00
|
|
|
static Group = CheckboxGroup;
|
|
|
|
static defaultProps = {
|
2016-05-11 09:32:33 +08:00
|
|
|
prefixCls: 'ant-checkbox',
|
2016-09-08 15:54:04 +08:00
|
|
|
indeterminate: false,
|
2016-07-13 11:14:24 +08:00
|
|
|
};
|
2016-06-07 17:54:06 +08:00
|
|
|
shouldComponentUpdate(...args) {
|
|
|
|
return PureRenderMixin.shouldComponentUpdate.apply(this, args);
|
|
|
|
}
|
2015-08-18 14:03:44 +08:00
|
|
|
render() {
|
2016-12-19 15:19:15 +08:00
|
|
|
const {
|
|
|
|
prefixCls, style, children, className, indeterminate,
|
|
|
|
onMouseEnter, onMouseLeave, ...restProps,
|
|
|
|
} = this.props;
|
2016-11-30 10:20:23 +08:00
|
|
|
const classString = classNames(className, {
|
2016-02-17 18:02:33 +08:00
|
|
|
[`${prefixCls}-wrapper`]: true,
|
|
|
|
});
|
2016-09-08 15:54:04 +08:00
|
|
|
const checkboxClass = classNames({
|
|
|
|
[`${prefixCls}-indeterminate`]: indeterminate,
|
|
|
|
});
|
2016-02-17 18:02:33 +08:00
|
|
|
return (
|
2016-11-14 11:52:18 +08:00
|
|
|
<label
|
|
|
|
className={classString}
|
|
|
|
style={style}
|
|
|
|
onMouseEnter={onMouseEnter}
|
|
|
|
onMouseLeave={onMouseLeave}
|
|
|
|
>
|
2016-09-08 15:54:04 +08:00
|
|
|
<RcCheckbox
|
|
|
|
{...restProps}
|
|
|
|
prefixCls={prefixCls}
|
|
|
|
className={checkboxClass}
|
|
|
|
children={null}
|
|
|
|
/>
|
2016-05-23 17:37:31 +08:00
|
|
|
{children !== undefined ? <span>{children}</span> : null}
|
2016-02-17 18:02:33 +08:00
|
|
|
</label>
|
|
|
|
);
|
2015-07-15 16:01:24 +08:00
|
|
|
}
|
2016-03-18 10:31:25 +08:00
|
|
|
}
|