2019-01-12 03:33:27 +00:00
|
|
|
import Radio from './Radio';
|
2020-01-18 13:44:13 +00:00
|
|
|
import { getOptionProps, getListeners } from '../_util/props-util';
|
2019-03-18 12:00:00 +00:00
|
|
|
import { ConfigConsumerProps } from '../config-provider';
|
2018-09-05 13:28:54 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'ARadioButton',
|
|
|
|
props: {
|
|
|
|
...Radio.props,
|
|
|
|
},
|
|
|
|
inject: {
|
|
|
|
radioGroupContext: { default: undefined },
|
2019-09-11 14:35:25 +00:00
|
|
|
configProvider: { default: () => ConfigConsumerProps },
|
2018-09-05 13:28:54 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
render() {
|
2019-05-28 03:37:38 +00:00
|
|
|
const { prefixCls: customizePrefixCls, ...otherProps } = getOptionProps(this);
|
2019-09-11 14:35:25 +00:00
|
|
|
const getPrefixCls = this.configProvider.getPrefixCls;
|
2019-03-18 12:00:00 +00:00
|
|
|
const prefixCls = getPrefixCls('radio-button', customizePrefixCls);
|
|
|
|
|
2019-05-28 03:37:38 +00:00
|
|
|
const radioProps = {
|
|
|
|
props: {
|
|
|
|
...otherProps,
|
|
|
|
prefixCls,
|
|
|
|
},
|
2020-01-18 13:44:13 +00:00
|
|
|
on: getListeners(this),
|
2019-05-28 03:37:38 +00:00
|
|
|
};
|
2018-09-05 13:28:54 +00:00
|
|
|
if (this.radioGroupContext) {
|
2019-01-12 03:33:27 +00:00
|
|
|
radioProps.on.change = this.radioGroupContext.onRadioChange;
|
2019-04-09 12:39:49 +00:00
|
|
|
radioProps.props.checked = this.$props.value === this.radioGroupContext.stateValue;
|
|
|
|
radioProps.props.disabled = this.$props.disabled || this.radioGroupContext.disabled;
|
2018-09-05 13:28:54 +00:00
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
return <Radio {...radioProps}>{this.$slots.default}</Radio>;
|
2018-09-05 13:28:54 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|