/
modal.vue
65 lines (58 loc) · 1.25 KB
/
modal.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<template>
<component :is="Teleport" to="html">
<transition name="fade-shrink-in" appear>
<div v-if="state" class="modal" @click="state = false">
<div class="content" @click.stop>
<slot></slot>
</div>
</div>
</transition>
</component>
</template>
<script lang="ts" setup>
import { Teleport as teleport_, type TeleportProps, type VNodeProps, ref, watch } from 'vue';
const props = defineProps({
modelValue: {
type: Boolean,
default: false,
},
});
const emit = defineEmits(['update:modelValue']);
const state = ref(props.modelValue);
watch(state, value => {
emit('update:modelValue', value);
});
watch(
() => props.modelValue,
value => {
state.value = value;
},
);
// https://github.com/vuejs/core/issues/2855
const Teleport = teleport_ as {
new (): {
$props: VNodeProps & TeleportProps;
};
};
</script>
<style lang="less" scoped>
.modal {
z-index: 20;
background-color: rgb(0 0 0 / 45.9%);
position: fixed;
top: 0;
left: 0;
bottom: 0;
right: 0;
display: flex;
justify-content: center;
align-items: center;
.content {
display: inline-block;
background-color: var(--cl-white);
max-width: min(95%, 800px);
max-height: 90%;
overflow: auto;
}
}
</style>