primevue-mirror/components/galleria/GalleriaContent.vue

145 lines
5.3 KiB
Vue
Raw Normal View History

2022-09-06 12:03:37 +00:00
<template>
2022-09-14 11:26:01 +00:00
<div v-if="$attrs.value && $attrs.value.length > 0" :id="id" :class="galleriaClass" :style="$attrs.containerStyle">
<button v-if="$attrs.fullScreen" v-ripple type="button" class="p-galleria-close p-link" @click="$emit('mask-hide')">
2022-09-06 12:03:37 +00:00
<span class="p-galleria-close-icon pi pi-times"></span>
</button>
<div v-if="$attrs.templates && $attrs.templates['header']" class="p-galleria-header">
<component :is="$attrs.templates['header']" />
</div>
<div class="p-galleria-content">
2022-09-14 11:26:01 +00:00
<GalleriaItem
v-model:activeIndex="activeIndex"
v-model:slideShowActive="slideShowActive"
:value="$attrs.value"
:circular="$attrs.circular"
:templates="$attrs.templates"
:showIndicators="$attrs.showIndicators"
:changeItemOnIndicatorHover="$attrs.changeItemOnIndicatorHover"
:showItemNavigators="$attrs.showItemNavigators"
:autoPlay="$attrs.autoPlay"
@start-slideshow="startSlideShow"
@stop-slideshow="stopSlideShow"
/>
2022-09-06 12:03:37 +00:00
2022-09-14 11:26:01 +00:00
<GalleriaThumbnails
v-if="$attrs.showThumbnails"
v-model:activeIndex="activeIndex"
v-model:slideShowActive="slideShowActive"
:containerId="id"
:value="$attrs.value"
:templates="$attrs.templates"
:numVisible="numVisible"
:responsiveOptions="$attrs.responsiveOptions"
:circular="$attrs.circular"
:isVertical="isVertical()"
:contentHeight="$attrs.verticalThumbnailViewPortHeight"
:showThumbnailNavigators="$attrs.showThumbnailNavigators"
@stop-slideshow="stopSlideShow"
/>
2022-09-06 12:03:37 +00:00
</div>
<div v-if="$attrs.templates && $attrs.templates['footer']" class="p-galleria-footer">
<component :is="$attrs.templates['footer']" />
</div>
</div>
</template>
<script>
2022-09-14 11:26:01 +00:00
import { UniqueComponentId } from 'primevue/utils';
2022-09-06 12:03:37 +00:00
import GalleriaItem from './GalleriaItem.vue';
import GalleriaThumbnails from './GalleriaThumbnails.vue';
import GalleriaItemSlot from './GalleriaItemSlot.vue';
import Ripple from 'primevue/ripple';
export default {
name: 'GalleriaContent',
inheritAttrs: false,
interval: null,
emits: ['activeitem-change', 'mask-hide'],
data() {
return {
id: this.$attrs.id || UniqueComponentId(),
activeIndex: this.$attrs.activeIndex,
numVisible: this.$attrs.numVisible,
slideShowActive: false
2022-09-14 11:26:01 +00:00
};
2022-09-06 12:03:37 +00:00
},
watch: {
2022-09-14 11:26:01 +00:00
'$attrs.value': function (newVal) {
2022-09-06 12:03:37 +00:00
if (newVal && newVal.length < this.numVisible) {
this.numVisible = newVal.length;
}
},
2022-09-14 11:26:01 +00:00
'$attrs.activeIndex': function (newVal) {
2022-09-06 12:03:37 +00:00
this.activeIndex = newVal;
},
2022-09-14 11:26:01 +00:00
'$attrs.numVisible': function (newVal) {
2022-09-06 12:03:37 +00:00
this.numVisible = newVal;
}
},
updated() {
this.$emit('activeitem-change', this.activeIndex);
},
beforeUnmount() {
2022-09-14 11:26:01 +00:00
if (this.slideShowActive) {
this.stopSlideShow();
}
},
2022-09-06 12:03:37 +00:00
methods: {
isAutoPlayActive() {
return this.slideShowActive;
},
startSlideShow() {
this.interval = setInterval(() => {
2022-09-14 11:26:01 +00:00
let activeIndex = this.$attrs.circular && this.$attrs.value.length - 1 === this.activeIndex ? 0 : this.activeIndex + 1;
2022-09-06 12:03:37 +00:00
this.activeIndex = activeIndex;
}, this.$attrs.transitionInterval);
this.slideShowActive = true;
},
stopSlideShow() {
if (this.interval) {
clearInterval(this.interval);
}
this.slideShowActive = false;
},
getPositionClass(preClassName, position) {
const positions = ['top', 'left', 'bottom', 'right'];
2022-09-14 11:26:01 +00:00
const pos = positions.find((item) => item === position);
2022-09-06 12:03:37 +00:00
return pos ? `${preClassName}-${pos}` : '';
},
isVertical() {
return this.$attrs.thumbnailsPosition === 'left' || this.$attrs.thumbnailsPosition === 'right';
}
},
computed: {
galleriaClass() {
const thumbnailsPosClass = this.$attrs.showThumbnails && this.getPositionClass('p-galleria-thumbnails', this.$attrs.thumbnailsPosition);
const indicatorPosClass = this.$attrs.showIndicators && this.getPositionClass('p-galleria-indicators', this.$attrs.indicatorsPosition);
2022-09-14 11:26:01 +00:00
return [
'p-galleria p-component',
{
'p-galleria-fullscreen': this.$attrs.fullScreen,
'p-galleria-indicator-onitem': this.$attrs.showIndicatorsOnItem,
'p-galleria-item-nav-onhover': this.$attrs.showItemNavigatorsOnHover && !this.$attrs.fullScreen
},
thumbnailsPosClass,
indicatorPosClass,
this.$attrs.containerClass
];
2022-09-06 12:03:37 +00:00
}
},
components: {
2022-09-14 11:26:01 +00:00
GalleriaItem: GalleriaItem,
GalleriaThumbnails: GalleriaThumbnails,
GalleriaItemSlot: GalleriaItemSlot
2022-09-06 12:03:37 +00:00
},
directives: {
2022-09-14 11:26:01 +00:00
ripple: Ripple
2022-09-06 12:03:37 +00:00
}
2022-09-14 11:26:01 +00:00
};
2022-09-06 12:03:37 +00:00
</script>