2017-11-17 14:38:54 +08:00
|
|
|
import * as React from 'react';
|
2017-05-09 13:40:33 +08:00
|
|
|
import PropTypes from 'prop-types';
|
2017-05-08 13:12:34 +08:00
|
|
|
import { AbstractCheckboxProps } from '../checkbox/Checkbox';
|
2016-03-21 21:16:38 +08:00
|
|
|
import Radio from './radio';
|
2015-11-06 22:03:09 +08:00
|
|
|
|
2017-05-16 11:55:17 +08:00
|
|
|
export type RadioButtonProps = AbstractCheckboxProps;
|
2016-08-10 10:26:42 +08:00
|
|
|
|
|
|
|
export default class RadioButton extends React.Component<RadioButtonProps, any> {
|
2016-03-28 23:21:47 +08:00
|
|
|
static defaultProps = {
|
|
|
|
prefixCls: 'ant-radio-button',
|
2016-07-13 11:14:24 +08:00
|
|
|
};
|
2017-03-23 17:19:50 +08:00
|
|
|
|
|
|
|
static contextTypes = {
|
|
|
|
radioGroup: PropTypes.any,
|
|
|
|
};
|
|
|
|
|
2015-11-06 22:03:09 +08:00
|
|
|
render() {
|
2017-07-31 01:50:46 +08:00
|
|
|
const radioProps: RadioButtonProps = { ...this.props };
|
2017-03-23 17:19:50 +08:00
|
|
|
if (this.context.radioGroup) {
|
|
|
|
radioProps.onChange = this.context.radioGroup.onChange;
|
|
|
|
radioProps.checked = this.props.value === this.context.radioGroup.value;
|
|
|
|
radioProps.disabled = this.props.disabled || this.context.radioGroup.disabled;
|
|
|
|
}
|
|
|
|
|
2015-11-06 22:03:09 +08:00
|
|
|
return (
|
2017-03-23 17:19:50 +08:00
|
|
|
<Radio {...radioProps} />
|
2015-11-06 22:03:09 +08:00
|
|
|
);
|
|
|
|
}
|
2016-03-28 23:21:47 +08:00
|
|
|
}
|