ant-design/components/radio/radioButton.tsx

29 lines
883 B
TypeScript
Raw Normal View History

import * as React from 'react';
2018-08-07 21:07:52 +08:00
import * as PropTypes from 'prop-types';
2017-05-08 13:12:34 +08:00
import { AbstractCheckboxProps } from '../checkbox/Checkbox';
import Radio from './radio';
import { RadioChangeEvent } from './interface';
export type RadioButtonProps = AbstractCheckboxProps<RadioChangeEvent>;
2016-08-10 10:26:42 +08:00
export default class RadioButton extends React.Component<RadioButtonProps, any> {
static defaultProps = {
prefixCls: 'ant-radio-button',
2016-07-13 11:14:24 +08:00
};
static contextTypes = {
radioGroup: PropTypes.any,
};
render() {
2017-07-31 01:50:46 +08:00
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;
}
2018-11-07 14:24:36 +08:00
return <Radio {...radioProps} />;
}
}