feat(toast): option context support function (#5022)

This commit is contained in:
uxuip 2022-09-07 22:43:33 +08:00 committed by GitHub
parent 06c2457513
commit 8220552f66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,15 +1,14 @@
import { isObj } from '../common/validator';
type ToastMessage = string | number;
type ToastContext = WechatMiniprogram.Component.TrivialInstance | WechatMiniprogram.Page.TrivialInstance
interface ToastOptions {
show?: boolean;
type?: string;
mask?: boolean;
zIndex?: number;
context?:
| WechatMiniprogram.Component.TrivialInstance
| WechatMiniprogram.Page.TrivialInstance;
context?: () => ToastContext | ToastContext;
position?: string;
duration?: number;
selector?: string;
@ -50,7 +49,7 @@ function Toast(toastOptions: ToastOptions | ToastMessage) {
...parseOptions(toastOptions),
} as ToastOptions;
const context = options.context || getContext();
const context = (typeof options.context === 'function' ? options.context() : options.context) || getContext();
const toast = context.selectComponent(options.selector as string);
if (!toast) {