ant-design/components/radio/radioButton.tsx

32 lines
1.1 KiB
TypeScript
Raw Normal View History

import * as React from 'react';
2018-08-07 21:07:52 +08:00
import * as PropTypes from 'prop-types';
import Radio from './radio';
import { RadioChangeEvent } from './interface';
import { AbstractCheckboxProps } from '../checkbox/Checkbox';
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
export type RadioButtonProps = AbstractCheckboxProps<RadioChangeEvent>;
2016-08-10 10:26:42 +08:00
export default class RadioButton extends React.Component<RadioButtonProps, any> {
static contextTypes = {
radioGroup: PropTypes.any,
};
2018-11-09 17:38:19 +08:00
context: any;
renderRadioButton = ({ getPrefixCls }: ConfigConsumerProps) => {
const { prefixCls: customizePrefixCls, ...radioProps }: RadioButtonProps = this.props;
const prefixCls = getPrefixCls('radio-button', customizePrefixCls);
if (this.context.radioGroup) {
radioProps.checked = this.props.value === this.context.radioGroup.value;
radioProps.disabled = this.props.disabled || this.context.radioGroup.disabled;
}
return <Radio prefixCls={prefixCls} {...radioProps} />;
2018-12-07 20:02:01 +08:00
};
render() {
2018-12-07 20:02:01 +08:00
return <ConfigConsumer>{this.renderRadioButton}</ConfigConsumer>;
}
}