2022-09-06 12:03:37 +00:00
|
|
|
<template>
|
2022-09-14 11:26:01 +00:00
|
|
|
<div class="p-galleria-item-wrapper">
|
|
|
|
<div class="p-galleria-item-container">
|
|
|
|
<button v-if="showItemNavigators" v-ripple type="button" :class="navBackwardClass" @click="navBackward($event)" :disabled="isNavBackwardDisabled()">
|
2023-04-07 06:45:02 +00:00
|
|
|
<component :is="templates.itemprevicon || 'ChevronLeftIcon'" class="p-galleria-item-prev-icon" />
|
2022-09-14 11:26:01 +00:00
|
|
|
</button>
|
2022-12-08 11:04:25 +00:00
|
|
|
<div :id="id + '_item_' + activeIndex" class="p-galleria-item" role="group" :aria-label="ariaSlideNumber(activeIndex + 1)" :aria-roledescription="ariaSlideLabel">
|
2022-09-14 11:26:01 +00:00
|
|
|
<component v-if="templates.item" :is="templates.item" :item="activeItem" />
|
|
|
|
</div>
|
|
|
|
<button v-if="showItemNavigators" v-ripple type="button" :class="navForwardClass" @click="navForward($event)" :disabled="isNavForwardDisabled()">
|
2023-04-07 06:45:02 +00:00
|
|
|
<component :is="templates.itemnexticon || 'ChevronRightIcon'" class="p-galleria-item-next-icon" />
|
2022-09-14 11:26:01 +00:00
|
|
|
</button>
|
|
|
|
<div v-if="templates['caption']" class="p-galleria-caption">
|
|
|
|
<component v-if="templates.caption" :is="templates.caption" :item="activeItem" />
|
|
|
|
</div>
|
2022-09-06 12:03:37 +00:00
|
|
|
</div>
|
2022-09-14 11:26:01 +00:00
|
|
|
<ul v-if="showIndicators" class="p-galleria-indicators p-reset">
|
|
|
|
<li
|
|
|
|
v-for="(item, index) of value"
|
|
|
|
:key="`p-galleria-indicator-${index}`"
|
2022-12-08 11:04:25 +00:00
|
|
|
:class="['p-galleria-indicator', { 'p-highlight': isIndicatorItemActive(index) }]"
|
2022-09-14 11:26:01 +00:00
|
|
|
tabindex="0"
|
2022-12-08 11:04:25 +00:00
|
|
|
:aria-label="ariaPageLabel(index + 1)"
|
|
|
|
:aria-selected="activeIndex === index"
|
|
|
|
:aria-controls="id + '_item_' + index"
|
2022-09-14 11:26:01 +00:00
|
|
|
@click="onIndicatorClick(index)"
|
|
|
|
@mouseenter="onIndicatorMouseEnter(index)"
|
2022-12-08 11:04:25 +00:00
|
|
|
@keydown="onIndicatorKeyDown($event, index)"
|
2022-09-14 11:26:01 +00:00
|
|
|
>
|
|
|
|
<button v-if="!templates['indicator']" type="button" tabindex="-1" class="p-link"></button>
|
|
|
|
<component v-if="templates.indicator" :is="templates.indicator" :index="index" />
|
|
|
|
</li>
|
|
|
|
</ul>
|
2022-09-06 12:03:37 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2023-04-06 08:21:23 +00:00
|
|
|
import ChevronLeftIcon from 'primevue/icon/chevronleft';
|
|
|
|
import ChevronRightIcon from 'primevue/icon/chevronright';
|
2022-09-06 12:03:37 +00:00
|
|
|
import Ripple from 'primevue/ripple';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'GalleriaItem',
|
|
|
|
emits: ['start-slideshow', 'stop-slideshow', 'update:activeIndex'],
|
|
|
|
props: {
|
|
|
|
circular: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
activeIndex: {
|
|
|
|
type: Number,
|
|
|
|
default: 0
|
|
|
|
},
|
|
|
|
value: {
|
|
|
|
type: Array,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
showItemNavigators: {
|
|
|
|
type: Boolean,
|
|
|
|
default: true
|
|
|
|
},
|
|
|
|
showIndicators: {
|
|
|
|
type: Boolean,
|
|
|
|
default: true
|
|
|
|
},
|
|
|
|
slideShowActive: {
|
|
|
|
type: Boolean,
|
|
|
|
default: true
|
|
|
|
},
|
|
|
|
changeItemOnIndicatorHover: {
|
|
|
|
type: Boolean,
|
|
|
|
default: true
|
|
|
|
},
|
|
|
|
autoPlay: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
templates: {
|
|
|
|
type: null,
|
|
|
|
default: null
|
2022-12-08 11:04:25 +00:00
|
|
|
},
|
|
|
|
id: {
|
|
|
|
type: String,
|
|
|
|
default: null
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
if (this.autoPlay) {
|
|
|
|
this.$emit('start-slideshow');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
next() {
|
|
|
|
let nextItemIndex = this.activeIndex + 1;
|
2022-09-14 11:26:01 +00:00
|
|
|
let activeIndex = this.circular && this.value.length - 1 === this.activeIndex ? 0 : nextItemIndex;
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
this.$emit('update:activeIndex', activeIndex);
|
|
|
|
},
|
|
|
|
prev() {
|
|
|
|
let prevItemIndex = this.activeIndex !== 0 ? this.activeIndex - 1 : 0;
|
2022-09-14 11:26:01 +00:00
|
|
|
let activeIndex = this.circular && this.activeIndex === 0 ? this.value.length - 1 : prevItemIndex;
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
this.$emit('update:activeIndex', activeIndex);
|
|
|
|
},
|
|
|
|
stopSlideShow() {
|
|
|
|
if (this.slideShowActive && this.stopSlideShow) {
|
|
|
|
this.$emit('stop-slideshow');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
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();
|
|
|
|
this.$emit('update:activeIndex', index);
|
|
|
|
},
|
|
|
|
onIndicatorMouseEnter(index) {
|
|
|
|
if (this.changeItemOnIndicatorHover) {
|
|
|
|
this.stopSlideShow();
|
|
|
|
|
|
|
|
this.$emit('update:activeIndex', index);
|
|
|
|
}
|
|
|
|
},
|
2022-12-08 11:04:25 +00:00
|
|
|
onIndicatorKeyDown(event, index) {
|
|
|
|
switch (event.code) {
|
|
|
|
case 'Enter':
|
|
|
|
case 'Space':
|
|
|
|
this.stopSlideShow();
|
2022-09-06 12:03:37 +00:00
|
|
|
|
2022-12-08 11:04:25 +00:00
|
|
|
this.$emit('update:activeIndex', index);
|
|
|
|
event.preventDefault();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'ArrowDown':
|
|
|
|
case 'ArrowUp':
|
|
|
|
event.preventDefault();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
isIndicatorItemActive(index) {
|
|
|
|
return this.activeIndex === index;
|
|
|
|
},
|
|
|
|
isNavBackwardDisabled() {
|
|
|
|
return !this.circular && this.activeIndex === 0;
|
|
|
|
},
|
|
|
|
isNavForwardDisabled() {
|
2022-09-14 11:26:01 +00:00
|
|
|
return !this.circular && this.activeIndex === this.value.length - 1;
|
2022-12-08 11:04:25 +00:00
|
|
|
},
|
|
|
|
ariaSlideNumber(value) {
|
|
|
|
return this.$primevue.config.locale.aria ? this.$primevue.config.locale.aria.slideNumber.replace(/{slideNumber}/g, value) : undefined;
|
|
|
|
},
|
|
|
|
ariaPageLabel(value) {
|
|
|
|
return this.$primevue.config.locale.aria ? this.$primevue.config.locale.aria.pageLabel.replace(/{page}/g, value) : undefined;
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
activeItem() {
|
|
|
|
return this.value[this.activeIndex];
|
|
|
|
},
|
|
|
|
navBackwardClass() {
|
2022-09-14 11:26:01 +00:00
|
|
|
return [
|
|
|
|
'p-galleria-item-prev p-galleria-item-nav p-link',
|
|
|
|
{
|
|
|
|
'p-disabled': this.isNavBackwardDisabled()
|
|
|
|
}
|
|
|
|
];
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
navForwardClass() {
|
2022-09-14 11:26:01 +00:00
|
|
|
return [
|
|
|
|
'p-galleria-item-next p-galleria-item-nav p-link',
|
|
|
|
{
|
|
|
|
'p-disabled': this.isNavForwardDisabled()
|
|
|
|
}
|
|
|
|
];
|
2022-12-08 11:04:25 +00:00
|
|
|
},
|
|
|
|
ariaSlideLabel() {
|
|
|
|
return this.$primevue.config.locale.aria ? this.$primevue.config.locale.aria.slide : undefined;
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
2023-04-06 08:21:23 +00:00
|
|
|
components: {
|
|
|
|
ChevronLeftIcon: ChevronLeftIcon,
|
|
|
|
ChevronRightIcon: ChevronRightIcon
|
|
|
|
},
|
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
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|