103 lines
3.0 KiB
Vue
103 lines
3.0 KiB
Vue
<template>
|
|
<Teleport to="body">
|
|
<Transition
|
|
enter-active-class="transition duration-200 ease-out"
|
|
enter-from-class="opacity-0"
|
|
enter-to-class="opacity-100"
|
|
leave-active-class="transition duration-150 ease-in"
|
|
leave-from-class="opacity-100"
|
|
leave-to-class="opacity-0"
|
|
>
|
|
<div
|
|
v-if="modelValue"
|
|
class="fixed inset-0 z-50 flex items-center justify-center p-4 bg-stone-950/60 backdrop-blur-sm"
|
|
dir="rtl"
|
|
@click.self="onBackdropClick"
|
|
>
|
|
<div
|
|
class="bg-white dark:bg-stone-900 rounded-3xl border border-stone-200 dark:border-stone-800 shadow-2xl w-full max-h-[90vh] overflow-hidden flex flex-col"
|
|
:class="sizeClass"
|
|
>
|
|
<!-- Modal Header -->
|
|
<div class="px-6 py-4 border-b border-stone-100 dark:border-stone-800 flex items-center justify-between">
|
|
<div class="space-y-0.5">
|
|
<h3 class="text-base font-bold text-stone-900 dark:text-white">{{ title }}</h3>
|
|
<p v-if="description" class="text-xs text-stone-500 dark:text-stone-400">{{ description }}</p>
|
|
</div>
|
|
<button
|
|
type="button"
|
|
class="w-8 h-8 rounded-xl text-stone-400 hover:text-stone-700 dark:hover:text-stone-200 hover:bg-stone-100 dark:hover:bg-stone-800 flex items-center justify-center transition"
|
|
@click="close"
|
|
>
|
|
<UIcon name="i-lucide-x" class="w-5 h-5" />
|
|
</button>
|
|
</div>
|
|
|
|
<!-- Modal Body -->
|
|
<div class="p-6 overflow-y-auto flex-1 space-y-4">
|
|
<slot />
|
|
</div>
|
|
|
|
<!-- Modal Footer -->
|
|
<div v-if="$slots.footer" class="px-6 py-3.5 bg-stone-50/70 dark:bg-stone-800/40 border-t border-stone-100 dark:border-stone-800 flex items-center justify-end gap-2">
|
|
<slot name="footer" :close="close" />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</Transition>
|
|
</Teleport>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { computed, watch } from 'vue'
|
|
|
|
const props = withDefaults(defineProps<{
|
|
modelValue: boolean
|
|
title?: string
|
|
description?: string
|
|
size?: 'sm' | 'md' | 'lg' | 'xl' | '2xl'
|
|
dismissible?: boolean
|
|
}>(), {
|
|
modelValue: false,
|
|
title: 'پنجره پیام',
|
|
description: '',
|
|
size: 'md',
|
|
dismissible: true
|
|
})
|
|
|
|
const emit = defineEmits(['update:modelValue', 'close'])
|
|
|
|
const sizeClass = computed(() => {
|
|
switch (props.size) {
|
|
case 'sm': return 'max-w-sm'
|
|
case 'lg': return 'max-w-2xl'
|
|
case 'xl': return 'max-w-4xl'
|
|
case '2xl': return 'max-w-5xl'
|
|
case 'md':
|
|
default: return 'max-w-lg'
|
|
}
|
|
})
|
|
|
|
const close = () => {
|
|
emit('update:modelValue', false)
|
|
emit('close')
|
|
}
|
|
|
|
const onBackdropClick = () => {
|
|
if (props.dismissible) {
|
|
close()
|
|
}
|
|
}
|
|
|
|
// بستن با کلید ESC
|
|
watch(() => props.modelValue, (isOpen) => {
|
|
if (import.meta.client) {
|
|
if (isOpen) {
|
|
document.body.classList.add('overflow-hidden')
|
|
} else {
|
|
document.body.classList.remove('overflow-hidden')
|
|
}
|
|
}
|
|
})
|
|
</script>
|