169 lines
3.6 KiB
Vue
169 lines
3.6 KiB
Vue
<script setup lang="ts">
|
|
import UiIcon from '@/components/UiIcon.vue';
|
|
import { useEscClose } from '@/lib/modal-stack';
|
|
|
|
const props = withDefaults(
|
|
defineProps<{
|
|
open: boolean;
|
|
title?: string;
|
|
width?: string;
|
|
}>(),
|
|
{ title: '', width: '440px' },
|
|
);
|
|
|
|
const emit = defineEmits<{ close: [] }>();
|
|
|
|
useEscClose(() => props.open, () => emit('close'));
|
|
</script>
|
|
|
|
<template>
|
|
<Teleport to="body">
|
|
<Transition name="ui-drawer">
|
|
<div v-if="open" class="ui-drawer-layer">
|
|
<div class="ui-drawer-dim" aria-hidden="true" />
|
|
<aside class="ui-drawer" role="dialog" aria-modal="true" :aria-label="title" :style="{ '--drawer-w': width }">
|
|
<header class="ui-drawer-head">
|
|
<slot name="header">
|
|
<h2>{{ title }}</h2>
|
|
</slot>
|
|
<button type="button" class="ui-drawer-close" aria-label="بستن (Esc)" title="بستن (Esc)" @click="emit('close')">
|
|
<UiIcon name="x" :size="18" />
|
|
</button>
|
|
</header>
|
|
<div class="ui-drawer-body">
|
|
<slot />
|
|
</div>
|
|
<footer v-if="$slots.footer" class="ui-drawer-foot">
|
|
<slot name="footer" />
|
|
</footer>
|
|
</aside>
|
|
</div>
|
|
</Transition>
|
|
</Teleport>
|
|
</template>
|
|
|
|
<style scoped>
|
|
.ui-drawer-layer {
|
|
position: fixed;
|
|
inset: 0;
|
|
/* زیر UiModal (۸۰) تا مودالهای داخل دراور رویش باز شوند */
|
|
z-index: 75;
|
|
}
|
|
|
|
.ui-drawer-dim {
|
|
position: absolute;
|
|
inset: 0;
|
|
border: 0;
|
|
padding: 0;
|
|
background: rgba(15, 23, 42, 0.28);
|
|
cursor: default;
|
|
}
|
|
|
|
/* RTL: inset-inline-start = سمت راست صفحه */
|
|
.ui-drawer {
|
|
position: absolute;
|
|
top: 0;
|
|
bottom: 0;
|
|
inset-inline-start: 0;
|
|
width: min(var(--drawer-w), 100vw);
|
|
display: flex;
|
|
flex-direction: column;
|
|
background: var(--surface);
|
|
box-shadow: var(--shadow-xl);
|
|
border-inline-end: 1px solid var(--line);
|
|
}
|
|
|
|
.ui-drawer-head {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
gap: var(--sp-3);
|
|
padding: var(--sp-4);
|
|
border-bottom: 1px solid var(--line);
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
.ui-drawer-head h2 {
|
|
margin: 0;
|
|
font-size: var(--fs-md);
|
|
font-weight: var(--fw-bold);
|
|
color: var(--ink);
|
|
}
|
|
|
|
.ui-drawer-close {
|
|
width: 36px;
|
|
height: 36px;
|
|
flex-shrink: 0;
|
|
border: 1px solid var(--line);
|
|
border-radius: var(--radius);
|
|
background: var(--surface);
|
|
color: var(--muted);
|
|
display: grid;
|
|
place-items: center;
|
|
cursor: pointer;
|
|
}
|
|
|
|
.ui-drawer-close:hover {
|
|
background: var(--surface-subtle);
|
|
color: var(--ink);
|
|
}
|
|
|
|
.ui-drawer-body {
|
|
flex: 1 1 auto;
|
|
min-height: 0;
|
|
overflow-y: auto;
|
|
overscroll-behavior: contain;
|
|
padding: var(--sp-4);
|
|
}
|
|
|
|
.ui-drawer-foot {
|
|
display: flex;
|
|
align-items: center;
|
|
flex-wrap: wrap;
|
|
gap: var(--sp-2);
|
|
padding: var(--sp-3) var(--sp-4);
|
|
border-top: 1px solid var(--line);
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
.ui-drawer-enter-active,
|
|
.ui-drawer-leave-active {
|
|
transition: opacity 0.2s ease;
|
|
}
|
|
|
|
.ui-drawer-enter-active .ui-drawer,
|
|
.ui-drawer-leave-active .ui-drawer {
|
|
transition: transform 0.22s ease;
|
|
}
|
|
|
|
.ui-drawer-enter-from,
|
|
.ui-drawer-leave-to {
|
|
opacity: 0;
|
|
}
|
|
|
|
.ui-drawer-enter-from .ui-drawer,
|
|
.ui-drawer-leave-to .ui-drawer {
|
|
transform: translateX(100%);
|
|
}
|
|
|
|
@media (max-width: 900px) {
|
|
.ui-drawer {
|
|
top: auto;
|
|
inset-inline: 0;
|
|
width: 100%;
|
|
max-height: 92dvh;
|
|
border-radius: 18px 18px 0 0;
|
|
border: 0;
|
|
}
|
|
|
|
.ui-drawer-foot {
|
|
padding-bottom: calc(var(--sp-3) + env(safe-area-inset-bottom, 0px));
|
|
}
|
|
|
|
.ui-drawer-enter-from .ui-drawer,
|
|
.ui-drawer-leave-to .ui-drawer {
|
|
transform: translateY(100%);
|
|
}
|
|
}
|
|
</style>
|