primevue-mirror/src/components/galleria/GalleriaItem.vue

163 lines
5.0 KiB
Vue
Raw Normal View History

2020-03-31 13:26:04 +00:00
<template>
2020-05-14 16:16:20 +00:00
<div class="p-galleria-item-wrapper">
<div class="p-galleria-item-container">
2020-06-27 09:36:55 +00:00
<button v-if="showItemNavigators" type="button" :class="navBackwardClass" @click="navBackward($event)" :disabled="isNavBackwardDisabled()" v-ripple>
2020-05-14 16:16:20 +00:00
<span class="p-galleria-item-prev-icon pi pi-chevron-left"></span>
2020-03-31 13:26:04 +00:00
</button>
2020-05-14 16:16:20 +00:00
<div class="p-galleria-item">
2020-04-06 04:25:05 +00:00
<GalleriaItemSlot type="item" :item="activeItem" :templates="templates" />
2020-03-31 13:26:04 +00:00
</div>
2020-06-27 09:36:55 +00:00
<button v-if="showItemNavigators" type="button" :class="navForwardClass" @click="navForward($event)" :disabled="isNavForwardDisabled()" v-ripple>
2020-05-14 16:16:20 +00:00
<span class="p-galleria-item-next-icon pi pi-chevron-right"></span>
2020-03-31 13:26:04 +00:00
</button>
2020-05-14 16:16:20 +00:00
<div class="p-galleria-caption" v-if="templates['caption']">
<GalleriaItemSlot type="caption" :item="activeItem" :templates="templates" />
2020-03-31 13:26:04 +00:00
</div>
</div>
2020-05-14 16:16:20 +00:00
<ul v-if="showIndicators" class="p-galleria-indicators p-reset">
2020-03-31 13:26:04 +00:00
<li v-for="(item, index) of value" :key="`p-galleria-indicator-${index}`" tabindex="0"
@click="onIndicatorClick(index)" @mouseenter="onIndicatorMouseEnter(index)" @keydown.enter="onIndicatorKeyDown(index)"
2020-05-14 16:16:20 +00:00
:class="['p-galleria-indicator', {'p-highlight': isIndicatorItemActive(index)}]">
<button type="button" tabindex="-1" class="p-link" v-if="!templates['indicator']"></button>
2020-03-31 13:26:04 +00:00
<GalleriaItemSlot type="indicator" :index="index" :templates="templates" />
</li>
</ul>
</div>
</template>
<script>
import GalleriaItemSlot from './GalleriaItemSlot';
2020-06-27 09:36:55 +00:00
import Ripple from '../ripple/Ripple';
2020-03-31 13:26:04 +00:00
export default {
props: {
circular: {
type: Boolean,
default: false
},
2020-05-15 08:13:19 +00:00
activeIndex: {
2020-03-31 13:26:04 +00:00
type: Number,
default: 0
},
value: {
type: Array,
default: null
},
2020-05-14 16:16:20 +00:00
showItemNavigators: {
2020-03-31 13:26:04 +00:00
type: Boolean,
default: true
},
showIndicators: {
type: Boolean,
default: true
},
slideShowActive: {
type: Boolean,
default: true
},
2020-05-14 16:16:20 +00:00
changeItemOnIndicatorHover: {
2020-03-31 13:26:04 +00:00
type: Boolean,
default: true
},
autoPlay: {
type: Boolean,
default: false
},
templates: {
type: null,
default: null
}
},
mounted() {
if (this.autoPlay) {
this.$emit('startSlideShow');
}
},
methods: {
next() {
2020-05-15 08:13:19 +00:00
let nextItemIndex = this.activeIndex + 1;
let activeIndex = this.circular && this.value.length - 1 === this.activeIndex
2020-03-31 13:26:04 +00:00
? 0
: nextItemIndex;
2020-05-15 08:13:19 +00:00
this.$emit('update:activeIndex', activeIndex);
2020-03-31 13:26:04 +00:00
},
prev() {
2020-05-15 08:13:19 +00:00
let prevItemIndex = this.activeIndex !== 0 ? this.activeIndex - 1 : 0;
let activeIndex = this.circular && this.activeIndex === 0
2020-03-31 13:26:04 +00:00
? this.value.length - 1
: prevItemIndex
2020-05-15 08:13:19 +00:00
this.$emit('update:activeIndex', activeIndex);
2020-03-31 13:26:04 +00:00
},
stopSlideShow() {
if (this.slideShowActive && this.stopSlideShow) {
this.$emit('stopSlideShow');
}
},
navBackward(e) {
this.stopSlideShow();
this.prev();
if (e && e.cancelable) {
e.preventDefault();
}
},
navForward(e) {
this.stopSlideShow();
this.next();
if (e && e.cancelable) {
e.preventDefault();
}
},
onIndicatorClick(index) {
this.stopSlideShow();
2020-05-15 08:13:19 +00:00
this.$emit('update:activeIndex', index);
2020-03-31 13:26:04 +00:00
},
onIndicatorMouseEnter(index) {
2020-05-14 16:16:20 +00:00
if (this.changeItemOnIndicatorHover) {
2020-03-31 13:26:04 +00:00
this.stopSlideShow();
2020-05-15 08:13:19 +00:00
this.$emit('update:activeIndex', index);
2020-03-31 13:26:04 +00:00
}
},
onIndicatorKeyDown(index) {
this.stopSlideShow();
2020-05-15 08:13:19 +00:00
this.$emit('update:activeIndex', index);
2020-03-31 13:26:04 +00:00
},
isIndicatorItemActive(index) {
2020-05-15 08:13:19 +00:00
return this.activeIndex === index;
2020-03-31 13:26:04 +00:00
},
isNavBackwardDisabled() {
2020-05-15 08:13:19 +00:00
return !this.circular && this.activeIndex === 0;
2020-03-31 13:26:04 +00:00
},
isNavForwardDisabled() {
2020-05-15 08:13:19 +00:00
return !this.circular && this.activeIndex === (this.value.length - 1);
2020-03-31 13:26:04 +00:00
}
},
computed: {
activeItem() {
2020-05-15 08:13:19 +00:00
return this.value[this.activeIndex];
2020-03-31 13:26:04 +00:00
},
navBackwardClass() {
2020-05-14 16:16:20 +00:00
return ['p-galleria-item-prev p-galleria-item-nav p-link', {
2020-03-31 13:26:04 +00:00
'p-disabled': this.isNavBackwardDisabled()
}];
},
navForwardClass() {
2020-05-14 16:16:20 +00:00
return ['p-galleria-item-next p-galleria-item-nav p-link', {
2020-03-31 13:26:04 +00:00
'p-disabled': this.isNavForwardDisabled()
}];
}
},
components: {
'GalleriaItemSlot': GalleriaItemSlot
2020-06-27 09:36:55 +00:00
},
directives: {
'ripple': Ripple
2020-03-31 13:26:04 +00:00
}
};
</script>