This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
Zaimki/components/Lightbox.vue

96 lines
2.3 KiB
Vue
Raw Normal View History

2021-01-06 06:21:20 -08:00
<template>
<div :class="['lightbox-wrapper', currentUrl === null ? 'd-none' : '']" ref="wrapper" @click.self="hide">
2021-01-07 14:27:28 -08:00
<div :class="['lightbox-inner', 'align-items-center']" ref="inner" @click.self="hide">
<img class="lightbox-image" :src="currentUrl" ref="image">
2021-01-06 06:21:20 -08:00
</div>
<span class="lightbox-menu">
<span class="lightbox-close fal fa-times" @click="hide"></span>
</span>
</div>
</template>
<script>
export default {
data() {
return {
currentUrl: null,
};
},
mounted() {
this.$eventHub.$on('lightbox', this.show);
if (!process.client) {
return;
}
document.body.addEventListener('keyup', e => {
if (!this.currentUrl) {
return;
}
if (e.keyCode === 27) { // ESC
this.hide();
e.preventDefault();
e.stopPropagation();
}
});
},
methods: {
show(url) {
this.currentUrl = url;
this.$refs.inner.focus();
},
hide() {
this.currentUrl = null;
this.$refs.inner.blur();
},
},
};
</script>
<style lang="scss" scoped>
@import "../assets/style";
.lightbox-wrapper {
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.75);
z-index: 10000;
padding: 2*$spacer 2*$spacer;
@include media-breakpoint-up('sm') {
padding: 2*$spacer 4*$spacer;
}
.lightbox-inner {
width: 100%;
height: 100%;
overflow-y: auto;
display: flex;
justify-content: center;
align-items: flex-start;
img {
max-width: 100%;
2021-01-07 14:27:28 -08:00
max-height: 100%;
2021-01-06 06:21:20 -08:00
}
}
.lightbox-menu {
position: absolute;
top: $spacer;
right: $spacer;
font-size: 2*$spacer;
color: $white;
}
.lightbox-close {
cursor: pointer;
}
}
</style>