2019-03-15 07:12:28 +00:00
|
|
|
import Vue from 'vue';
|
2019-01-12 03:33:27 +00:00
|
|
|
import PropTypes from '../_util/vue-types';
|
2019-04-10 05:28:07 +00:00
|
|
|
import { filterEmpty, getComponentFromProp } from '../_util/props-util';
|
2019-03-08 05:48:55 +00:00
|
|
|
import defaultRenderEmpty from './renderEmpty';
|
2019-08-28 02:50:19 +00:00
|
|
|
import Base from '../base';
|
2019-01-02 12:13:25 +00:00
|
|
|
|
2019-03-15 07:12:28 +00:00
|
|
|
function getWatch(keys = []) {
|
|
|
|
const watch = {};
|
|
|
|
keys.forEach(k => {
|
|
|
|
watch[k] = function() {
|
|
|
|
this._proxyVm._data[k] = value;
|
|
|
|
};
|
|
|
|
});
|
|
|
|
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,
|
|
|
|
renderEmpty: PropTypes.any,
|
|
|
|
csp: PropTypes.any,
|
|
|
|
autoInsertSpaceInButton: PropTypes.bool,
|
2019-01-02 12:13:25 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
provide() {
|
2019-03-15 07:12:28 +00:00
|
|
|
const _self = this;
|
|
|
|
this._proxyVm = new Vue({
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
..._self.$props,
|
|
|
|
getPrefixCls: _self.getPrefixCls,
|
|
|
|
renderEmpty: _self.renderEmptyComponent,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
});
|
2019-01-02 12:13:25 +00:00
|
|
|
return {
|
2019-03-15 07:12:28 +00:00
|
|
|
configProvider: this._proxyVm._data,
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2019-01-02 12:13:25 +00:00
|
|
|
},
|
2019-03-15 07:12:28 +00:00
|
|
|
watch: {
|
2019-05-28 03:37:38 +00:00
|
|
|
...getWatch(['prefixCls', 'csp', 'autoInsertSpaceInButton']),
|
2019-03-15 07:12:28 +00:00
|
|
|
},
|
2019-03-15 02:04:14 +00:00
|
|
|
methods: {
|
2019-09-11 14:35:25 +00:00
|
|
|
renderEmptyComponent(h, name) {
|
|
|
|
const renderEmpty =
|
|
|
|
getComponentFromProp(this, 'renderEmpty', {}, false) || defaultRenderEmpty;
|
|
|
|
return renderEmpty(h, 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;
|
|
|
|
},
|
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
render() {
|
2019-03-08 05:48:55 +00:00
|
|
|
return this.$slots.default ? filterEmpty(this.$slots.default) : null;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
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 */
|
2019-01-12 03:33:27 +00:00
|
|
|
ConfigProvider.install = function(Vue) {
|
2019-08-28 02:50:19 +00:00
|
|
|
Vue.use(Base);
|
2019-01-12 03:33:27 +00:00
|
|
|
Vue.component(ConfigProvider.name, ConfigProvider);
|
|
|
|
};
|
2019-01-02 12:13:25 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
export default ConfigProvider;
|