2020-05-28 11:45:50 +00:00
|
|
|
import { reactive, provide } from 'vue';
|
2019-01-12 03:33:27 +00:00
|
|
|
import PropTypes from '../_util/vue-types';
|
2020-07-29 07:34:19 +00:00
|
|
|
import { getComponent, getSlot } from '../_util/props-util';
|
2019-03-08 05:48:55 +00:00
|
|
|
import defaultRenderEmpty from './renderEmpty';
|
2020-03-07 11:45:13 +00:00
|
|
|
import LocaleProvider, { ANT_MARK } from '../locale-provider';
|
|
|
|
import LocaleReceiver from '../locale-provider/LocaleReceiver';
|
2019-01-02 12:13:25 +00:00
|
|
|
|
2019-03-15 07:12:28 +00:00
|
|
|
function getWatch(keys = []) {
|
|
|
|
const watch = {};
|
|
|
|
keys.forEach(k => {
|
2020-02-12 02:38:15 +00:00
|
|
|
watch[k] = function(value) {
|
2020-05-28 15:36:43 +00:00
|
|
|
this.configProvider[k] = value;
|
2019-03-15 07:12:28 +00:00
|
|
|
};
|
|
|
|
});
|
|
|
|
return watch;
|
|
|
|
}
|
|
|
|
|
2019-01-02 12:13:25 +00:00
|
|
|
const ConfigProvider = {
|
|
|
|
name: 'AConfigProvider',
|
|
|
|
props: {
|
|
|
|
getPopupContainer: PropTypes.func,
|
2019-03-08 05:48:55 +00:00
|
|
|
prefixCls: PropTypes.string,
|
2019-09-26 14:05:24 +00:00
|
|
|
renderEmpty: PropTypes.func,
|
|
|
|
csp: PropTypes.object,
|
2019-03-08 05:48:55 +00:00
|
|
|
autoInsertSpaceInButton: PropTypes.bool,
|
2020-03-07 11:45:13 +00:00
|
|
|
locale: PropTypes.object,
|
|
|
|
pageHeader: PropTypes.object,
|
2020-04-23 07:40:17 +00:00
|
|
|
transformCellText: PropTypes.func,
|
2019-01-02 12:13:25 +00:00
|
|
|
},
|
2020-05-28 15:36:43 +00:00
|
|
|
created() {
|
2020-07-28 10:37:07 +00:00
|
|
|
this.configProvider = reactive({
|
|
|
|
...this.$props,
|
|
|
|
getPrefixCls: this.getPrefixCls,
|
|
|
|
renderEmpty: this.renderEmptyComponent,
|
|
|
|
});
|
|
|
|
provide('configProvider', this.configProvider);
|
2019-01-02 12:13:25 +00:00
|
|
|
},
|
2019-03-15 07:12:28 +00:00
|
|
|
watch: {
|
2020-04-23 07:40:17 +00:00
|
|
|
...getWatch([
|
|
|
|
'prefixCls',
|
|
|
|
'csp',
|
|
|
|
'autoInsertSpaceInButton',
|
|
|
|
'locale',
|
|
|
|
'pageHeader',
|
|
|
|
'transformCellText',
|
|
|
|
]),
|
2019-03-15 07:12:28 +00:00
|
|
|
},
|
2019-03-15 02:04:14 +00:00
|
|
|
methods: {
|
2020-06-28 15:11:31 +00:00
|
|
|
renderEmptyComponent(name) {
|
|
|
|
const renderEmpty = getComponent(this, 'renderEmpty', {}, false) || defaultRenderEmpty;
|
|
|
|
return renderEmpty(name);
|
2019-03-14 13:21:58 +00:00
|
|
|
},
|
2019-03-08 05:48:55 +00:00
|
|
|
getPrefixCls(suffixCls, customizePrefixCls) {
|
|
|
|
const { prefixCls = 'ant' } = this.$props;
|
|
|
|
if (customizePrefixCls) return customizePrefixCls;
|
|
|
|
return suffixCls ? `${prefixCls}-${suffixCls}` : prefixCls;
|
|
|
|
},
|
2020-03-07 11:45:13 +00:00
|
|
|
renderProvider(legacyLocale) {
|
|
|
|
return (
|
|
|
|
<LocaleProvider locale={this.locale || legacyLocale} _ANT_MARK__={ANT_MARK}>
|
2020-07-29 07:34:19 +00:00
|
|
|
{getSlot(this)}
|
2020-03-07 11:45:13 +00:00
|
|
|
</LocaleProvider>
|
|
|
|
);
|
|
|
|
},
|
2019-03-08 05:48:55 +00:00
|
|
|
},
|
2020-03-07 11:45:13 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
render() {
|
2020-05-28 11:45:50 +00:00
|
|
|
return <LocaleReceiver children={(_, __, legacyLocale) => this.renderProvider(legacyLocale)} />;
|
2019-03-08 05:48:55 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
export const ConfigConsumerProps = {
|
|
|
|
getPrefixCls: (suffixCls, customizePrefixCls) => {
|
|
|
|
if (customizePrefixCls) return customizePrefixCls;
|
|
|
|
return `ant-${suffixCls}`;
|
2019-01-02 12:13:25 +00:00
|
|
|
},
|
2019-03-14 13:21:58 +00:00
|
|
|
renderEmpty: defaultRenderEmpty,
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2019-01-02 12:13:25 +00:00
|
|
|
|
|
|
|
/* istanbul ignore next */
|
2020-06-02 15:21:24 +00:00
|
|
|
ConfigProvider.install = function(app) {
|
|
|
|
app.component(ConfigProvider.name, ConfigProvider);
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2019-01-02 12:13:25 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
export default ConfigProvider;
|