gamebrary/src/components/Modal/Modal.vue

230 lines
4.7 KiB
Vue
Raw Normal View History

2019-02-05 07:31:40 +00:00
<template lang="html">
<div>
<div @click="open">
<slot />
</div>
<div :class="['modal', { show, popover }]" @click="close">
<i
v-if="popover"
:class="['fas fa-caret-up popover-arrow', { dark: darkModeEnabled }]"
/>
2019-02-22 06:14:11 +00:00
<div :class="['content', { large, padded, dark: darkModeEnabled }]" @click.stop>
<i class="close fas fa-times" @click="close" v-if="!popover" />
<header v-if="!popover && title">
<h2>{{ title }}</h2>
2019-02-15 21:57:11 +00:00
</header>
2019-02-18 12:48:26 +00:00
<section>
<p v-if="message">{{ message }}</p>
<slot name="content" v-if="show" />
<div :class="{ actions: actionText }">
<button class="small info" @click="close" v-if="showClose">
{{ closeText }}
</button>
<button
v-if="actionText"
class="small primary action"
:disabled="actionDisabled"
@click="handleAction"
>
{{ actionText }}
</button>
</div>
</section>
2019-02-05 07:31:40 +00:00
</div>
</div>
</div>
</template>
<script>
2019-02-22 06:14:11 +00:00
import { mapGetters } from 'vuex';
2019-02-05 07:31:40 +00:00
export default {
props: {
actionText: String,
title: String,
message: String,
showClose: {
type: Boolean,
2019-02-21 17:03:43 +00:00
default: false,
2019-02-05 07:31:40 +00:00
},
closeText: {
type: String,
default: 'Cancel',
},
actionDisabled: {
type: Boolean,
default: false,
},
popover: Boolean,
2019-02-06 06:55:00 +00:00
large: 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: {
...mapGetters(['darkModeEnabled']),
},
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-04-05 19:10:50 +00:00
@import "src/styles/styles.scss";
2019-02-05 07:31:40 +00:00
.modal {
2019-02-08 17:34:05 +00:00
color: $color-dark-gray;
2019-02-05 07:31:40 +00:00
width: 100%;
position: fixed;
2019-02-15 21:57:11 +00:00
background: rgba(0, 0, 0, 0.8);
2019-02-05 07:31:40 +00:00
z-index: 1;
top: 0;
left: 0;
display: flex;
align-items: center;
justify-content: center;
opacity: .1;
height: 100%;
transition: all 100ms linear;
visibility: hidden;
cursor: pointer;
&.popover {
background: none;
justify-content: flex-end;
align-items: baseline;
2019-03-29 05:57:17 +00:00
.content {
@media($small) {
height: auto;
}
}
}
2019-02-05 07:31:40 +00:00
&.show {
visibility: visible;
transition: all 100ms linear;
opacity: 1;
}
.content {
position: relative;
background-color: $color-white;
height: auto;
width: 380px;
max-height: calc(85vh);
max-width: 100%;
overflow: auto;
margin: 0 $gp;
padding: 0;
border-radius: $border-radius;
cursor: default;
&.dark {
2019-04-01 20:15:59 +00:00
background-color: $color-darker-gray;
color: $color-gray;
2019-04-01 20:15:59 +00:00
border: 1px solid $color-darker-gray;
}
2019-02-06 06:55:00 +00:00
&.large {
width: 780px;
2019-02-22 06:14:11 +00:00
@media($small) {
width: 100vw;
}
}
2019-02-16 04:45:14 +00:00
&.padded {
> section {
padding: 0 $gp $gp;
}
2019-02-16 04:45:14 +00:00
}
2019-02-08 06:14:02 +00:00
@media($small) {
height: auto;
margin: 0;
max-height: 100vh;
height: 100vh;
border-radius: 0;
width: 100vw;
2019-02-22 06:14:11 +00:00
}
2019-02-08 06:14:02 +00:00
}
2019-02-06 06:55:00 +00:00
&.popover .content {
max-width: 280px;
margin: $gp * 3 $gp 0;
2019-02-06 06:55:00 +00:00
}
2019-02-05 07:31:40 +00:00
}
2019-02-15 21:57:11 +00:00
header {
position: sticky;
2019-02-15 22:19:37 +00:00
display: flex;
2019-02-18 12:48:26 +00:00
top: 0;
2019-03-29 22:00:42 +00:00
padding: $gp $gp 0;
2019-02-18 12:48:26 +00:00
z-index: 2;
align-items: center;
justify-content: space-between;
min-height: 30px;
}
2019-02-15 22:19:37 +00:00
2019-02-18 12:48:26 +00:00
.close {
2019-02-21 03:09:45 +00:00
display: none;
padding: $gp;
position: absolute;
top: $gp / 4;
right: $gp / 4;
z-index: 99999;
2019-02-18 12:48:26 +00:00
color: $color-gray;
cursor: pointer;
2019-02-21 03:09:45 +00:00
@media($small) {
display: block;
}
2019-02-15 22:19:37 +00:00
}
2019-02-05 07:31:40 +00:00
.actions {
display: grid;
grid-gap: $gp;
grid-template-columns: auto auto;
}
.popover-arrow {
color: $color-white;
font-size: 25px;
position: absolute;
top: $gp * 2;
right: $gp * 1.5;
&.dark {
2019-04-01 20:15:59 +00:00
color: $color-darker-gray;
}
}
2019-02-05 07:31:40 +00:00
</style>