Skip to content

Commit 3adbf0b

Browse files
Michael.KryvoruchkoMichael.Kryvoruchko
authored andcommitted
feat: make option to change closeDelay for plugin
1 parent dfb9c65 commit 3adbf0b

File tree

2 files changed

+29
-25
lines changed

2 files changed

+29
-25
lines changed

src/plugin.ts

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,6 @@ import type {
66
} from './types/Plugin'
77

88
const dialogs = shallowReactive<IDialogItem[]>([])
9-
const $dialog: IDialog = {
10-
dialogs,
11-
12-
addDialog: ({ component, props }) => {
13-
dialogs.push({
14-
component,
15-
id: Date.now() + Math.random(),
16-
17-
props: reactive({
18-
modelValue: true,
19-
...props,
20-
}),
21-
})
22-
},
23-
24-
removeDialog: (index) => {
25-
const dialog = dialogs[index]
26-
dialog.props.modelValue = false
27-
setTimeout(() => {
28-
dialogs.splice(index, 1)
29-
}, 150)
30-
},
31-
}
329

3310
export const errorLogger = {
3411
pluginIsNotInitialized(): void {
@@ -73,7 +50,33 @@ export const dialogInjectionFallback: IDialog = {
7350
* .mount('#app')
7451
*/
7552
export const plugin: Plugin = {
76-
install: (app) => {
53+
install: (app, options) => {
54+
const defaultCloseDelay = options?.closeDelay ?? 150
55+
56+
const $dialog: IDialog = {
57+
dialogs,
58+
59+
addDialog: ({ component, props }) => {
60+
dialogs.push({
61+
component,
62+
id: Date.now() + Math.random(),
63+
64+
props: reactive({
65+
modelValue: true,
66+
...props,
67+
}),
68+
})
69+
},
70+
71+
removeDialog: (index, closeDelay) => {
72+
const dialog = dialogs[index]
73+
dialog.props.modelValue = false
74+
setTimeout(() => {
75+
dialogs.splice(index, 1)
76+
}, closeDelay ?? defaultCloseDelay)
77+
},
78+
}
79+
7780
app.provide(dialogInjectionKey, $dialog)
7881
app.config.globalProperties.$dialog = $dialog
7982
},

src/types/Plugin.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ type DialogAddMethod = <T>(params: {
1616
}) => void
1717

1818
type DialogRemoveMethod = (
19-
index: number
19+
index: number,
20+
closeDelay?: number
2021
) => void
2122

2223
interface IDialogMethods {

0 commit comments

Comments
 (0)