Profectus-Demo/src/components/system/Modal.vue

132 lines
2.3 KiB
Vue
Raw Normal View History

2021-05-22 15:29:06 -05:00
<template>
2021-07-24 17:08:52 -05:00
<teleport to="#modal-root">
2021-06-27 16:45:33 -05:00
<transition name="modal" @before-enter="setAnimating(true)" @after-leave="setAnimating(false)">
2021-07-24 17:08:52 -05:00
<div class="modal-mask" v-show="show" v-on:pointerdown.self="$emit('close')" v-bind="$attrs">
2021-06-12 00:41:25 -05:00
<div class="modal-wrapper">
<div class="modal-container">
<div class="modal-header">
2021-06-27 16:45:33 -05:00
<slot name="header" :shown="isVisible">
2021-06-12 00:41:25 -05:00
default header
</slot>
</div>
2021-07-24 17:08:52 -05:00
<div class="modal-body">
2021-06-12 00:41:25 -05:00
<branches>
2021-06-27 16:45:33 -05:00
<slot name="body" :shown="isVisible">
2021-06-12 00:41:25 -05:00
default body
</slot>
</branches>
2021-07-24 17:08:52 -05:00
</div>
2021-06-12 00:41:25 -05:00
<div class="modal-footer">
2021-06-27 16:45:33 -05:00
<slot name="footer" :shown="isVisible">
2021-06-12 00:41:25 -05:00
<div class="modal-default-footer">
<div class="modal-default-flex-grow"></div>
<button class="button modal-default-button" @click="$emit('close')">
Close
</button>
</div>
2021-06-11 23:38:16 -05:00
</slot>
2021-06-12 00:41:25 -05:00
</div>
2021-05-22 15:29:06 -05:00
</div>
</div>
</div>
2021-06-12 00:41:25 -05:00
</transition>
2021-07-24 17:08:52 -05:00
</teleport>
2021-05-22 15:29:06 -05:00
</template>
<script>
export default {
name: 'Modal',
2021-06-27 16:45:33 -05:00
data() {
return {
isAnimating: false
}
},
2021-05-22 15:29:06 -05:00
props: {
show: Boolean
2021-06-27 16:45:33 -05:00
},
2021-07-24 17:08:52 -05:00
emits: [ 'close' ],
2021-06-27 16:45:33 -05:00
computed: {
isVisible() {
return this.show || this.isAnimating;
}
},
methods: {
setAnimating(isAnimating) {
this.isAnimating = isAnimating;
}
2021-05-22 15:29:06 -05:00
}
}
</script>
<style scoped>
.modal-mask {
position: fixed;
z-index: 9998;
top: 0;
left: 0;
bottom: 0;
right: 0;
background-color: rgba(0, 0, 0, 0.5);
transition: opacity 0.3s ease;
}
.modal-wrapper {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
.modal-container {
2021-06-11 23:38:16 -05:00
width: 640px;
max-width: 95vw;
max-height: 95vh;
2021-05-22 15:29:06 -05:00
background-color: var(--background);
padding: 20px;
border-radius: 5px;
transition: all 0.3s ease;
text-align: left;
border: var(--modal-border);
2021-06-11 23:38:16 -05:00
box-sizing: border-box;
display: flex;
flex-direction: column;
}
.modal-header {
width: 100%;
2021-05-22 15:29:06 -05:00
}
.modal-body {
margin: 20px 0;
2021-06-11 23:38:16 -05:00
width: 100%;
2021-06-22 03:34:59 -05:00
overflow-y: auto;
overflow-x: hidden;
2021-06-11 23:38:16 -05:00
}
.modal-footer {
width: 100%;
2021-05-22 15:29:06 -05:00
}
.modal-default-footer {
display: flex;
}
.modal-default-flex-grow {
flex-grow: 1;
}
2021-07-24 17:08:52 -05:00
.modal-enter-from {
2021-05-22 15:29:06 -05:00
opacity: 0;
}
.modal-leave-active {
opacity: 0;
}
2021-07-24 17:08:52 -05:00
.modal-enter-from .modal-container,
2021-05-22 15:29:06 -05:00
.modal-leave-active .modal-container {
-webkit-transform: scale(1.1);
transform: scale(1.1);
}
</style>