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