mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
[new feauture] Notify: add onClose option
This commit is contained in:
parent
82134fe402
commit
333666f506
@ -6,6 +6,10 @@
|
|||||||
|
|
||||||
- 新增`sticky`参数
|
- 新增`sticky`参数
|
||||||
|
|
||||||
|
##### Notify
|
||||||
|
|
||||||
|
- 新增`onClose`选项
|
||||||
|
|
||||||
##### Rate
|
##### Rate
|
||||||
|
|
||||||
- 新增`gutter`属性
|
- 新增`gutter`属性
|
||||||
@ -17,7 +21,7 @@
|
|||||||
|
|
||||||
##### Toast
|
##### Toast
|
||||||
|
|
||||||
- 新增`onOpened`属性
|
- 新增`onOpened`选项
|
||||||
|
|
||||||
|
|
||||||
### [v2.0.0-beta.2](https://github.com/youzan/vant/tree/v2.0.0-beta.2)
|
### [v2.0.0-beta.2](https://github.com/youzan/vant/tree/v2.0.0-beta.2)
|
||||||
|
@ -58,4 +58,5 @@ export default {
|
|||||||
| color | Message color | `String` | `#fff` | |
|
| color | Message color | `String` | `#fff` | |
|
||||||
| background | Background color | `String` | `#f44` |
|
| background | Background color | `String` | `#f44` |
|
||||||
| className | Custom className | `String | Array | Object` | - |
|
| className | Custom className | `String | Array | Object` | - |
|
||||||
| onClick | Click callback | `Function` | - |
|
| onClick | Callback function after click | `Function` | - |
|
||||||
|
| onClose | Callback function after close | `Function` | - |
|
||||||
|
@ -53,6 +53,7 @@ function defaultOptions(): NotifyOptions {
|
|||||||
background: RED,
|
background: RED,
|
||||||
duration: 3000,
|
duration: 3000,
|
||||||
className: '',
|
className: '',
|
||||||
|
onClose: null,
|
||||||
onClick: null
|
onClick: null
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -60,6 +61,10 @@ function defaultOptions(): NotifyOptions {
|
|||||||
Notify.clear = () => {
|
Notify.clear = () => {
|
||||||
if (instance) {
|
if (instance) {
|
||||||
instance.value = false;
|
instance.value = false;
|
||||||
|
|
||||||
|
if (instance.onClose) {
|
||||||
|
instance.onClose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -14,11 +14,13 @@ test('create a notify', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('notify disappear', async () => {
|
test('notify disappear', async () => {
|
||||||
|
const onClose = jest.fn();
|
||||||
const notify = Notify({
|
const notify = Notify({
|
||||||
message: 'test',
|
message: 'test',
|
||||||
color: 'red',
|
color: 'red',
|
||||||
background: 'blue',
|
background: 'blue',
|
||||||
duration: 10
|
duration: 10,
|
||||||
|
onClose
|
||||||
});
|
});
|
||||||
|
|
||||||
await later();
|
await later();
|
||||||
@ -26,6 +28,7 @@ test('notify disappear', async () => {
|
|||||||
|
|
||||||
await later(20);
|
await later(20);
|
||||||
expect(notify.$el.outerHTML).toMatchSnapshot();
|
expect(notify.$el.outerHTML).toMatchSnapshot();
|
||||||
|
expect(onClose).toHaveBeenCalledTimes(1);
|
||||||
|
|
||||||
Notify({
|
Notify({
|
||||||
message: 'text2',
|
message: 'text2',
|
||||||
|
@ -59,3 +59,4 @@ export default {
|
|||||||
| background | 背景颜色 | `String` | `#f44` | 1.4.7 |
|
| background | 背景颜色 | `String` | `#f44` | 1.4.7 |
|
||||||
| className | 自定义类名 | `String | Array | Object` | - | 1.6.0 |
|
| className | 自定义类名 | `String | Array | Object` | - | 1.6.0 |
|
||||||
| onClick | 点击时的回调函数 | `Function` | - | 2.0.0 |
|
| onClick | 点击时的回调函数 | `Function` | - | 2.0.0 |
|
||||||
|
| onClose | 关闭时的回调函数 | `Function` | - | 2.0.0 |
|
||||||
|
1
types/notify.d.ts
vendored
1
types/notify.d.ts
vendored
@ -9,6 +9,7 @@ export type NotifyOptions = {
|
|||||||
duration?: number;
|
duration?: number;
|
||||||
className?: any;
|
className?: any;
|
||||||
background?: string;
|
background?: string;
|
||||||
|
onClose?: (() => void) | null;
|
||||||
onClick?: ((event: Event) => void) | null;
|
onClick?: ((event: Event) => void) | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user