From 7dbf5ed4d72c66b963875180b9925a5b72879d37 Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Wed, 2 Jan 2019 20:13:25 +0800 Subject: [PATCH] feat: add config-provider --- components/config-provider/demo/index.vue | 32 +++++++++++++++++++++ components/config-provider/index.en-US.md | 16 +++++++++++ components/config-provider/index.jsx | 25 ++++++++++++++++ components/config-provider/index.zh-CN.md | 15 ++++++++++ components/config-provider/style/index.js | 1 + components/config-provider/style/index.less | 2 ++ components/index.js | 4 +++ components/style.js | 1 + site/components.js | 2 ++ 9 files changed, 98 insertions(+) create mode 100644 components/config-provider/demo/index.vue create mode 100644 components/config-provider/index.en-US.md create mode 100644 components/config-provider/index.jsx create mode 100644 components/config-provider/index.zh-CN.md create mode 100644 components/config-provider/style/index.js create mode 100644 components/config-provider/style/index.less diff --git a/components/config-provider/demo/index.vue b/components/config-provider/demo/index.vue new file mode 100644 index 000000000..08b0655ce --- /dev/null +++ b/components/config-provider/demo/index.vue @@ -0,0 +1,32 @@ + diff --git a/components/config-provider/index.en-US.md b/components/config-provider/index.en-US.md new file mode 100644 index 000000000..52629e520 --- /dev/null +++ b/components/config-provider/index.en-US.md @@ -0,0 +1,16 @@ + +## Usage + +This component provides a configuration to all Vue components underneath itself via the [provide / inject](https://vuejs.org/v2/api/#provide-inject), In the render tree all components will have access to the provided config. + +````html + + + +```` + +## API + +| Property | Description | Type | Default | +| -------- | ----------- | ---- | ------- | +| getPopupContainer | to set the container of the popup element. The default is to create a `div` element in `body`. | Function(triggerNode) | `() => document.body` | diff --git a/components/config-provider/index.jsx b/components/config-provider/index.jsx new file mode 100644 index 000000000..289f47327 --- /dev/null +++ b/components/config-provider/index.jsx @@ -0,0 +1,25 @@ + +import PropTypes from '../_util/vue-types' + +const ConfigProvider = { + name: 'AConfigProvider', + props: { + getPopupContainer: PropTypes.func, + }, + provide () { + return { + configProvider: this.$props, + } + }, + render () { + return this.$slots.default ? this.$slots.default[0] : null + }, +} + +/* istanbul ignore next */ +ConfigProvider.install = function (Vue) { + Vue.component(ConfigProvider.name, ConfigProvider) +} + +export default ConfigProvider + diff --git a/components/config-provider/index.zh-CN.md b/components/config-provider/index.zh-CN.md new file mode 100644 index 000000000..5beed7964 --- /dev/null +++ b/components/config-provider/index.zh-CN.md @@ -0,0 +1,15 @@ +## 使用 + +ConfigProvider 使用 Vue 的 [provide / inject](https://vuejs.org/v2/api/#provide-inject) 特性,只需在应用外围包裹一次即可全局生效。 + +````html + + + +```` + +## API + +| 参数 | 说明 | 类型 | 默认值 | +| --- | --- | --- | --- | +| getPopupContainer | 弹出框(Select, Tooltip, Menu 等等)渲染父节点,默认渲染到 body 上。 | Function(triggerNode) | () => document.body | diff --git a/components/config-provider/style/index.js b/components/config-provider/style/index.js new file mode 100644 index 000000000..d74e52ee9 --- /dev/null +++ b/components/config-provider/style/index.js @@ -0,0 +1 @@ +import './index.less'; diff --git a/components/config-provider/style/index.less b/components/config-provider/style/index.less new file mode 100644 index 000000000..df1dee5e0 --- /dev/null +++ b/components/config-provider/style/index.less @@ -0,0 +1,2 @@ +// placeholder +@import '../../style/themes/default'; diff --git a/components/index.js b/components/index.js index 9d70e0f7e..122e1a1b7 100644 --- a/components/index.js +++ b/components/index.js @@ -126,6 +126,8 @@ import { default as Skeleton } from './skeleton' import { default as Comment } from './comment' +import { default as ConfigProvider } from './config-provider' + const components = [ Affix, Anchor, @@ -180,6 +182,7 @@ const components = [ Drawer, Skeleton, Comment, + ConfigProvider, ] const install = function (Vue) { @@ -259,6 +262,7 @@ export { Drawer, Skeleton, Comment, + ConfigProvider, } export default { diff --git a/components/style.js b/components/style.js index 25cf8b5b7..41a18a4c6 100644 --- a/components/style.js +++ b/components/style.js @@ -52,3 +52,4 @@ import './tree-select/style' import './drawer/style' import './skeleton/style' import './comment/style' +import './config-provider/style' diff --git a/site/components.js b/site/components.js index ad20b73bf..8877b500d 100644 --- a/site/components.js +++ b/site/components.js @@ -57,6 +57,7 @@ import { Drawer, Skeleton, Comment, + ConfigProvider, } from 'ant-design-vue' Vue.prototype.$message = message @@ -121,6 +122,7 @@ Vue.use(Tooltip) Vue.use(Upload) Vue.use(Skeleton) Vue.use(Comment) +Vue.use(ConfigProvider) /* v1.1.2 registration methods */ // Vue.component(Affix.name, Affix) // a-affix