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,12 +17,20 @@ 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
@@ -57,35 +65,33 @@ const maxWidthClass = computed(() => {
57
65
< / script>
58
66
59
67
< 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 >
68
+ < dialog class = " z-50 m-0 min-h-full min-w-full overflow-y-auto bg-transparent backdrop:bg-transparent" ref= " dialog" >
69
+ < div class = " fixed inset-0 overflow-y-auto px-4 py-6 sm:px-0 z-50" scroll- region>
70
+ < transition
71
+ enter- active- class = " ease-out duration-300"
72
+ enter- from- class = " opacity-0"
73
+ enter- to- class = " opacity-100"
74
+ leave- active- class = " ease-in duration-200"
75
+ leave- from- class = " opacity-100"
76
+ leave- to- class = " opacity-0"
77
+ >
78
+ < div v- show= " show" class = " fixed inset-0 transform transition-all" @click= " close" >
79
+ < div class = " absolute inset-0 bg-gray-500 dark:bg-gray-900 opacity-75" / >
80
+ < / div>
81
+ < / transition>
75
82
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 >
83
+ < transition
84
+ enter- active- class = " ease-out duration-300"
85
+ enter- from- class = " opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
86
+ enter- to- class = " opacity-100 translate-y-0 sm:scale-100"
87
+ leave- active- class = " ease-in duration-200"
88
+ leave- from- class = " opacity-100 translate-y-0 sm:scale-100"
89
+ leave- to- class = " opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
90
+ >
91
+ < 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" >
92
+ < slot v- if = " showSlot" / >
93
+ < / div>
94
+ < / transition>
95
+ < / div>
96
+ < / dialog>
91
97
< / template>
0 commit comments