gamebrary/src/components/Modal.vue

178 lines
3 KiB
Vue
Raw Normal View History

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