
<template>
	<div
		class="x_modal"
		:style="[this.duration ? { transitionDuration: duration + 'ms' } : '']"
		:class="{ 'x_modal-hid': !this.ready }"
	>
		<div class="x_modal-main" :class="{ 'x_modal-hid': !this.ready }">
			<slot></slot>
		</div>
		<div
			v-if="this.mask"
			class="x_modal-mask"
			:class="{ 'x_modal-hid': !this.ready }"
		></div>
	</div>
</template>

<script>
import mixin from "../mixin";
export default {
	name: mixin.prefix + "modal",
	props: {
		mask: {
			type: Boolean,
			default: true,
		},
		duration: Number,
	},
	data() {
		return {
			ready: false,
		};
	},
	mounted() {
		setTimeout(() => {
			this.ready = true;
		}, 0);
	}
};
</script>

<style lang="less" scoped>
.x_modal {
	bottom: 0;
	left: 0;
	position: fixed;
	right: 0;
	-webkit-tap-highlight-color: rgba(255, 255, 255, 0);
	top: 0;
	z-index: 1000;
	transition: opacity 0.2s ease;
	display: flex;
	justify-content: center;
	align-items: center;
	&-main {
		backface-visibility: hidden;
		position: relative;
		z-index: 1000;
		transition: opacity 0.2s ease;
	}
	&-mask {
		background-color: #000;
		bottom: 0;
		left: 0;
		opacity: 0.5;
		position: fixed;
		right: 0;
		top: 0;
		z-index: 999;
		transition: opacity 0.2s ease;
	}
	&-hid {
		opacity: 0;
	}
}
</style>

