Skip to content

Commit

Permalink
feat(Notify): add jsdoc for utility functions (#12342)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan authored Oct 6, 2023
1 parent d8521b7 commit d56623e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
8 changes: 4 additions & 4 deletions packages/vant/src/notify/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ Vant exports following Notify utility functions:

| Methods | Description | Attribute | Return value |
| --- | --- | --- | --- |
| showNotify | Show notify | `NotifyOptions \| string` | notify instance |
| closeNotify | Close notify | - | `void` |
| setNotifyDefaultOptions | Set default options of all notifies | `NotifyOptions` | `void` |
| resetNotifyDefaultOptions | Reset default options of all notifies | - | `void` |
| showNotify | Display Notify at the top of the page | `NotifyOptions \| string` | Notify instance |
| closeNotify | Close the currently displayed Notify | - | `void` |
| setNotifyDefaultOptions | Modify the default configuration, affecting all `showNotify` calls | `NotifyOptions` | `void` |
| resetNotifyDefaultOptions | Reset the default configuration, affecting all `showNotify` calls | - | `void` |

### NotifyOptions

Expand Down
4 changes: 2 additions & 2 deletions packages/vant/src/notify/README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ Vant 中导出了以下 Notify 相关的辅助函数:

| 方法名 | 说明 | 参数 | 返回值 |
| --- | --- | --- | --- |
| showNotify | 展示提示 | `NotifyOptions \| string` | notify 实例 |
| closeNotify | 关闭提示 | - | `void` |
| showNotify | 在页面顶部展示 Notify | `NotifyOptions \| string` | notify 实例 |
| closeNotify | 关闭当前展示的 Notify | - | `void` |
| setNotifyDefaultOptions | 修改默认配置,影响所有的 `showNotify` 调用 | `NotifyOptions` | `void` |
| resetNotifyDefaultOptions | 重置默认配置,影响所有的 `showNotify` 调用 | - | `void` |

Expand Down
12 changes: 12 additions & 0 deletions packages/vant/src/notify/function-call.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,18 @@ const getDefaultOptions = (): NotifyOptions => ({

let currentOptions = getDefaultOptions();

/**
* Close the currently displayed Notify
*/
export const closeNotify = () => {
if (instance) {
instance.toggle(false);
}
};

/**
* Display Notify at the top of the page
*/
export function showNotify(options: NotifyMessage | NotifyOptions) {
if (!inBrowser) {
return;
Expand All @@ -61,9 +67,15 @@ export function showNotify(options: NotifyMessage | NotifyOptions) {
return instance;
}

/**
* Modify the default configuration, affecting all `showNotify` calls
*/
export const setNotifyDefaultOptions = (options: NotifyOptions) =>
extend(currentOptions, options);

/**
* Reset the default configuration, affecting all `showNotify` calls
*/
export const resetNotifyDefaultOptions = () => {
currentOptions = getDefaultOptions();
};

0 comments on commit d56623e

Please sign in to comment.