ant-design/components/radio/radio.tsx

57 lines
1.6 KiB
TypeScript
Raw Normal View History

import RcRadio from 'rc-radio';
2016-09-21 11:54:53 +08:00
import React from 'react';
2016-01-21 22:45:21 +08:00
import classNames from 'classnames';
import PureRenderMixin from 'rc-util/lib/PureRenderMixin';
2015-08-21 18:24:09 +08:00
2016-08-10 10:26:42 +08:00
export interface RadioProps {
/** 指定当前是否选中*/
checked?: boolean;
/** 初始是否选中*/
defaultChecked?: boolean;
/** 根据 value 进行比较,判断是否选中 */
value?: any;
2016-08-10 10:26:42 +08:00
style?: React.CSSProperties;
prefixCls?: string;
disabled?: boolean;
className?: string;
onChange?: (e: any) => any;
onMouseEnter?: React.FormEventHandler<any>;
onMouseLeave?: React.FormEventHandler<any>;
2016-08-10 10:26:42 +08:00
}
export default class Radio extends React.Component<RadioProps, any> {
static Group: any;
static Button: any;
static defaultProps = {
2016-05-11 09:32:33 +08:00
prefixCls: 'ant-radio',
2016-07-13 11:14:24 +08:00
};
2016-06-12 16:15:11 +08:00
shouldComponentUpdate(...args) {
return PureRenderMixin.shouldComponentUpdate.apply(this, args);
}
2015-08-21 18:24:09 +08:00
render() {
2016-10-24 16:30:38 +08:00
const { prefixCls, children, checked, disabled, className = '', style } = this.props;
2016-06-27 17:22:03 +08:00
const wrapperClassString = classNames({
[`${prefixCls}-wrapper`]: true,
[`${prefixCls}-wrapper-checked`]: checked,
[`${prefixCls}-wrapper-disabled`]: disabled,
}, className);
const classString = classNames(prefixCls, {
[`${prefixCls}-checked`]: checked,
[`${prefixCls}-disabled`]: disabled,
2016-01-21 22:45:21 +08:00
});
2015-08-21 18:24:09 +08:00
return (
<label
className={wrapperClassString}
style={style}
onMouseEnter={this.props.onMouseEnter}
onMouseLeave={this.props.onMouseLeave}
>
2016-06-27 17:22:03 +08:00
<RcRadio {...this.props} className={classString} style={null} children={null} />
2016-04-14 14:23:12 +08:00
{children ? <span>{children}</span> : null}
2015-08-21 18:24:09 +08:00
</label>
);
}
}