From 333666f506d6b8413faf5d9f978391a01d66b48c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=98=89=E6=B6=B5?= Date: Thu, 30 May 2019 12:00:47 +0800 Subject: [PATCH] [new feauture] Notify: add onClose option --- docs/markdown/changelog.zh-CN.md | 6 +++++- packages/notify/en-US.md | 3 ++- packages/notify/index.ts | 5 +++++ packages/notify/test/index.spec.js | 5 ++++- packages/notify/zh-CN.md | 1 + types/notify.d.ts | 1 + 6 files changed, 18 insertions(+), 3 deletions(-) diff --git a/docs/markdown/changelog.zh-CN.md b/docs/markdown/changelog.zh-CN.md index eec9ad1c1..7e58d8ab6 100644 --- a/docs/markdown/changelog.zh-CN.md +++ b/docs/markdown/changelog.zh-CN.md @@ -6,6 +6,10 @@ - 新增`sticky`参数 +##### Notify + +- 新增`onClose`选项 + ##### Rate - 新增`gutter`属性 @@ -17,7 +21,7 @@ ##### Toast -- 新增`onOpened`属性 +- 新增`onOpened`选项 ### [v2.0.0-beta.2](https://github.com/youzan/vant/tree/v2.0.0-beta.2) diff --git a/packages/notify/en-US.md b/packages/notify/en-US.md index bd9a40d6c..8812fb0a1 100644 --- a/packages/notify/en-US.md +++ b/packages/notify/en-US.md @@ -58,4 +58,5 @@ export default { | color | Message color | `String` | `#fff` | | | background | Background color | `String` | `#f44` | | className | Custom className | `String | Array | Object` | - | -| onClick | Click callback | `Function` | - | +| onClick | Callback function after click | `Function` | - | +| onClose | Callback function after close | `Function` | - | diff --git a/packages/notify/index.ts b/packages/notify/index.ts index feee3451a..98f3f2218 100644 --- a/packages/notify/index.ts +++ b/packages/notify/index.ts @@ -53,6 +53,7 @@ function defaultOptions(): NotifyOptions { background: RED, duration: 3000, className: '', + onClose: null, onClick: null }; } @@ -60,6 +61,10 @@ function defaultOptions(): NotifyOptions { Notify.clear = () => { if (instance) { instance.value = false; + + if (instance.onClose) { + instance.onClose(); + } } }; diff --git a/packages/notify/test/index.spec.js b/packages/notify/test/index.spec.js index 88efb6e8b..0d87177a3 100644 --- a/packages/notify/test/index.spec.js +++ b/packages/notify/test/index.spec.js @@ -14,11 +14,13 @@ test('create a notify', async () => { }); test('notify disappear', async () => { + const onClose = jest.fn(); const notify = Notify({ message: 'test', color: 'red', background: 'blue', - duration: 10 + duration: 10, + onClose }); await later(); @@ -26,6 +28,7 @@ test('notify disappear', async () => { await later(20); expect(notify.$el.outerHTML).toMatchSnapshot(); + expect(onClose).toHaveBeenCalledTimes(1); Notify({ message: 'text2', diff --git a/packages/notify/zh-CN.md b/packages/notify/zh-CN.md index e1d0e79d7..c7d44329a 100644 --- a/packages/notify/zh-CN.md +++ b/packages/notify/zh-CN.md @@ -59,3 +59,4 @@ export default { | background | 背景颜色 | `String` | `#f44` | 1.4.7 | | className | 自定义类名 | `String | Array | Object` | - | 1.6.0 | | onClick | 点击时的回调函数 | `Function` | - | 2.0.0 | +| onClose | 关闭时的回调函数 | `Function` | - | 2.0.0 | diff --git a/types/notify.d.ts b/types/notify.d.ts index a17563378..1bce5b80c 100644 --- a/types/notify.d.ts +++ b/types/notify.d.ts @@ -9,6 +9,7 @@ export type NotifyOptions = { duration?: number; className?: any; background?: string; + onClose?: (() => void) | null; onClick?: ((event: Event) => void) | null; }