From bb9ca793113903f82d8bd948a807201b340e701d Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Mon, 5 Feb 2018 19:12:41 +0800 Subject: [PATCH] add notification and fix tag bug --- components/_util/BaseMixin.js | 2 +- components/_util/createChainedFunction.js | 22 +++ components/_util/getTransitionProps.js | 28 ++++ components/notification/src/Notice.vue | 64 ++++++++ components/notification/src/Notification.vue | 145 +++++++++++++++++++ components/notification/src/index.js | 2 + components/tag/Tag.vue | 67 +++++---- components/tag/demo/control.vue | 4 +- 8 files changed, 302 insertions(+), 32 deletions(-) create mode 100644 components/_util/createChainedFunction.js create mode 100644 components/_util/getTransitionProps.js create mode 100644 components/notification/src/Notice.vue create mode 100644 components/notification/src/Notification.vue create mode 100644 components/notification/src/index.js diff --git a/components/_util/BaseMixin.js b/components/_util/BaseMixin.js index 7c3206312..52d853735 100644 --- a/components/_util/BaseMixin.js +++ b/components/_util/BaseMixin.js @@ -1,7 +1,7 @@ export default { methods: { setState (state, callback) { - Object.assign(this.$data, state) + Object.assign(this.$data, typeof state === 'function' ? state(this.$data) : state) this.$nextTick(() => { callback && callback() }) diff --git a/components/_util/createChainedFunction.js b/components/_util/createChainedFunction.js new file mode 100644 index 000000000..f9334e32e --- /dev/null +++ b/components/_util/createChainedFunction.js @@ -0,0 +1,22 @@ +/** + * Safe chained function + * + * Will only create a new function if needed, + * otherwise will pass back existing functions or null. + * + * @returns {function|null} + */ +export default function createChainedFunction () { + const args = [].slice.call(arguments, 0) + if (args.length === 1) { + return args[0] + } + + return function chainedFunction () { + for (let i = 0; i < args.length; i++) { + if (args[i] && args[i].apply) { + args[i].apply(this, arguments) + } + } + } +} diff --git a/components/_util/getTransitionProps.js b/components/_util/getTransitionProps.js new file mode 100644 index 000000000..369971cd5 --- /dev/null +++ b/components/_util/getTransitionProps.js @@ -0,0 +1,28 @@ +import animate from './css-animation' +const noop = () => {} +const getTransitionProps = (transitionName, opt = {}) => { + const { beforeEnter, enter, leave, afterLeave, appear = true, tag } = opt + const transitionProps = { + props: { + appear, + css: false, + }, + on: { + beforeEnter: beforeEnter || noop, + enter: enter || ((el, done) => { + animate(el, `${transitionName}-enter`, done) + }), + leave: leave || ((el, done) => { + animate(el, `${transitionName}-leave`, done) + }), + afterLeave: afterLeave || noop, + }, + } + // transition-group + if (tag) { + transitionProps.tag = tag + } + return transitionProps +} + +export default getTransitionProps diff --git a/components/notification/src/Notice.vue b/components/notification/src/Notice.vue new file mode 100644 index 000000000..18129498d --- /dev/null +++ b/components/notification/src/Notice.vue @@ -0,0 +1,64 @@ + diff --git a/components/notification/src/Notification.vue b/components/notification/src/Notification.vue new file mode 100644 index 000000000..848f302d1 --- /dev/null +++ b/components/notification/src/Notification.vue @@ -0,0 +1,145 @@ + diff --git a/components/notification/src/index.js b/components/notification/src/index.js new file mode 100644 index 000000000..15721f977 --- /dev/null +++ b/components/notification/src/index.js @@ -0,0 +1,2 @@ +import Notification from './Notification' +export default Notification diff --git a/components/tag/Tag.vue b/components/tag/Tag.vue index 620dacef1..9c3519b61 100644 --- a/components/tag/Tag.vue +++ b/components/tag/Tag.vue @@ -1,25 +1,10 @@ - diff --git a/components/tag/demo/control.vue b/components/tag/demo/control.vue index 2b0c2f749..eff2c24f3 100644 --- a/components/tag/demo/control.vue +++ b/components/tag/demo/control.vue @@ -2,11 +2,11 @@