Skip to content

Commit 0718c6a

Browse files
committed
chore: use new style of defining props with defaults
1 parent bc6f42f commit 0718c6a

File tree

1 file changed

+29
-32
lines changed

1 file changed

+29
-32
lines changed

adminforth/spa/src/afcl/Dialog.vue

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -63,32 +63,31 @@ import { Modal } from 'flowbite';
6363
const modalEl = ref(null);
6464
const modal: Ref<Modal|null> = ref(null);
6565
66-
const props = defineProps({
67-
header: {
68-
type: String,
69-
default: '',
70-
},
71-
headerCloseButton: {
72-
type: Boolean,
73-
default: true,
74-
},
75-
buttons: {
76-
type: Array,
77-
default: () => [{ label: 'Close', onclick: (dialog) => dialog.hide(), type: '' }],
78-
},
79-
clickToCloseOutside: {
80-
type: Boolean,
81-
default: true,
82-
},
83-
beforeCloseFunction: {
84-
type: Function,
85-
default: null,
86-
},
87-
beforeOpenFunction: {
88-
type: Function,
89-
default: null,
90-
},
91-
});
66+
interface DialogButton {
67+
label: string
68+
onclick: (dialog: any) => void
69+
type?: string
70+
}
71+
72+
interface DialogProps {
73+
header?: string
74+
headerCloseButton?: boolean
75+
buttons?: DialogButton[]
76+
clickToCloseOutside?: boolean
77+
beforeCloseFunction?: (() => void | Promise<void>) | null
78+
beforeOpenFunction?: (() => void | Promise<void>) | null
79+
}
80+
81+
const props = withDefaults(defineProps<DialogProps>(), {
82+
header: '',
83+
headerCloseButton: true,
84+
buttons: () => [
85+
{ label: 'Close', onclick: (dialog: any) => dialog.hide(), type: '' },
86+
],
87+
clickToCloseOutside: true,
88+
beforeCloseFunction: null,
89+
beforeOpenFunction: null,
90+
})
9291
9392
onMounted(async () => {
9493
//await one tick when all is mounted
@@ -97,16 +96,14 @@ onMounted(async () => {
9796
modalEl.value,
9897
{
9998
backdrop: props.clickToCloseOutside ? 'dynamic' : 'static',
100-
onHide: () => {
99+
onHide: async () => {
101100
if (props.beforeCloseFunction) {
102-
props.beforeCloseFunction(modal);
103-
return;
101+
await props.beforeCloseFunction();
104102
}
105103
},
106-
onShow: () => {
104+
onShow: async () => {
107105
if (props.beforeOpenFunction) {
108-
props.beforeOpenFunction(modal);
109-
return;
106+
await props.beforeOpenFunction();
110107
}
111108
},
112109
}

0 commit comments

Comments
 (0)