1
1
<script setup>
2
- import { computed , onMounted , onUnmounted , watch } from ' vue' ;
2
+ import { computed , onMounted , onUnmounted , ref , watch } from ' vue' ;
3
3
4
4
const props = defineProps ({
5
5
show: {
@@ -17,18 +17,27 @@ const props = defineProps({
17
17
});
18
18
19
19
const emit = defineEmits ([' close' ]);
20
+ const dialog = ref ();
21
+ const showSlot = ref (props .show );
20
22
21
23
watch (() => props .show , () => {
22
24
if (props .show ) {
23
25
document .body .style .overflow = ' hidden' ;
26
+ showSlot .value = true ;
27
+ dialog .value ? .showModal ();
24
28
} else {
25
29
document .body .style .overflow = null ;
30
+ setTimeout (() => {
31
+ dialog .value ? .close ();
32
+ showSlot .value = false ;
33
+ }, 200 );
26
34
}
27
35
});
28
36
29
37
const close = () => {
30
38
if (props .closeable ) {
31
39
emit (' close' );
40
+ e .preventDefault ();
32
41
}
33
42
};
34
43
@@ -57,35 +66,33 @@ const maxWidthClass = computed(() => {
57
66
< / script>
58
67
59
68
< template>
60
- <teleport to =" body" >
61
- <transition leave-active-class =" duration-200" >
62
- <div v-show =" show" class =" fixed inset-0 overflow-y-auto px-4 py-6 sm:px-0 z-50" scroll-region >
63
- <transition
64
- enter-active-class =" ease-out duration-300"
65
- enter-from-class =" opacity-0"
66
- enter-to-class =" opacity-100"
67
- leave-active-class =" ease-in duration-200"
68
- leave-from-class =" opacity-100"
69
- leave-to-class =" opacity-0"
70
- >
71
- <div v-show =" show" class =" fixed inset-0 transform transition-all" @click =" close" >
72
- <div class =" absolute inset-0 bg-gray-500 dark:bg-gray-900 opacity-75" />
73
- </div >
74
- </transition >
69
+ < dialog class = " z-50 m-0 min-h-full min-w-full overflow-y-auto bg-transparent backdrop:bg-transparent" ref= " dialog" >
70
+ < div class = " fixed inset-0 overflow-y-auto px-4 py-6 sm:px-0 z-50" scroll- region>
71
+ < transition
72
+ enter- active- class = " ease-out duration-300"
73
+ enter- from- class = " opacity-0"
74
+ enter- to- class = " opacity-100"
75
+ leave- active- class = " ease-in duration-200"
76
+ leave- from- class = " opacity-100"
77
+ leave- to- class = " opacity-0"
78
+ >
79
+ < div v- show= " show" class = " fixed inset-0 transform transition-all" @click= " close" >
80
+ < div class = " absolute inset-0 bg-gray-500 dark:bg-gray-900 opacity-75" / >
81
+ < / div>
82
+ < / transition>
75
83
76
- <transition
77
- enter-active-class =" ease-out duration-300"
78
- enter-from-class =" opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
79
- enter-to-class =" opacity-100 translate-y-0 sm:scale-100"
80
- leave-active-class =" ease-in duration-200"
81
- leave-from-class =" opacity-100 translate-y-0 sm:scale-100"
82
- leave-to-class =" opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
83
- >
84
- <div v-show =" show" class =" mb-6 bg-white dark:bg-gray-800 rounded-lg overflow-hidden shadow-xl transform transition-all sm:w-full sm:mx-auto" :class =" maxWidthClass" >
85
- <slot v-if =" show" />
86
- </div >
87
- </transition >
88
- </div >
89
- </transition >
90
- </teleport >
84
+ < transition
85
+ enter- active- class = " ease-out duration-300"
86
+ enter- from- class = " opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
87
+ enter- to- class = " opacity-100 translate-y-0 sm:scale-100"
88
+ leave- active- class = " ease-in duration-200"
89
+ leave- from- class = " opacity-100 translate-y-0 sm:scale-100"
90
+ leave- to- class = " opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
91
+ >
92
+ < div v- show= " show" class = " mb-6 bg-white dark:bg-gray-800 rounded-lg overflow-hidden shadow-xl transform transition-all sm:w-full sm:mx-auto" : class = " maxWidthClass" >
93
+ < slot v- if = " showSlot" / >
94
+ < / div>
95
+ < / transition>
96
+ < / div>
97
+ < / dialog>
91
98
< / template>
0 commit comments