From 44c048580b1d0bdee97f862337e9db5f1c455d28 Mon Sep 17 00:00:00 2001
From: tangjinzhou <415800467@qq.com>
Date: Wed, 3 Jun 2020 22:46:20 +0800
Subject: [PATCH] feat: update alert
---
components/alert/index.jsx | 28 +++++++++++++---------------
examples/App.vue | 31 ++++++++++---------------------
examples/index.js | 2 ++
3 files changed, 25 insertions(+), 36 deletions(-)
diff --git a/components/alert/index.jsx b/components/alert/index.jsx
index cded4e72a..5ea9d51f0 100644
--- a/components/alert/index.jsx
+++ b/components/alert/index.jsx
@@ -1,4 +1,4 @@
-import { Transition } from 'vue';
+import { Transition, inject, cloneVNode } from 'vue';
import CloseOutlined from '@ant-design/icons-vue/CloseOutlined';
import CheckCircleOutlined from '@ant-design/icons-vue/CheckCircleOutlined';
import ExclamationCircleOutlined from '@ant-design/icons-vue/ExclamationCircleOutlined';
@@ -12,10 +12,8 @@ import classNames from 'classnames';
import BaseMixin from '../_util/BaseMixin';
import PropTypes from '../_util/vue-types';
import getTransitionProps from '../_util/getTransitionProps';
-import { getComponentFromProp, isValidElement } from '../_util/props-util';
-import { cloneElement } from '../_util/vnode';
+import { getComponent, isValidElement } from '../_util/props-util';
import { ConfigConsumerProps } from '../config-provider';
-import Base from '../base';
function noop() {}
@@ -61,8 +59,10 @@ const Alert = {
name: 'AAlert',
props: AlertProps,
mixins: [BaseMixin],
- inject: {
- configProvider: { default: () => ConfigConsumerProps },
+ setup() {
+ return {
+ configProvider: inject('configProvider', ConfigConsumerProps),
+ };
},
data() {
return {
@@ -99,11 +99,10 @@ const Alert = {
const prefixCls = getPrefixCls('alert', customizePrefixCls);
let { closable, type, showIcon } = this;
- const { closeText, description, message, icon } = this.$props;
- // const closeText = getComponentFromProp(this, 'closeText');
- // const description = getComponentFromProp(this, 'description');
- // const message = getComponentFromProp(this, 'message');
- // const icon = getComponentFromProp(this, 'icon');
+ const closeText = getComponent(this, 'closeText');
+ const description = getComponent(this, 'description');
+ const message = getComponent(this, 'message');
+ const icon = getComponent(this, 'icon');
// banner模式默认有 Icon
showIcon = banner && showIcon === undefined ? true : showIcon;
// banner模式默认为警告
@@ -133,7 +132,7 @@ const Alert = {
const iconNode = (icon &&
(isValidElement(icon) ? (
- cloneElement(icon, {
+ cloneVNode(icon, {
class: `${prefixCls}-icon`,
})
) : (
@@ -159,9 +158,8 @@ const Alert = {
};
/* istanbul ignore next */
-Alert.install = function(Vue) {
- Vue.use(Base);
- Vue.component(Alert.name, Alert);
+Alert.install = function(app) {
+ app.component(Alert.name, Alert);
};
export default Alert;
diff --git a/examples/App.vue b/examples/App.vue
index c4433e844..723e2f835 100644
--- a/examples/App.vue
+++ b/examples/App.vue
@@ -1,26 +1,15 @@
-
-
- Affix top
-
-
+
-
-
- Affix bottom
-
-
+
+
+
+
+
-
-
diff --git a/examples/index.js b/examples/index.js
index c7f60ce72..7f2050efe 100644
--- a/examples/index.js
+++ b/examples/index.js
@@ -4,6 +4,7 @@ import App from './App.vue';
import Button from 'ant-design-vue/button';
import Drawer from 'ant-design-vue/drawer';
import Affix from 'ant-design-vue/affix';
+import Alert from 'ant-design-vue/alert';
import ConfigProvider from 'ant-design-vue/config-provider';
import 'ant-design-vue/style.js';
@@ -12,4 +13,5 @@ createApp(App)
.use(ConfigProvider)
.use(Drawer)
.use(Affix)
+ .use(Alert)
.mount('#app');