11<script setup lang="ts">
2- import { Component as VueComponent } from ' vue'
2+ import { useTemplateRef , Component as VueComponent , watch } from ' vue'
33
4- defineProps <{
4+ const props = defineProps <{
55 eoa? : string
66 modalClose? : () => void
77 isVisible: boolean
88 modalContent: VueComponent
99 attrs: { [key : string ]: any }
1010}>()
11- </script >
12-
13- <style >
14- .modal-container {
15- position : fixed ;
16- top : 0 ;
17- right : 0 ;
18- bottom : 0 ;
19- left : 0 ;
20- display : flex ;
21- justify-content : center ;
22- align-items : flex-end ;
23- z-index : 10 ;
24- }
25-
26- @media (min-width : 1024px ) {
27- .modal-container {
28- align-items : center ;
29- }
30- }
3111
32- .modal-overlay {
33- position : fixed ;
34- top : 0 ;
35- right : 0 ;
36- bottom : 0 ;
37- left : 0 ;
38- background : rgba (0 , 0 , 0 , 0.6 );
39- z-index : -1 ;
40- }
41-
42- .modal-content {
43- display : flex ;
44- flex-direction : column ;
45- padding : 1rem ;
46- width : 100% ;
47- max-width : 64rem ;
48- background : white ;
49- border-top-left-radius : 0.5rem ;
50- border-top-right-radius : 0.5rem ;
51- border-bottom-left-radius : 0 ;
52- border-bottom-right-radius : 0 ;
53- box-shadow : 0 0 1rem rgba (0 , 0 , 0 , 0.2 );
54-
55- max-height : 80vh ;
56- overflow-y : auto ;
57- }
12+ const dialog = useTemplateRef (' dialog' )
5813
59- @media (min-width : 1024px ) {
60- .modal-content {
61- border-bottom-left-radius : 0.5rem ;
62- border-bottom-right-radius : 0.5rem ;
14+ watch (props , () => {
15+ if (props .isVisible ) {
16+ dialog .value ?.showModal ()
17+ } else {
18+ dialog .value ?.close ()
6319 }
64- }
20+ })
21+ </script >
6522
23+ <style >
6624.v-enter-active {
6725 transition : transform 600ms cubic-bezier (0.07 , 1.28 , 0.5 , 1 );
6826}
@@ -79,36 +37,34 @@ defineProps<{
7937 transform : translate (0 , 0 );
8038}
8139
82- html :has (#modal-container [ data-active = ' true ' ]) {
40+ html :has (dialog [ open ]) {
8341 overflow : hidden ;
8442}
8543 </style >
8644
8745<template >
8846 <div >
89- <Teleport to =" body" >
90- <div
91- id =" modal-container"
92- v-show =" isVisible"
93- class =" modal-container"
94- :data-active =" isVisible"
95- >
96- <div class =" modal-overlay" ></div >
97- <Transition >
47+ <dialog
48+ ref =" dialog"
49+ class =" fixed inset-0 flex items-center justify-center overflow-y-auto"
50+ :class =" { hidden: !isVisible }"
51+ >
52+ <div class =" fixed inset-0 bg-black/60" ></div >
53+ <Transition >
54+ <div class =" relative m-auto w-full py-4" >
9855 <component
9956 :eoa =" eoa"
10057 :modalClose =" modalClose"
10158 v-show =" isVisible"
102- class =" modal-content"
10359 :is =" modalContent"
10460 v-bind =" attrs"
10561 >
10662 <template #after :description >
10763 <slot name =" after:description" />
10864 </template >
10965 </component >
110- </Transition >
111- </div >
112- </Teleport >
66+ </div >
67+ </Transition >
68+ </dialog >
11369 </div >
11470</template >
0 commit comments