From 8220552f660d74ab029dda8d0c47f741890e1225 Mon Sep 17 00:00:00 2001 From: uxuip <110730129+uxuip@users.noreply.github.com> Date: Wed, 7 Sep 2022 22:43:33 +0800 Subject: [PATCH] feat(toast): option context support function (#5022) --- packages/toast/toast.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/toast/toast.ts b/packages/toast/toast.ts index 39207f8e..1488726b 100644 --- a/packages/toast/toast.ts +++ b/packages/toast/toast.ts @@ -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) {