primevue-mirror/components/lib/galleria/Galleria.vue

206 lines
5.4 KiB
Vue
Raw Normal View History

2022-09-06 12:03:37 +00:00
<template>
<Portal v-if="fullScreen">
2023-05-31 22:28:41 +00:00
<div v-if="containerVisible" :ref="maskRef" :class="cx('mask')" :role="fullScreen ? 'dialog' : 'region'" :aria-modal="fullScreen ? 'true' : undefined" v-bind="ptm('mask')">
2022-09-06 12:03:37 +00:00
<transition name="p-galleria" @before-enter="onBeforeEnter" @enter="onEnter" @before-leave="onBeforeLeave" @after-leave="onAfterLeave" appear>
2023-05-31 22:28:41 +00:00
<GalleriaContent v-if="visible" :ref="containerRef" v-focustrap @mask-hide="maskHide" :templates="$slots" @activeitem-change="onActiveItemChange" :pt="pt" :unstyled="unstyled" v-bind="$props" />
2022-09-06 12:03:37 +00:00
</transition>
</div>
</Portal>
2023-05-31 22:28:41 +00:00
<GalleriaContent v-else :templates="$slots" @activeitem-change="onActiveItemChange" :pt="pt" :unstyled="unstyled" v-bind="$props" />
2022-09-06 12:03:37 +00:00
</template>
<script>
2023-05-31 22:28:41 +00:00
import BaseGalleria from './BaseGalleria.vue';
2022-12-08 11:04:25 +00:00
import FocusTrap from 'primevue/focustrap';
2022-09-06 12:03:37 +00:00
import Portal from 'primevue/portal';
2022-12-08 11:04:25 +00:00
import { DomHandler, ZIndexUtils } from 'primevue/utils';
import GalleriaContent from './GalleriaContent.vue';
2022-09-06 12:03:37 +00:00
export default {
name: 'Galleria',
2023-05-31 22:28:41 +00:00
extends: BaseGalleria,
2022-09-06 12:03:37 +00:00
inheritAttrs: false,
emits: ['update:activeIndex', 'update:visible'],
props: {
id: {
type: String,
default: null
},
2022-09-14 11:26:01 +00:00
value: {
2022-09-06 12:03:37 +00:00
type: Array,
default: null
},
activeIndex: {
type: Number,
default: 0
},
fullScreen: {
type: Boolean,
default: false
},
visible: {
type: Boolean,
default: false
},
numVisible: {
2022-09-14 11:26:01 +00:00
type: Number,
default: 3
},
2022-09-06 12:03:37 +00:00
responsiveOptions: {
type: Array,
default: null
},
showItemNavigators: {
type: Boolean,
default: false
},
showThumbnailNavigators: {
type: Boolean,
default: true
},
showItemNavigatorsOnHover: {
type: Boolean,
default: false
},
changeItemOnIndicatorHover: {
type: Boolean,
default: false
},
circular: {
type: Boolean,
default: false
},
autoPlay: {
type: Boolean,
default: false
},
transitionInterval: {
2022-09-14 11:26:01 +00:00
type: Number,
default: 4000
},
2022-09-06 12:03:37 +00:00
showThumbnails: {
type: Boolean,
default: true
},
thumbnailsPosition: {
2022-09-14 11:26:01 +00:00
type: String,
default: 'bottom'
},
2022-09-06 12:03:37 +00:00
verticalThumbnailViewPortHeight: {
2022-09-14 11:26:01 +00:00
type: String,
default: '300px'
},
2022-09-06 12:03:37 +00:00
showIndicators: {
type: Boolean,
default: false
},
showIndicatorsOnItem: {
type: Boolean,
default: false
},
indicatorsPosition: {
2022-09-14 11:26:01 +00:00
type: String,
default: 'bottom'
},
2022-09-06 12:03:37 +00:00
baseZIndex: {
2022-09-14 11:26:01 +00:00
type: Number,
default: 0
2022-09-06 12:03:37 +00:00
},
maskClass: {
type: String,
default: null
},
2022-12-08 11:04:25 +00:00
containerStyle: {
type: null,
default: null
},
containerClass: {
type: null,
default: null
},
containerProps: {
type: null,
default: null
},
prevButtonProps: {
type: null,
default: null
},
nextButtonProps: {
type: null,
default: null
}
2022-09-06 12:03:37 +00:00
},
container: null,
mask: null,
data() {
return {
containerVisible: this.visible
2022-09-14 11:26:01 +00:00
};
2022-09-06 12:03:37 +00:00
},
updated() {
if (this.fullScreen && this.visible) {
this.containerVisible = this.visible;
}
},
beforeUnmount() {
if (this.fullScreen) {
DomHandler.removeClass(document.body, 'p-overflow-hidden');
}
this.mask = null;
2022-09-14 11:26:01 +00:00
2022-09-06 12:03:37 +00:00
if (this.container) {
ZIndexUtils.clear(this.container);
this.container = null;
}
},
methods: {
onBeforeEnter(el) {
ZIndexUtils.set('modal', el, this.baseZIndex || this.$primevue.config.zIndex.modal);
},
onEnter(el) {
this.mask.style.zIndex = String(parseInt(el.style.zIndex, 10) - 1);
DomHandler.addClass(document.body, 'p-overflow-hidden');
2022-12-08 11:04:25 +00:00
this.focus();
2022-09-06 12:03:37 +00:00
},
onBeforeLeave() {
DomHandler.addClass(this.mask, 'p-component-overlay-leave');
},
onAfterLeave(el) {
ZIndexUtils.clear(el);
this.containerVisible = false;
DomHandler.removeClass(document.body, 'p-overflow-hidden');
},
onActiveItemChange(index) {
if (this.activeIndex !== index) {
this.$emit('update:activeIndex', index);
}
},
maskHide() {
this.$emit('update:visible', false);
},
containerRef(el) {
this.container = el;
},
maskRef(el) {
this.mask = el;
2022-12-08 11:04:25 +00:00
},
focus() {
let focusTarget = this.container.$el.querySelector('[autofocus]');
if (focusTarget) {
focusTarget.focus();
}
2022-09-06 12:03:37 +00:00
}
},
components: {
2022-09-14 11:26:01 +00:00
GalleriaContent: GalleriaContent,
Portal: Portal
2022-12-08 11:04:25 +00:00
},
directives: {
focustrap: FocusTrap
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>