11<script setup lang="ts">
22const props = defineProps <{
33 modalTitle: string
4- whenReadyOnly? : boolean
54}>()
65
7- const emit = defineEmits <{
8- (e : ' opened' ): void
9- (e : ' closed' ): void
10- }>()
11-
12- const dialogRef = ref <HTMLDialogElement >()
13- const isReady = ref (false )
6+ const dialogRef = useTemplateRef (' dialogRef' )
147
158const modalTitleId = computed (() => {
169 const id = getCurrentInstance ()?.attrs .id
@@ -21,25 +14,8 @@ function handleModalClose() {
2114 dialogRef .value ?.close ()
2215}
2316
24- function handleTransitionEnd(e : TransitionEvent ) {
25- if (e .target !== dialogRef .value ) return
26- if (e .propertyName !== ' opacity' ) return
27- if (! dialogRef .value ?.matches (' :modal' )) return
28-
29- isReady .value = true
30- emit (' opened' )
31- }
32-
33- function handleCloseEvent() {
34- isReady .value = false
35- emit (' closed' )
36- }
37-
3817defineExpose ({
39- showModal : () => {
40- isReady .value = false
41- dialogRef .value ?.showModal ()
42- },
18+ showModal : () => dialogRef .value ?.showModal (),
4319 close : () => dialogRef .value ?.close (),
4420})
4521 </script >
@@ -48,14 +24,12 @@ defineExpose({
4824 <Teleport to =" body" >
4925 <dialog
5026 ref =" dialogRef"
51- @transitionend =" handleTransitionEnd"
52- @close =" handleCloseEvent"
5327 closedby =" any"
5428 class =" w-full bg-bg border border-border rounded-lg shadow-xl max-h-[90vh] overflow-y-auto overscroll-contain m-0 m-auto p-6 text-white"
55- :class =" props.whenReadyOnly ? (isReady ? 'modal-ready' : 'modal-not-ready') : ''"
5629 :aria-labelledby =" modalTitleId"
5730 v-bind =" $attrs"
5831 >
32+ <!-- Modal top header section -->
5933 <div class =" flex items-center justify-between mb-6" >
6034 <h2 :id =" modalTitleId" class =" font-mono text-lg font-medium" >
6135 {{ modalTitle }}
@@ -69,13 +43,14 @@ defineExpose({
6943 <span class =" i-carbon-close w-5 h-5" aria-hidden =" true" />
7044 </button >
7145 </div >
72-
46+ <!-- Modal body content -->
7347 <slot />
7448 </dialog >
7549 </Teleport >
7650</template >
7751
7852<style scoped>
53+ /* Backdrop styling when any of the modals are open */
7954dialog :modal::backdrop {
8055 @apply bg-black /60;
8156}
@@ -102,15 +77,4 @@ dialog:modal {
10277 opacity : 0 ;
10378 }
10479}
105-
106- /* whenReadyOnly: keep it non-visible but allow opacity transition to run */
107- .modal-not-ready :modal {
108- visibility : hidden ;
109- pointer-events : none ;
110- }
111-
112- .modal-ready :modal {
113- visibility : visible ;
114- pointer-events : auto ;
115- }
11680 </style >
0 commit comments