mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-05 05:28:20 +08:00
f78e0098fa
Close #9574
31 lines
892 B
TypeScript
31 lines
892 B
TypeScript
import * as React from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import { AbstractCheckboxProps } from '../checkbox/Checkbox';
|
|
import Radio from './radio';
|
|
import { RadioChangeEvent } from './interface';
|
|
|
|
export type RadioButtonProps = AbstractCheckboxProps<RadioChangeEvent>;
|
|
|
|
export default class RadioButton extends React.Component<RadioButtonProps, any> {
|
|
static defaultProps = {
|
|
prefixCls: 'ant-radio-button',
|
|
};
|
|
|
|
static contextTypes = {
|
|
radioGroup: PropTypes.any,
|
|
};
|
|
|
|
render() {
|
|
const radioProps: RadioButtonProps = { ...this.props };
|
|
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;
|
|
}
|
|
|
|
return (
|
|
<Radio {...radioProps} />
|
|
);
|
|
}
|
|
}
|