2023-12-09 15:47:03 +01:00
|
|
|
<template>
|
2023-12-14 16:53:05 +01:00
|
|
|
<Teleport to="body">
|
2023-12-20 13:51:39 +01:00
|
|
|
<transition @leave="onLeave">
|
2024-04-15 19:39:03 +02:00
|
|
|
<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="{ 'backdrop-blur-sm': backdropBlur }"
|
|
|
|
|
@click.self="close"
|
2023-12-09 15:47:03 +01:00
|
|
|
>
|
2024-04-15 19:39:03 +02:00
|
|
|
<div
|
|
|
|
|
ref="content"
|
|
|
|
|
class="self-start bg-white dark:bg-notion-dark w-full relative my-6 rounded-xl shadow-xl"
|
|
|
|
|
:class="maxWidthClass"
|
2023-12-09 15:47:03 +01:00
|
|
|
>
|
2024-04-15 19:39:03 +02:00
|
|
|
<div
|
|
|
|
|
v-if="closeable"
|
|
|
|
|
class="absolute top-4 right-4"
|
|
|
|
|
>
|
|
|
|
|
<button
|
|
|
|
|
class="text-gray-500 hover:text-gray-900 cursor-pointer"
|
|
|
|
|
@click="close()"
|
|
|
|
|
>
|
|
|
|
|
<svg
|
|
|
|
|
class="h-6 w-6"
|
|
|
|
|
viewBox="0 0 24 24"
|
|
|
|
|
fill="none"
|
|
|
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
|
|
|
>
|
|
|
|
|
<path
|
|
|
|
|
d="M18 6L6 18M6 6L18 18"
|
|
|
|
|
stroke="currentColor"
|
|
|
|
|
stroke-width="2"
|
|
|
|
|
stroke-linecap="round"
|
|
|
|
|
stroke-linejoin="round"
|
2023-12-09 15:47:03 +01:00
|
|
|
/>
|
|
|
|
|
</svg>
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
2024-04-15 19:39:03 +02:00
|
|
|
<div
|
|
|
|
|
v-if="_has($slots, 'icon') || _has($slots, 'title')"
|
|
|
|
|
class="flex border-b pb-4"
|
|
|
|
|
:class="[
|
|
|
|
|
{
|
|
|
|
|
'flex-col sm:items-start': !compactHeader,
|
|
|
|
|
'items-center justify-center py-6 gap-x-4': compactHeader,
|
|
|
|
|
},
|
|
|
|
|
headerInnerPadding,
|
|
|
|
|
]"
|
|
|
|
|
>
|
|
|
|
|
<div
|
|
|
|
|
v-if="_has($slots, 'icon')"
|
|
|
|
|
:class="{ 'w-full mb-4 flex justify-center': !compactHeader }"
|
|
|
|
|
>
|
|
|
|
|
<div
|
|
|
|
|
class="w-14 h-14 rounded-full flex justify-center items-center"
|
|
|
|
|
:class="'bg-' + iconColor + '-100 text-' + iconColor + '-600'"
|
2023-12-09 15:47:03 +01:00
|
|
|
>
|
2024-04-15 19:39:03 +02:00
|
|
|
<slot name="icon" />
|
2023-12-09 15:47:03 +01:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2024-04-15 19:39:03 +02:00
|
|
|
<div
|
|
|
|
|
class="mt-3 text-center sm:mt-0"
|
|
|
|
|
:class="{ 'w-full': !compactHeader }"
|
|
|
|
|
>
|
|
|
|
|
<h2
|
|
|
|
|
v-if="_has($slots, 'title')"
|
|
|
|
|
class="text-2xl font-semibold text-center text-gray-900"
|
2023-12-09 15:47:03 +01:00
|
|
|
>
|
2024-04-15 19:39:03 +02:00
|
|
|
<slot name="title" />
|
2023-12-09 15:47:03 +01:00
|
|
|
</h2>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
2024-04-15 19:39:03 +02:00
|
|
|
<div
|
|
|
|
|
class="w-full"
|
|
|
|
|
:class="innerPadding"
|
|
|
|
|
>
|
|
|
|
|
<slot />
|
2023-12-09 15:47:03 +01:00
|
|
|
</div>
|
|
|
|
|
|
2024-04-15 19:39:03 +02:00
|
|
|
<div
|
|
|
|
|
v-if="_has($slots, 'footer')"
|
|
|
|
|
class="bg-gray-50 border-t rounded-b-xl text-right"
|
|
|
|
|
:class="footerInnerPadding"
|
|
|
|
|
>
|
|
|
|
|
<slot name="footer" />
|
2023-12-09 15:47:03 +01:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</transition>
|
2023-12-14 16:53:05 +01:00
|
|
|
</Teleport>
|
2023-12-09 15:47:03 +01:00
|
|
|
</template>
|
|
|
|
|
|
2023-12-19 19:42:02 +01:00
|
|
|
<script setup>
|
2024-04-15 19:39:03 +02:00
|
|
|
import { watch } from "vue"
|
|
|
|
|
import { default as _has } from "lodash/has"
|
2023-12-09 15:47:03 +01:00
|
|
|
|
2023-12-19 19:42:02 +01:00
|
|
|
const props = defineProps({
|
|
|
|
|
show: {
|
2024-04-15 19:39:03 +02:00
|
|
|
type: Boolean,
|
|
|
|
|
default: false,
|
2023-12-19 19:42:02 +01:00
|
|
|
},
|
|
|
|
|
backdropBlur: {
|
|
|
|
|
type: Boolean,
|
2024-04-15 19:39:03 +02:00
|
|
|
default: false,
|
2023-12-19 19:42:02 +01:00
|
|
|
},
|
|
|
|
|
iconColor: {
|
2024-04-15 19:39:03 +02:00
|
|
|
type: String,
|
|
|
|
|
default: "blue",
|
2023-12-09 15:47:03 +01:00
|
|
|
},
|
2023-12-19 19:42:02 +01:00
|
|
|
maxWidth: {
|
2024-04-15 19:39:03 +02:00
|
|
|
type: String,
|
|
|
|
|
default: "2xl",
|
2023-12-19 19:42:02 +01:00
|
|
|
},
|
2024-03-28 18:14:30 +01:00
|
|
|
innerPadding: {
|
2024-04-15 19:39:03 +02:00
|
|
|
type: String,
|
|
|
|
|
default: "p-6",
|
2024-03-28 18:14:30 +01:00
|
|
|
},
|
|
|
|
|
headerInnerPadding: {
|
2024-04-15 19:39:03 +02:00
|
|
|
type: String,
|
|
|
|
|
default: "p-6",
|
2024-03-28 18:14:30 +01:00
|
|
|
},
|
|
|
|
|
footerInnerPadding: {
|
2024-04-15 19:39:03 +02:00
|
|
|
type: String,
|
|
|
|
|
default: "p-6",
|
2024-03-28 18:14:30 +01:00
|
|
|
},
|
2023-12-19 19:42:02 +01:00
|
|
|
closeable: {
|
2024-04-15 19:39:03 +02:00
|
|
|
type: Boolean,
|
|
|
|
|
default: true,
|
2024-03-28 18:14:30 +01:00
|
|
|
},
|
|
|
|
|
compactHeader: {
|
|
|
|
|
default: false,
|
2024-04-15 19:39:03 +02:00
|
|
|
type: Boolean,
|
2024-03-28 18:14:30 +01:00
|
|
|
},
|
2023-12-19 19:42:02 +01:00
|
|
|
})
|
2023-12-09 15:47:03 +01:00
|
|
|
|
2024-04-15 19:39:03 +02:00
|
|
|
const emit = defineEmits(["close"])
|
2023-12-09 15:47:03 +01:00
|
|
|
|
2023-12-19 19:42:02 +01:00
|
|
|
useHead({
|
2024-03-28 18:14:30 +01:00
|
|
|
bodyAttrs: computed(() => {
|
|
|
|
|
return {
|
|
|
|
|
class: {
|
2024-04-15 19:39:03 +02:00
|
|
|
"overflow-hidden": props.show,
|
|
|
|
|
},
|
2023-12-09 15:47:03 +01:00
|
|
|
}
|
2024-04-15 19:39:03 +02:00
|
|
|
}),
|
2023-12-19 19:42:02 +01:00
|
|
|
})
|
2023-12-09 15:47:03 +01:00
|
|
|
|
2023-12-19 19:42:02 +01:00
|
|
|
const closeOnEscape = (e) => {
|
2024-04-15 19:39:03 +02:00
|
|
|
if (e.key === "Escape" && props.show) {
|
2024-01-18 12:58:12 +01:00
|
|
|
close()
|
2023-12-19 19:42:02 +01:00
|
|
|
}
|
|
|
|
|
}
|
2023-12-09 15:47:03 +01:00
|
|
|
|
2023-12-19 19:42:02 +01:00
|
|
|
onMounted(() => {
|
2024-03-28 17:59:41 +01:00
|
|
|
if (import.meta.server) return
|
2024-04-15 19:39:03 +02:00
|
|
|
document.addEventListener("keydown", closeOnEscape)
|
2023-12-25 19:57:00 +01:00
|
|
|
initMotions()
|
2023-12-19 19:42:02 +01:00
|
|
|
})
|
2023-12-09 15:47:03 +01:00
|
|
|
|
2023-12-19 19:42:02 +01:00
|
|
|
onBeforeUnmount(() => {
|
2024-03-28 17:59:41 +01:00
|
|
|
if (import.meta.server) return
|
2024-04-15 19:39:03 +02:00
|
|
|
document.removeEventListener("keydown", closeOnEscape)
|
2023-12-19 19:42:02 +01:00
|
|
|
})
|
2023-12-09 15:47:03 +01:00
|
|
|
|
2023-12-19 19:42:02 +01:00
|
|
|
const maxWidthClass = computed(() => {
|
|
|
|
|
return {
|
2024-04-15 19:39:03 +02:00
|
|
|
sm: "sm:max-w-sm",
|
|
|
|
|
md: "sm:max-w-md",
|
|
|
|
|
lg: "sm:max-w-lg",
|
|
|
|
|
xl: "sm:max-w-xl",
|
|
|
|
|
"2xl": "sm:max-w-2xl",
|
2023-12-19 19:42:02 +01:00
|
|
|
}[props.maxWidth]
|
|
|
|
|
})
|
|
|
|
|
|
2023-12-20 13:51:39 +01:00
|
|
|
const motionFadeIn = {
|
|
|
|
|
initial: {
|
|
|
|
|
opacity: 0,
|
|
|
|
|
transition: {
|
|
|
|
|
delay: 100,
|
|
|
|
|
duration: 200,
|
2024-04-15 19:39:03 +02:00
|
|
|
ease: "easeIn",
|
|
|
|
|
},
|
2023-12-20 13:51:39 +01:00
|
|
|
},
|
|
|
|
|
enter: {
|
|
|
|
|
opacity: 1,
|
|
|
|
|
transition: {
|
2024-04-15 19:39:03 +02:00
|
|
|
duration: 200,
|
|
|
|
|
},
|
|
|
|
|
},
|
2023-12-20 13:51:39 +01:00
|
|
|
}
|
2023-12-09 15:47:03 +01:00
|
|
|
|
2023-12-20 13:51:39 +01:00
|
|
|
const motionSlideBottom = {
|
|
|
|
|
initial: {
|
|
|
|
|
y: 150,
|
|
|
|
|
opacity: 0,
|
|
|
|
|
transition: {
|
2024-04-15 19:39:03 +02:00
|
|
|
ease: "easeIn",
|
|
|
|
|
duration: 200,
|
|
|
|
|
},
|
2023-12-20 13:51:39 +01:00
|
|
|
},
|
|
|
|
|
enter: {
|
|
|
|
|
y: 0,
|
|
|
|
|
opacity: 1,
|
|
|
|
|
transition: {
|
|
|
|
|
duration: 250,
|
2024-04-15 19:39:03 +02:00
|
|
|
ease: "easeOut",
|
|
|
|
|
delay: 100,
|
|
|
|
|
},
|
|
|
|
|
},
|
2023-12-20 13:51:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const onLeave = (el, done) => {
|
2024-04-15 19:39:03 +02:00
|
|
|
contentMotion.value.leave(() => {})
|
2023-12-20 13:51:39 +01:00
|
|
|
backdropMotion.value.leave(done)
|
|
|
|
|
}
|
2023-12-19 19:42:02 +01:00
|
|
|
|
|
|
|
|
const close = () => {
|
|
|
|
|
if (props.closeable) {
|
2024-04-15 19:39:03 +02:00
|
|
|
emit("close")
|
2023-12-19 19:42:02 +01:00
|
|
|
}
|
2023-12-09 15:47:03 +01:00
|
|
|
}
|
2023-12-20 13:51:39 +01:00
|
|
|
|
|
|
|
|
const backdrop = ref(null)
|
|
|
|
|
const content = ref(null)
|
|
|
|
|
const backdropMotion = ref(null)
|
|
|
|
|
const contentMotion = ref(null)
|
|
|
|
|
|
2023-12-25 19:57:00 +01:00
|
|
|
const initMotions = () => {
|
|
|
|
|
if (props.show) {
|
2023-12-20 13:51:39 +01:00
|
|
|
nextTick(() => {
|
|
|
|
|
backdropMotion.value = useMotion(backdrop.value, motionFadeIn)
|
|
|
|
|
contentMotion.value = useMotion(content.value, motionSlideBottom)
|
|
|
|
|
})
|
|
|
|
|
}
|
2023-12-25 19:57:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
watch(() => props.show, initMotions)
|
2023-12-09 15:47:03 +01:00
|
|
|
</script>
|