From c687269ad8940d8c9c1a2d24fcce56468d705a3b Mon Sep 17 00:00:00 2001 From: Ilya Pekert Date: Wed, 19 Apr 2023 16:58:52 +0200 Subject: [PATCH] Fix(modal plugin): (#3345) - Add confirm function to vaModalPlugin --- .../src/components/va-modal/plugin/index.ts | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/packages/ui/src/components/va-modal/plugin/index.ts b/packages/ui/src/components/va-modal/plugin/index.ts index 6ee74e0e90..7308563b22 100644 --- a/packages/ui/src/components/va-modal/plugin/index.ts +++ b/packages/ui/src/components/va-modal/plugin/index.ts @@ -7,6 +7,35 @@ const createVaModalPlugin = (app: App) => ({ init (options: string | ModalOptions) { return createModalInstance(options, app?._context) }, + confirm (options: string | ModalOptions) { + if (typeof options === 'string') { + return new Promise((resolve) => { + createModalInstance({ + message: options as string, + onOk () { + resolve(true) + }, + onCancel () { + resolve(false) + }, + }, app?._context) + }) + } + + return new Promise((resolve) => { + createModalInstance({ + ...options, + onOk () { + options?.onOk?.() + resolve(true) + }, + onCancel () { + options?.onCancel?.() + resolve(false) + }, + }, app?._context) + }) + }, }) export const VaModalPlugin = defineVuesticPlugin(() => ({