adminforth 2.22.0-next.28 → 2.22.0-next.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/spa/src/afcl/Modal.vue +30 -67
- package/package.json +1 -1
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div
|
|
3
3
|
v-if="$slots.trigger"
|
|
4
|
-
@click="
|
|
4
|
+
@click="toggleModal()" class="inline-flex items-center cursor-pointer w-full"
|
|
5
5
|
>
|
|
6
6
|
<slot name="trigger"></slot>
|
|
7
7
|
</div>
|
|
8
8
|
<Teleport to="body">
|
|
9
|
-
|
|
10
|
-
<div v-bind="$attrs" class="relative p-4 max-h-full">
|
|
9
|
+
<div v-show="isModalOpen" v-if="!removeFromDom" @click="backdropClick" v-bind="$attrs" class="bg-black/50 overflow-y-auto overflow-x-hidden fixed top-0 right-0 left-0 z-50 justify-center items-center w-full md:inset-0 h-1rem max-h-full flex" >
|
|
11
10
|
<!-- Modal content -->
|
|
12
11
|
<div class="relative bg-lightDialogBackgorund rounded-lg shadow-sm dark:bg-darkDialogBackgorund">
|
|
13
12
|
|
|
14
13
|
<!-- Modal body -->
|
|
15
14
|
<div class="p-4 md:p-5 space-y-4 text-lightDialogBodyText dark:text-darkDialogBodyText">
|
|
16
|
-
<slot></slot>
|
|
15
|
+
<slot ></slot>
|
|
17
16
|
</div>
|
|
18
17
|
|
|
19
18
|
<!-- Confirmation Modal -->
|
|
@@ -34,7 +33,7 @@
|
|
|
34
33
|
<Button
|
|
35
34
|
@click="
|
|
36
35
|
showConfirmationOnClose = false;
|
|
37
|
-
|
|
36
|
+
close();
|
|
38
37
|
"
|
|
39
38
|
>
|
|
40
39
|
Confirm
|
|
@@ -44,97 +43,48 @@
|
|
|
44
43
|
</div>
|
|
45
44
|
</div>
|
|
46
45
|
</div>
|
|
47
|
-
</div>
|
|
48
46
|
</Teleport>
|
|
49
47
|
</template>
|
|
50
48
|
|
|
51
49
|
<script setup lang="ts">
|
|
52
50
|
import Button from "./Button.vue";
|
|
53
51
|
import { ref, onMounted, nextTick, onUnmounted, computed, type Ref } from 'vue';
|
|
54
|
-
import { Modal } from 'flowbite';
|
|
55
52
|
|
|
56
|
-
const
|
|
57
|
-
const modal: Ref<Modal|null> = ref(null);
|
|
53
|
+
const isModalOpen = ref(false);
|
|
58
54
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
options?: Record<string, any>
|
|
63
|
-
}
|
|
55
|
+
const removeFromDom = computed(() => {
|
|
56
|
+
return props.removeFromDomOnClose && !isModalOpen.value;
|
|
57
|
+
})
|
|
64
58
|
|
|
65
59
|
interface DialogProps {
|
|
66
|
-
buttons?: DialogButton[]
|
|
67
60
|
clickToCloseOutside?: boolean
|
|
68
61
|
beforeCloseFunction?: (() => void | Promise<void>) | null
|
|
69
62
|
beforeOpenFunction?: (() => void | Promise<void>) | null
|
|
70
|
-
closable?: boolean
|
|
71
63
|
askForCloseConfirmation?: boolean
|
|
72
64
|
closeConfirmationText?: string
|
|
65
|
+
removeFromDomOnClose?: boolean
|
|
73
66
|
}
|
|
74
67
|
|
|
75
68
|
const props = withDefaults(defineProps<DialogProps>(), {
|
|
76
|
-
buttons: () => [],
|
|
77
69
|
clickToCloseOutside: true,
|
|
78
70
|
beforeCloseFunction: null,
|
|
79
71
|
beforeOpenFunction: null,
|
|
80
|
-
closable: true,
|
|
81
72
|
askForCloseConfirmation: false,
|
|
82
73
|
closeConfirmationText: 'Are you sure you want to close this dialog?',
|
|
74
|
+
removeFromDomOnClose: false,
|
|
83
75
|
})
|
|
84
76
|
|
|
85
|
-
const buttons = computed<DialogButton[]>(() => {
|
|
86
|
-
if (props.buttons && props.buttons.length > 0) {
|
|
87
|
-
return props.buttons;
|
|
88
|
-
}
|
|
89
|
-
return [
|
|
90
|
-
{
|
|
91
|
-
label: 'Close',
|
|
92
|
-
onclick: (dialog: any) => {
|
|
93
|
-
if (!props.askForCloseConfirmation) {
|
|
94
|
-
dialog.hide();
|
|
95
|
-
} else {
|
|
96
|
-
showConfirmationOnClose.value = true;
|
|
97
|
-
}
|
|
98
|
-
},
|
|
99
|
-
options: {}
|
|
100
|
-
}
|
|
101
|
-
];
|
|
102
|
-
});
|
|
103
|
-
|
|
104
77
|
const showConfirmationOnClose = ref(false);
|
|
105
|
-
onMounted(async () => {
|
|
106
|
-
//await one tick when all is mounted
|
|
107
|
-
await nextTick();
|
|
108
|
-
modal.value = new Modal(
|
|
109
|
-
modalEl.value,
|
|
110
|
-
{
|
|
111
|
-
closable: props.closable,
|
|
112
|
-
backdrop: props.clickToCloseOutside ? 'dynamic' : 'static',
|
|
113
|
-
onHide: async () => {
|
|
114
|
-
if (props.beforeCloseFunction) {
|
|
115
|
-
await props.beforeCloseFunction();
|
|
116
|
-
}
|
|
117
|
-
},
|
|
118
|
-
onShow: async () => {
|
|
119
|
-
if (props.beforeOpenFunction) {
|
|
120
|
-
await props.beforeOpenFunction();
|
|
121
|
-
}
|
|
122
|
-
},
|
|
123
|
-
}
|
|
124
|
-
);
|
|
125
|
-
})
|
|
126
78
|
|
|
127
|
-
onUnmounted(() => {
|
|
128
|
-
//destroy tooltip
|
|
129
|
-
modal.value?.destroy();
|
|
130
|
-
})
|
|
131
79
|
|
|
132
|
-
function open() {
|
|
133
|
-
|
|
80
|
+
async function open() {
|
|
81
|
+
await props.beforeOpenFunction?.();
|
|
82
|
+
isModalOpen.value = true;
|
|
134
83
|
}
|
|
135
84
|
|
|
136
|
-
function close() {
|
|
137
|
-
|
|
85
|
+
async function close() {
|
|
86
|
+
await props.beforeCloseFunction?.();
|
|
87
|
+
isModalOpen.value = false;
|
|
138
88
|
}
|
|
139
89
|
|
|
140
90
|
defineExpose({
|
|
@@ -145,11 +95,24 @@ defineExpose({
|
|
|
145
95
|
|
|
146
96
|
function tryToHideModal() {
|
|
147
97
|
if (!props.askForCloseConfirmation ) {
|
|
148
|
-
|
|
98
|
+
close();
|
|
149
99
|
} else {
|
|
150
100
|
showConfirmationOnClose.value = true;
|
|
151
101
|
}
|
|
152
102
|
}
|
|
153
103
|
|
|
104
|
+
function toggleModal() {
|
|
105
|
+
if (isModalOpen.value) {
|
|
106
|
+
tryToHideModal();
|
|
107
|
+
} else {
|
|
108
|
+
open();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function backdropClick(e: MouseEvent) {
|
|
113
|
+
if (props.clickToCloseOutside && e.target === e.currentTarget) {
|
|
114
|
+
tryToHideModal();
|
|
115
|
+
}
|
|
116
|
+
}
|
|
154
117
|
|
|
155
118
|
</script>
|