Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Commit

Permalink
feat: plugin image slider (#1783)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbarnsley authored Mar 7, 2020
1 parent e217ef6 commit ba1f575
Show file tree
Hide file tree
Showing 5 changed files with 303 additions and 27 deletions.
10 changes: 8 additions & 2 deletions src/renderer/components/Modal/ModalWindow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
class="ModalWindow"
:class="{
'ModalWindow--maximized': isMaximized,
'ModalWindow--minimized': !isMaximized
'ModalWindow--minimized': !isMaximized,
[modalClasses]: true
}"
@mousedown.left="onBackdropClick"
>
Expand Down Expand Up @@ -98,6 +99,11 @@ export default {
required: false,
default: false
},
modalClasses: {
type: String,
required: false,
default: ''
},
headerClasses: {
type: String,
required: false,
Expand Down Expand Up @@ -232,7 +238,7 @@ export default {
}
.ModalWindow__container__actions {
@apply absolute pin-x pin-t flex justify-end m-2 p-2;
@apply absolute pin-x pin-t flex justify-end m-2 p-2 z-10;
}
.ModalWindow--maximized .ModalWindow__container__content {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<ModalWindow
:message="$t('PAGES.PLUGIN_MANAGER.DISCLAIMER')"
header-classes="flex p-8 -mx-16 -mt-16 bg-theme-secondary-feature rounded-t-lg"
container-classes="max-w-md"
container-classes="PluginDetailsModal max-w-md"
@close="emitClose"
>
<template #header>
Expand Down Expand Up @@ -94,12 +94,6 @@
</template>

<template #default>
<div class="-mx-16 -mt-3">
<PluginSlider
:plugin="plugin"
/>
</div>

<p
class="PluginDetailsModal__description"
:class="{
Expand Down Expand Up @@ -133,6 +127,12 @@
{{ $t('MODAL_PLUGIN_DETAILS.SHOW_PERMISSIONS') }}
</a>

<div class="mt-6">
<PluginSlider
:plugin="plugin"
/>
</div>

<div class="PluginDetailsModal__stats">
<div>
<span>{{ $t('COMMON.CATEGORY') }}</span>
Expand Down Expand Up @@ -319,6 +319,12 @@ export default {
</script>

<style lang="postcss" scoped>
.PluginDetailsModal .ModalWindow__container__content {
@apply .pb-8;
}
.PluginDetailsModal .ModalWindow__container__footer--warning {
@apply .py-4;
}
.PluginDetailsModal__header__details {
@apply flex items-center mt-1 text-theme-page-text-light;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
<template>
<ModalWindow
modal-classes="PluginImageModal"
aacontainer-classes="PluginImageModal max-w-md"
@close="emitClose"
>
<div class="flex flex-col">
<div class="PluginSlider">
<div class="relative w-full h-full">
<!-- Images -->
<transition-group
:name="sliderClass"
tag="div"
class="flex flex-no-wrap h-full"
@after-leave="transitionEnd"
>
<div
v-for="imageId in [currentIndex]"
:key="imageId"
class="PluginSlider__slide"
>
<img :src="`data:image/png;base64,${images[imageId]}`">
</div>
</transition-group>
</div>

<!-- Left Button -->
<div
class="PluginSlider__left"
@click="previousImage"
>
<SvgIcon
name="caret-left"
view-box="0 0 12 12"
/>
</div>

<!-- Right Button -->
<div
class="PluginSlider__right"
@click="nextImage"
>
<SvgIcon
name="caret-right"
view-box="0 0 12 12"
/>
</div>
</div>

<div class="flex flex-inline mt-4 justify-center">
<div
v-for="page in images.length"
:key="page"
class="PluginSlider__page"
:class="{
'bg-theme-button': currentIndex + 1 !== page,
'bg-theme-button-active': currentIndex + 1 === page
}"
@click="goToPage(page)"
/>
</div>
</div>
</ModalWindow>
</template>

<script>
import { ModalWindow } from '@/components/Modal'
import SvgIcon from '@/components/SvgIcon/SvgIcon'
export default {
name: 'PluginImageModal',
components: {
ModalWindow,
SvgIcon
},
props: {
images: {
type: Array,
required: true
},
imageIndex: {
type: Number,
required: false,
default: 0
}
},
data: (vm) => ({
currentIndex: vm.imageIndex,
isTransitioning: false,
sliderClass: 'slides-right'
}),
methods: {
emitClose () {
this.$emit('close')
},
transitionEnd () {
this.isTransitioning = false
},
previousImage () {
if (this.isTransitioning) {
return
}
this.isTransitioning = true
if (this.currentIndex === 0) {
this.sliderClass = 'slides-right'
this.currentIndex = this.images.length - 1
} else {
this.sliderClass = 'slides-left'
this.currentIndex--
}
},
nextImage () {
if (this.isTransitioning) {
return
}
this.isTransitioning = true
if (this.currentIndex >= this.images.length - 1) {
this.sliderClass = 'slides-left'
this.currentIndex = 0
} else {
this.sliderClass = 'slides-right'
this.currentIndex++
}
},
goToPage (page) {
if (page < this.currentIndex + 1) {
this.sliderClass = 'slides-left'
} else if (page > this.currentIndex + 1) {
this.sliderClass = 'slides-right'
} else {
return
}
this.isTransitioning = true
this.currentIndex = page - 1
}
}
}
</script>

<style>
.PluginImageModal .ModalWindow__container__content {
@apply .p-4;
}
.PluginImageModal article {
@apply .flex .mt-0;
}
</style>

<style scoped>
.PluginSlider {
@apply .flex-1 .relative .overflow-x-hidden .select-none;
width: 640px;
height: 550px;
}
.PluginSlider__slide {
@apply .absolute .flex .flex-none .h-full .w-full .pin .overflow-hidden .justify-center;
}
.PluginSlider__slide img {
max-width: none;
height: max-content;
@apply .m-auto .max-h-full;
}
.PluginSlider__left,
.PluginSlider__right {
@apply .absolute .rounded .bg-theme-button .text-theme-button-text .flex .pin-y .my-auto .cursor-pointer .shadow;
width: 35px;
height: 35px;
}
.PluginSlider__left:hover,
.PluginSlider__right:hover {
@apply .bg-theme-button-active;
}
.PluginSlider__left {
@apply .pin-l .ml-6;
padding-right: 0.125rem;
}
.PluginSlider__right {
@apply .pin-r .mr-6;
}
.PluginSlider__left .SvgIcon,
.PluginSlider__right .SvgIcon {
@apply .m-auto;
}
.PluginSlider__page {
@apply .rounded-full .p-1 .mx-1 .cursor-pointer;
}
.slides-right-leave-active,
.slides-right-enter-active,
.slides-left-leave-active,
.slides-left-enter-active {
transition: 0.5s;
}
.slides-left-leave-to,
.slides-right-enter {
transform: translate(100%, 0);
}
.slides-left-enter,
.slides-right-leave-to {
transform: translate(-100%, 0);
}
</style>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import PluginBlacklistDisclaimerModal from './PluginBlacklistDisclaimerModal'
import PluginBlacklistModal from './PluginBlacklistModal'
import PluginDetailsModal from './PluginDetailsModal'
import PluginImageModal from './PluginImageModal'
import PluginInstallModal from './PluginInstallModal'
import PluginManageBlacklistModal from './PluginManageBlacklistModal'
import PluginPermissionsModal from './PluginPermissionsModal'
Expand All @@ -11,6 +12,7 @@ export {
PluginBlacklistDisclaimerModal,
PluginBlacklistModal,
PluginDetailsModal,
PluginImageModal,
PluginInstallModal,
PluginManageBlacklistModal,
PluginPermissionsModal,
Expand Down
Loading

0 comments on commit ba1f575

Please sign in to comment.