Skip to content

Commit

Permalink
Fix(modal plugin): (#3345)
Browse files Browse the repository at this point in the history
- Add confirm function to vaModalPlugin
  • Loading branch information
misterpekert committed Apr 19, 2023
1 parent 6d1420c commit c687269
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions packages/ui/src/components/va-modal/plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean>((resolve) => {
createModalInstance({
message: options as string,
onOk () {
resolve(true)
},
onCancel () {
resolve(false)
},
}, app?._context)
})
}

return new Promise<boolean>((resolve) => {
createModalInstance({
...options,
onOk () {
options?.onOk?.()
resolve(true)
},
onCancel () {
options?.onCancel?.()
resolve(false)
},
}, app?._context)
})
},
})

export const VaModalPlugin = defineVuesticPlugin(() => ({
Expand Down

0 comments on commit c687269

Please sign in to comment.