68 lines
2.0 KiB
Vue
68 lines
2.0 KiB
Vue
<template>
|
|
<Transition
|
|
enter-active-class="transition duration-150 ease-out"
|
|
enter-from-class="opacity-0"
|
|
enter-to-class="opacity-100"
|
|
leave-active-class="transition duration-100 ease-in"
|
|
leave-from-class="opacity-100"
|
|
leave-to-class="opacity-0"
|
|
>
|
|
<div
|
|
v-if="popup?.config"
|
|
class="fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4 backdrop-blur-[2px]"
|
|
@click="closeOutside"
|
|
>
|
|
<div
|
|
class="flex max-h-[calc(100vh-4rem)] w-full flex-col rounded-lg border border-border bg-surface shadow-xl shadow-black/20"
|
|
:class="sizeClass"
|
|
@click.stop
|
|
>
|
|
<div class="flex shrink-0 items-center justify-between border-b border-border px-5 py-4">
|
|
<h2 class="text-sm font-semibold tracking-[0.04em] text-text">{{ popup.config.heading }}</h2>
|
|
<button type="button" class="text-muted transition-colors hover:text-text" @click="usePopup().close()">
|
|
<span class="material-symbols-outlined">close</span>
|
|
</button>
|
|
</div>
|
|
<div class="min-h-0 flex-1 overflow-y-auto p-5">
|
|
<component :is="popup.component" />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</Transition>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { computed, onMounted, onUnmounted } from 'vue'
|
|
import { PopupSize } from '~/utils/popup'
|
|
|
|
const popup = computed(() => usePopup().get())
|
|
|
|
const sizeClass = computed(() => {
|
|
switch (popup.value?.config?.size) {
|
|
case PopupSize.SMALL:
|
|
return 'max-w-md'
|
|
case PopupSize.LARGE:
|
|
return 'max-w-4xl'
|
|
case PopupSize.FULL:
|
|
return 'max-w-[calc(100vw-2rem)]'
|
|
default:
|
|
return 'max-w-xl'
|
|
}
|
|
})
|
|
|
|
function closeOutside() {
|
|
if (popup.value?.config?.closeOnOverlayClick) {
|
|
usePopup().close()
|
|
}
|
|
}
|
|
|
|
function handleKeydown(event: KeyboardEvent) {
|
|
if (event.key === 'Escape') {
|
|
usePopup().close()
|
|
}
|
|
}
|
|
|
|
onMounted(() => document.addEventListener('keydown', handleKeydown))
|
|
onUnmounted(() => document.removeEventListener('keydown', handleKeydown))
|
|
</script>
|