diff --git a/src/constants.js b/src/constants.js index b46cb54..6b0ff04 100644 --- a/src/constants.js +++ b/src/constants.js @@ -47,6 +47,7 @@ export const DEFAULTS = Object.freeze({ // 高级 resetTimerOnUpdate: false, + notifyWhenHidden: false, // 国际化 locale: 'zh-CN', diff --git a/types/index.d.ts b/types/index.d.ts index e220e76..2d6d33c 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -268,12 +268,58 @@ export interface ToastConfig { onClose?: (toast: ToastInstance) => void; /** 点击回调 */ onClick?: (toast: ToastInstance) => void; + /** 更新回调 */ + onUpdate?: (toast: ToastInstance) => void; + /** 自定义渲染函数 */ + render?: (toast: ToastInstance) => string; + /** 更新时重置计时器 */ + resetTimerOnUpdate?: boolean; + /** 后台发送系统通知 */ + notifyWhenHidden?: boolean; + /** 分组名称 */ + group?: string; /** 语言 */ locale?: ToastLocale; /** 插件 */ plugins?: Array; } +/** Action Toast 按钮 */ +export interface ActionButton { + text: string; + onClick: (toast: ToastInstance) => void; + color?: string; + style?: Partial; + close?: boolean; +} + +/** 可取消的队列 */ +export interface QueueControl { + then: (onFulfilled?: (value: any) => any, onRejected?: (reason: any) => any) => Promise; + catch: (onRejected?: (reason: any) => any) => Promise; + cancel: () => void; +} + +/** 分组API */ +export interface GroupAPI { + show: (messageOrOpts: string | ToastOptions, opts?: ToastOptions) => ToastInstance; + success: (messageOrOpts: string | ToastOptions, opts?: ToastOptions) => ToastInstance; + error: (messageOrOpts: string | ToastOptions, opts?: ToastOptions) => ToastInstance; + warning: (messageOrOpts: string | ToastOptions, opts?: ToastOptions) => ToastInstance; + info: (messageOrOpts: string | ToastOptions, opts?: ToastOptions) => ToastInstance; + loading: (messageOrOpts: string | ToastOptions, opts?: ToastOptions) => LoadingControl; + action: (messageOrOpts: string | ToastOptions, actions: ActionButton[], opts?: ToastOptions) => ActionControl; + dismiss: () => void; + count: () => number; +} + +/** Action Toast 控制对象 */ +export interface ActionControl { + id: string; + toast: ToastInstance; + dismiss: () => void; +} + // Toast选项 export interface ToastOptions extends ToastConfig { /** Toast类型 */ @@ -592,11 +638,19 @@ export interface MeToast { progress(message: string, options?: ProgressOptions): ProgressControl; /** 倒计时Toast */ countdown(message: string, seconds: number, options?: CountdownOptions): CountdownControl; + /** Action Toast */ + action(message: string, actions: ActionButton[], options?: ToastOptions): ActionControl; /** 队列Toast */ - queue(messages: Array, options?: QueueOptions): Promise; + queue(messages: Array, options?: QueueOptions): QueueControl; /** 堆叠Toast */ stack(messages: Array, options?: StackOptions): void; + // 分组管理 + /** 创建分组 */ + group(name: string): GroupAPI; + /** 按组关闭 */ + dismissGroup(name: string): void; + // Toast管理 /** 查找Toast */ find(id: string): ToastInstance | undefined;