gamebrary/src/components/Modal.vue

210 lines
4.5 KiB
Vue
Raw Normal View History

2019-02-05 07:31:40 +00:00
<template lang="html">
<div>
<div @click="open">
<slot />
</div>
2019-10-16 19:39:40 +00:00
<div :class="['overlay', { show, confirm }]" @click="close">
<div :class="['modal-content', { large, confirm }]" @click.stop>
2019-09-25 21:56:38 +00:00
<header :class="{ fixed: !title }">
<h2 v-if="title">{{ title }}</h2>
2019-10-16 19:39:40 +00:00
<button class="secondary small" @click="close">
2019-09-25 21:56:38 +00:00
<i class="fas fa-times" />
</button>
2019-02-15 21:57:11 +00:00
</header>
2019-02-18 12:48:26 +00:00
2019-10-16 19:39:40 +00:00
<main :class="{ padded }">
<span v-if="confirm && message">{{ message }}</span>
<slot name="content" v-else-if="show" />
</main>
<footer>
<button
v-if="actionText && confirm"
:class="actionButtonClass"
:disabled="actionDisabled"
@click="handleAction"
>
{{ actionText }}
</button>
<slot v-else name="footer" />
</footer>
2019-02-05 07:31:40 +00:00
</div>
</div>
</div>
</template>
<script>
export default {
props: {
actionText: String,
title: String,
message: String,
2019-10-16 19:39:40 +00:00
actionButtonClass: {
2019-02-05 07:31:40 +00:00
type: String,
2019-10-16 19:39:40 +00:00
default: 'primary',
2019-02-05 07:31:40 +00:00
},
actionDisabled: {
type: Boolean,
default: false,
},
2019-02-06 06:55:00 +00:00
large: Boolean,
2019-07-11 20:16:04 +00:00
confirm: Boolean,
2019-02-15 21:57:11 +00:00
padded: Boolean,
2019-02-05 07:31:40 +00:00
},
data() {
return {
show: false,
};
},
2019-02-22 06:14:11 +00:00
computed: {
2019-08-09 19:03:27 +00:00
routeName() {
return this.$route.name;
},
2019-02-22 06:14:11 +00:00
},
2019-08-09 19:17:43 +00:00
watch: {
routeName() {
this.close();
},
},
2019-02-05 07:31:40 +00:00
methods: {
open() {
this.show = true;
this.$emit('open');
},
handleAction() {
this.$emit('action');
this.close();
},
close() {
this.$emit('close');
this.show = false;
},
},
};
</script>
<style lang="scss" rel="stylesheet/scss" scoped>
2019-10-16 19:39:40 +00:00
@import "~styles/styles";
.overlay {
background: rgba(0, 0, 0, 0.8);
cursor: pointer;
height: 100%;
left: 0;
margin: 0;
opacity: .1;
position: fixed;
top: 0;
2019-02-05 07:31:40 +00:00
transition: all 100ms linear;
2019-10-16 19:39:40 +00:00
visibility: hidden;
width: 100%;
z-index: 1;
&.show {
visibility: visible;
transition: all 100ms linear;
opacity: 1;
}
&.confirm {
display: flex;
align-items: flex-start;
justify-content: center;
@media($small) {
align-items: flex-end;
}
}
2019-02-05 07:31:40 +00:00
}
2019-10-16 19:39:40 +00:00
.modal-content {
background: var(--modal-background);
color: var(--modal-text-color);
height: auto;
width: 500px;
max-height: calc(85vh);
max-width: 100%;
overflow: auto;
margin: $gp * 2 auto $gp;
padding: 0;
border-radius: $border-radius;
cursor: default;
display: flex;
flex-direction: column;
2019-02-16 04:45:14 +00:00
2019-07-10 23:24:04 +00:00
@media($small) {
2019-10-16 19:39:40 +00:00
border-radius: 0;
margin: 0;
height: 100%;
2019-07-10 23:24:04 +00:00
max-height: 100vh;
2019-10-16 19:39:40 +00:00
height: 100vh;
width: 100vw;
2019-02-16 04:45:14 +00:00
}
2019-02-08 06:14:02 +00:00
2019-10-16 19:39:40 +00:00
&.large {
width: 780px;
max-width: 100% !important;
@media($small) {
max-width: 90vw;
max-height: 100vh;
}
2019-02-22 06:14:11 +00:00
}
2019-02-06 06:55:00 +00:00
2019-10-16 19:39:40 +00:00
&.confirm {
2019-07-11 20:16:04 +00:00
height: auto;
2019-10-16 19:39:40 +00:00
max-width: calc(100vw - #{$gp * 4});
2019-07-11 20:16:04 +00:00
border-radius: $border-radius;
2019-10-16 19:39:40 +00:00
@media($small) {
margin-bottom: $gp * 2;
}
}
2019-09-25 21:56:38 +00:00
}
2019-10-16 19:39:40 +00:00
header {
display: flex;
2019-09-25 22:36:31 +00:00
padding: $gp;
2019-10-16 19:39:40 +00:00
z-index: 1;
align-items: center;
justify-content: space-between;
@media($small) {
right: 0;
}
&.fixed {
position: fixed;
padding: $gp;
background-color: transparent !important;
margin: 0;
z-index: 99999999;
}
2019-07-11 20:16:04 +00:00
}
2019-02-15 22:19:37 +00:00
2019-10-16 19:39:40 +00:00
main {
&.padded {
padding: 0 $gp;
}
2019-02-21 03:09:45 +00:00
2019-10-16 19:39:40 +00:00
flex-grow: 1;
max-height: calc(100% - 144px);
overflow: auto;
2019-02-21 03:09:45 +00:00
}
2019-02-15 22:19:37 +00:00
2019-10-16 19:39:40 +00:00
footer {
padding: $gp;
margin-top: auto;
}
2019-02-05 07:31:40 +00:00
</style>