Newer
Older
<script setup lang="ts">
import { computed, watch } from 'vue';
import type { IModalProps } from '@interfaces/componentsProps';
import { iconsSet } from '@/common/constants/icons';
import {
convertThemeToColor,
convertThemeToSecondaryColor,
convertThemeToTextColor,
} from '../../common/helpers/common';
import type { CustomWindow } from '@interfaces/common';
const props = withDefaults(defineProps<IModalProps>(), {

Дмитрий Малюгин
committed
darknessTheme: '500',
width: '30%',
height: '30%',
headerDivider: false,
const body = document.querySelector('body')!;
const emit = defineEmits(['onClose']);
const visible = defineModel('visible', {
set(value) {
(window as CustomWindow).blockPopupActions = false;
body.style.overflow = 'auto';
watch(visible, () => {
if (visible.value) {
(window as CustomWindow).blockPopupActions = true;
body.style.overflow = 'hidden';
}
});
const themeColor = computed(() => convertThemeToColor(props.theme, props.darknessTheme));

Дмитрий Малюгин
committed
const secondaryColor = computed(() => convertThemeToSecondaryColor(props.theme, props.darknessTheme));
const color = computed(() =>
props.textColor
? convertThemeToColor(props.textColor, props.darknessTextColor)
: convertThemeToTextColor(props.theme, props.darknessTheme),
const onKeydown = (event: KeyboardEvent) => {
if (event.key === 'Escape' && visible.value) visible.value = false;
};
document.addEventListener('keydown', onKeydown);
</script>
<template>
<article>
<section
:class="[
'modalBackground',
{
@pointerdown="() => (dismissible ? (visible = false) : false)"
></section>
<section

Дмитрий Малюгин
committed
:style="`color: ${color}; background-color: ${themeColor}; width: ${width}; height: ${height}`"
:class="[
'modal',
{
modalToCenter: !position,
top: position === 'top',
toTop: position === 'topLeft' || position === 'topRight',
bottom: position === 'bottom',
toBottom: position === 'bottomLeft' || position === 'bottomRight',
left: position === 'left',
toLeft: position === 'topLeft' || position === 'bottomLeft',
right: position === 'right',
toRight: position === 'topRight' || position === 'bottomRight',
]"
>
<header class="modalHeader">
<div class="headerContent">
<slot name="header" />
<button class="buttonClose" @click.prevent="visible = false">

Дмитрий Малюгин
committed
<component :is="iconsSet[closeIcon]" :color="color" />
</button>
<div v-if="headerDivider" class="divider"></div>
</section>
</article>
</template>
<style scoped>
.modalBackground {
position: fixed;
top: -100%;
left: -100%;
width: 200vw;
height: 200vh;
background-color: rgba(0, 0, 0, 0.5);
z-index: -50;
opacity: 0;
}
.openedModalBackground {
z-index: 60;
opacity: 1;
}
.modal {
z-index: -50;
min-width: 250px;
min-height: 100px;
padding: 20px;

Дмитрий Малюгин
committed
border: 2px solid v-bind(secondaryColor);
opacity: 0;
transition: all ease-in-out 0.2s;
user-select: none;
}
.modalToCenter {
top: 50%;
left: 50%;
translate: -50% -50%;
}
.openedModal {
user-select: auto;
z-index: 9999;
opacity: 1;
}
.modalHeader {
font-size: 1.5rem;
min-height: 1.5rem;
text-align: center;
padding-right: 40px;
margin-bottom: 20px;
}
.headerContent {
font-weight: bold;
overflow: auto;
white-space: nowrap;
}
.main {
padding-right: 5px;
height: calc(100% - 45px);
overflow: auto;
}
.buttonClose {
position: absolute;
top: 20px;
right: 20px;
width: 30px;
cursor: pointer;
}

Дмитрий Малюгин
committed
background-color: v-bind(secondaryColor);
position: absolute;
left: 20px;
top: 60px;
width: calc(100% - 40px);
}
::-webkit-scrollbar-thumb {
border-radius: 5px;

Дмитрий Малюгин
committed
background-color: v-bind(secondaryColor);
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
}
.toTop {
top: 10px !important;
}
.toBottom {
bottom: 10px !important;
}
.toLeft {
left: 10px !important;
}
.toRight {
right: 10px !important;
}
.top {
top: 10px !important;
left: 50%;
translate: -50% 0;
}
.bottom {
bottom: 10px !important;
left: 50%;
translate: -50% 0;
}
.left {
top: 50%;
translate: 0 -50%;
left: 10px !important;
}
.right {
top: 50%;
translate: 0 -50%;
right: 10px !important;
}