Fix modal
This commit is contained in:
parent
df2fa4c444
commit
b598a16406
|
@ -1,12 +1,12 @@
|
||||||
<template>
|
<template>
|
||||||
<Teleport to="body">
|
<Teleport to="body">
|
||||||
<transition @leave="(el,done) => motions.backdrop.leave(done)">
|
<transition @leave="onLeave">
|
||||||
<div v-if="show" v-motion="'backdrop'" :variants="motionFadeIn"
|
<div v-if="show" ref="backdrop"
|
||||||
class="fixed z-30 top-0 inset-0 px-4 sm:px-0 flex items-top justify-center bg-gray-700/75 w-full h-screen overflow-y-scroll"
|
class="fixed z-30 top-0 inset-0 px-4 sm:px-0 flex items-top justify-center bg-gray-700/75 w-full h-screen overflow-y-scroll"
|
||||||
:class="{'backdrop-blur-sm':backdropBlur}"
|
:class="{'backdrop-blur-sm':backdropBlur}"
|
||||||
@click.self="close"
|
@click.self="close"
|
||||||
>
|
>
|
||||||
<div ref="content" v-motion="'body'" :variants="motionSlideBottom"
|
<div ref="content"
|
||||||
class="self-start bg-white dark:bg-notion-dark w-full relative p-4 md:p-6 my-6 rounded-xl shadow-xl"
|
class="self-start bg-white dark:bg-notion-dark w-full relative p-4 md:p-6 my-6 rounded-xl shadow-xl"
|
||||||
:class="maxWidthClass"
|
:class="maxWidthClass"
|
||||||
>
|
>
|
||||||
|
@ -40,7 +40,7 @@
|
||||||
<slot/>
|
<slot/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-if="$scopedSlots.hasOwnProperty('footer')" class="px-6 py-4 bg-gray-100 text-right">
|
<div v-if="$slots.hasOwnProperty('footer')" class="px-6 py-4 bg-gray-100 text-right">
|
||||||
<slot name="footer"/>
|
<slot name="footer"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -50,7 +50,6 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import {useMotions} from '@vueuse/motion'
|
|
||||||
import {watch} from "vue";
|
import {watch} from "vue";
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
|
@ -98,8 +97,6 @@ onBeforeUnmount(() => {
|
||||||
document.removeEventListener('keydown', closeOnEscape)
|
document.removeEventListener('keydown', closeOnEscape)
|
||||||
})
|
})
|
||||||
|
|
||||||
const motions = useMotions()
|
|
||||||
|
|
||||||
const maxWidthClass = computed(() => {
|
const maxWidthClass = computed(() => {
|
||||||
return {
|
return {
|
||||||
sm: 'sm:max-w-sm',
|
sm: 'sm:max-w-sm',
|
||||||
|
@ -110,8 +107,7 @@ const maxWidthClass = computed(() => {
|
||||||
}[props.maxWidth]
|
}[props.maxWidth]
|
||||||
})
|
})
|
||||||
|
|
||||||
const motionFadeIn = computed(() => {
|
const motionFadeIn = {
|
||||||
return {
|
|
||||||
initial: {
|
initial: {
|
||||||
opacity: 0,
|
opacity: 0,
|
||||||
transition: {
|
transition: {
|
||||||
|
@ -127,10 +123,8 @@ const motionFadeIn = computed(() => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
|
||||||
const motionSlideBottom = computed(() => {
|
const motionSlideBottom = {
|
||||||
return {
|
|
||||||
initial: {
|
initial: {
|
||||||
y: 150,
|
y: 150,
|
||||||
opacity: 0,
|
opacity: 0,
|
||||||
|
@ -149,23 +143,30 @@ const motionSlideBottom = computed(() => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
|
||||||
watch(() => props.show, (newVal, oldVal) => {
|
const onLeave = (el, done) => {
|
||||||
if (newVal !== oldVal) {
|
contentMotion.value.leave(()=>{})
|
||||||
if (newVal) {
|
backdropMotion.value.leave(done)
|
||||||
motions.body.apply('enter')
|
|
||||||
motions.backdrop.apply('enter')
|
|
||||||
} else {
|
|
||||||
motions.body.apply('initial')
|
|
||||||
motions.backdrop.apply('initial')
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
const close = () => {
|
const close = () => {
|
||||||
if (props.closeable) {
|
if (props.closeable) {
|
||||||
emits('close')
|
emits('close')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const backdrop = ref(null)
|
||||||
|
const content = ref(null)
|
||||||
|
const backdropMotion = ref(null)
|
||||||
|
const contentMotion = ref(null)
|
||||||
|
|
||||||
|
watch(() => props.show, (newVal, oldVal) => {
|
||||||
|
if (newVal) {
|
||||||
|
nextTick(() => {
|
||||||
|
backdropMotion.value = useMotion(backdrop.value, motionFadeIn)
|
||||||
|
contentMotion.value = useMotion(content.value, motionSlideBottom)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in New Issue