2019-03-15 15:12:28 +08:00
|
|
|
import Vue from 'vue';
|
2019-01-12 11:33:27 +08:00
|
|
|
import PropTypes from '../_util/vue-types';
|
2019-04-10 13:28:07 +08:00
|
|
|
import { filterEmpty, getComponentFromProp } from '../_util/props-util';
|
2019-03-08 13:48:55 +08:00
|
|
|
import defaultRenderEmpty from './renderEmpty';
|
2019-08-28 10:50:19 +08:00
|
|
|
import Base from '../base';
|
2019-01-02 20:13:25 +08:00
|
|
|
|
2019-03-15 15:12:28 +08:00
|
|
|
function getWatch(keys = []) {
|
|
|
|
const watch = {};
|
|
|
|
keys.forEach(k => {
|
2020-02-12 10:38:15 +08:00
|
|
|
watch[k] = function(value) {
|
2019-03-15 15:12:28 +08:00
|
|
|
this._proxyVm._data[k] = value;
|
|
|
|
};
|
|
|
|
});
|
|
|
|
return watch;
|
|
|
|
}
|
|
|
|
|
2019-01-02 20:13:25 +08:00
|
|
|
const ConfigProvider = {
|
|
|
|
name: 'AConfigProvider',
|
|
|
|
props: {
|
|
|
|
getPopupContainer: PropTypes.func,
|
2019-03-08 13:48:55 +08:00
|
|
|
prefixCls: PropTypes.string,
|
2019-09-26 22:05:24 +08:00
|
|
|
renderEmpty: PropTypes.func,
|
|
|
|
csp: PropTypes.object,
|
2019-03-08 13:48:55 +08:00
|
|
|
autoInsertSpaceInButton: PropTypes.bool,
|
2019-01-02 20:13:25 +08:00
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
provide() {
|
2019-03-15 15:12:28 +08:00
|
|
|
const _self = this;
|
|
|
|
this._proxyVm = new Vue({
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
..._self.$props,
|
|
|
|
getPrefixCls: _self.getPrefixCls,
|
|
|
|
renderEmpty: _self.renderEmptyComponent,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
});
|
2019-01-02 20:13:25 +08:00
|
|
|
return {
|
2019-03-15 15:12:28 +08:00
|
|
|
configProvider: this._proxyVm._data,
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2019-01-02 20:13:25 +08:00
|
|
|
},
|
2019-03-15 15:12:28 +08:00
|
|
|
watch: {
|
2019-05-28 11:37:38 +08:00
|
|
|
...getWatch(['prefixCls', 'csp', 'autoInsertSpaceInButton']),
|
2019-03-15 15:12:28 +08:00
|
|
|
},
|
2019-03-15 10:04:14 +08:00
|
|
|
methods: {
|
2019-09-11 22:35:25 +08:00
|
|
|
renderEmptyComponent(h, name) {
|
|
|
|
const renderEmpty =
|
|
|
|
getComponentFromProp(this, 'renderEmpty', {}, false) || defaultRenderEmpty;
|
|
|
|
return renderEmpty(h, name);
|
2019-03-14 21:21:58 +08:00
|
|
|
},
|
2019-03-08 13:48:55 +08:00
|
|
|
getPrefixCls(suffixCls, customizePrefixCls) {
|
|
|
|
const { prefixCls = 'ant' } = this.$props;
|
|
|
|
if (customizePrefixCls) return customizePrefixCls;
|
|
|
|
return suffixCls ? `${prefixCls}-${suffixCls}` : prefixCls;
|
|
|
|
},
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
render() {
|
2019-11-26 15:57:22 +08:00
|
|
|
return this.$slots.default ? filterEmpty(this.$slots.default)[0] : null;
|
2019-03-08 13:48:55 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
export const ConfigConsumerProps = {
|
|
|
|
getPrefixCls: (suffixCls, customizePrefixCls) => {
|
|
|
|
if (customizePrefixCls) return customizePrefixCls;
|
|
|
|
return `ant-${suffixCls}`;
|
2019-01-02 20:13:25 +08:00
|
|
|
},
|
2019-03-14 21:21:58 +08:00
|
|
|
renderEmpty: defaultRenderEmpty,
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2019-01-02 20:13:25 +08:00
|
|
|
|
|
|
|
/* istanbul ignore next */
|
2019-01-12 11:33:27 +08:00
|
|
|
ConfigProvider.install = function(Vue) {
|
2019-08-28 10:50:19 +08:00
|
|
|
Vue.use(Base);
|
2019-01-12 11:33:27 +08:00
|
|
|
Vue.component(ConfigProvider.name, ConfigProvider);
|
|
|
|
};
|
2019-01-02 20:13:25 +08:00
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
export default ConfigProvider;
|