2020-10-13 11:02:03 +00:00
|
|
|
import { defineComponent, inject } from 'vue';
|
2019-01-12 03:33:27 +00:00
|
|
|
import Radio from './Radio';
|
2020-06-13 14:32:10 +00:00
|
|
|
import { getOptionProps, getSlot } from '../_util/props-util';
|
2020-09-30 02:47:18 +00:00
|
|
|
import { defaultConfigProvider } from '../config-provider';
|
2018-09-05 13:28:54 +00:00
|
|
|
|
2020-10-13 11:02:03 +00:00
|
|
|
export default defineComponent({
|
2018-09-05 13:28:54 +00:00
|
|
|
name: 'ARadioButton',
|
|
|
|
props: {
|
|
|
|
...Radio.props,
|
|
|
|
},
|
2020-06-13 14:32:10 +00:00
|
|
|
setup() {
|
|
|
|
return {
|
2020-09-30 02:47:18 +00:00
|
|
|
configProvider: inject('configProvider', defaultConfigProvider),
|
2020-08-14 09:04:32 +00:00
|
|
|
radioGroupContext: inject('radioGroupContext', {}),
|
2020-06-13 14:32:10 +00:00
|
|
|
};
|
2018-09-05 13:28:54 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
render() {
|
2020-06-13 14:32:10 +00:00
|
|
|
const props = getOptionProps(this);
|
|
|
|
const { prefixCls: customizePrefixCls, ...otherProps } = props;
|
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 = {
|
2020-06-13 14:32:10 +00:00
|
|
|
prefixCls,
|
|
|
|
...otherProps,
|
2019-05-28 03:37:38 +00:00
|
|
|
};
|
2018-09-05 13:28:54 +00:00
|
|
|
if (this.radioGroupContext) {
|
2020-06-13 14:32:10 +00:00
|
|
|
radioProps.onChange = this.radioGroupContext.onRadioChange;
|
|
|
|
radioProps.checked = props.value === this.radioGroupContext.stateValue;
|
|
|
|
radioProps.disabled = props.disabled || this.radioGroupContext.disabled;
|
2018-09-05 13:28:54 +00:00
|
|
|
}
|
2020-06-13 14:32:10 +00:00
|
|
|
return <Radio {...radioProps}>{getSlot(this)}</Radio>;
|
2018-09-05 13:28:54 +00:00
|
|
|
},
|
2020-10-13 11:02:03 +00:00
|
|
|
});
|