primevue-mirror/doc/galleria/ControlledDoc.vue

193 lines
6.0 KiB
Vue
Raw Normal View History

2023-02-28 08:29:30 +00:00
<template>
<DocSectionText v-bind="$attrs">
<p>Galleria can be controlled programmatically using a binding to <i>activeIndex</i>.</p>
</DocSectionText>
2023-10-04 09:32:01 +00:00
<div class="card">
<div class="mb-3">
2023-02-28 08:29:30 +00:00
<Button icon="pi pi-minus" @click="prev" />
2023-03-03 12:15:20 +00:00
<Button icon="pi pi-plus" @click="next" severity="secondary" class="ml-2" />
2023-02-28 08:29:30 +00:00
</div>
<Galleria v-model:activeIndex="activeIndex" :value="images" :responsiveOptions="responsiveOptions" :numVisible="5" containerStyle="max-width: 640px">
<template #item="slotProps">
<img :src="slotProps.item.itemImageSrc" :alt="slotProps.item.alt" style="width: 100%" />
</template>
<template #thumbnail="slotProps">
<img :src="slotProps.item.thumbnailImageSrc" :alt="slotProps.item.alt" />
</template>
</Galleria>
</div>
<DocSectionCode :code="code" :service="['PhotoService']" />
</template>
<script>
import { PhotoService } from '@/service/PhotoService';
export default {
data() {
return {
images: null,
activeIndex: 2,
responsiveOptions: [
{
breakpoint: '991px',
numVisible: 4
},
{
breakpoint: '767px',
numVisible: 3
},
{
breakpoint: '575px',
numVisible: 1
}
],
code: {
2023-09-22 12:54:14 +00:00
basic: `
<div>
2023-02-28 08:29:30 +00:00
<Button icon="pi pi-minus" @click="prev" />
2023-03-03 12:15:20 +00:00
<Button icon="pi pi-plus" @click="next" severity="secondary" class="ml-2" />
2023-02-28 08:29:30 +00:00
</div>
<Galleria v-model:activeIndex="activeIndex" :value="images" :responsiveOptions="responsiveOptions" :numVisible="5" containerStyle="max-width: 640px">
<template #item="slotProps">
<img :src="slotProps.item.itemImageSrc" :alt="slotProps.item.alt" style="width: 100%" />
</template>
<template #thumbnail="slotProps">
<img :src="slotProps.item.thumbnailImageSrc" :alt="slotProps.item.alt" />
</template>
</Galleria>`,
2023-09-22 12:54:14 +00:00
options: `
<template>
2023-10-04 09:32:01 +00:00
<div class="card">
<div class="mb-3">
2023-02-28 08:29:30 +00:00
<Button icon="pi pi-minus" @click="prev" />
2023-03-03 12:15:20 +00:00
<Button icon="pi pi-plus" @click="next" severity="secondary" class="ml-2" />
2023-02-28 08:29:30 +00:00
</div>
<Galleria v-model:activeIndex="activeIndex" :value="images" :responsiveOptions="responsiveOptions" :numVisible="5" containerStyle="max-width: 640px">
<template #item="slotProps">
<img :src="slotProps.item.itemImageSrc" :alt="slotProps.item.alt" style="width: 100%" />
</template>
<template #thumbnail="slotProps">
<img :src="slotProps.item.thumbnailImageSrc" :alt="slotProps.item.alt" />
</template>
</Galleria>
</div>
</template>
<script>
import { PhotoService } from '@/service/PhotoService';
export default {
data() {
return {
images: null,
activeIndex: 2,
responsiveOptions: [
{
breakpoint: '991px',
numVisible: 4
},
{
breakpoint: '767px',
numVisible: 3
},
{
breakpoint: '575px',
numVisible: 1
}
]
};
},
mounted() {
PhotoService.getImages().then((data) => (this.images = data));
},
methods: {
next() {
2023-08-18 11:49:38 +00:00
this.activeIndex = this.activeIndex === this.images.length - 1 ? this.images.length - 1 : this.activeIndex + 1;
2023-02-28 08:29:30 +00:00
},
prev() {
2023-08-18 11:49:38 +00:00
this.activeIndex = this.activeIndex === 0 ? 0 : this.activeIndex - 1;
2023-02-28 08:29:30 +00:00
}
}
};
<\/script>`,
2023-09-22 12:54:14 +00:00
composition: `
<template>
2023-10-04 09:32:01 +00:00
<div class="card">
<div class="mb-3">
2023-02-28 08:29:30 +00:00
<Button icon="pi pi-minus" @click="prev" />
2023-03-03 12:15:20 +00:00
<Button icon="pi pi-plus" @click="next" severity="secondary" class="ml-2" />
2023-02-28 08:29:30 +00:00
</div>
<Galleria v-model:activeIndex="activeIndex" :value="images" :responsiveOptions="responsiveOptions" :numVisible="5" containerStyle="max-width: 640px">
<template #item="slotProps">
<img :src="slotProps.item.itemImageSrc" :alt="slotProps.item.alt" style="width: 100%" />
</template>
<template #thumbnail="slotProps">
<img :src="slotProps.item.thumbnailImageSrc" :alt="slotProps.item.alt" />
</template>
</Galleria>
</div>
</template>
<script setup>
import { ref, onMounted } from "vue";
import { PhotoService } from '@/service/PhotoService';
onMounted(() => {
PhotoService.getImages().then((data) => (images.value = data));
});
const images = ref();
const activeIndex = ref(2);
const responsiveOptions = ref([
{
breakpoint: '991px',
numVisible: 4
},
{
breakpoint: '767px',
numVisible: 3
},
{
breakpoint: '575px',
numVisible: 1
}
]);
const next = () => {
2023-08-18 11:49:38 +00:00
activeIndex.value = activeIndex.value === images.value.length - 1 ? images.value.length - 1 : activeIndex.value + 1;
2023-02-28 08:29:30 +00:00
};
const prev = () => {
2023-08-18 11:49:38 +00:00
activeIndex.value = activeIndex.value === 0 ? 0 : activeIndex.value - 1;
2023-02-28 08:29:30 +00:00
};
<\/script>`,
data: `
/* PhotoService */
{
itemImageSrc: 'https://primefaces.org/cdn/primevue/images/galleria/galleria1.jpg',
thumbnailImageSrc: 'https://primefaces.org/cdn/primevue/images/galleria/galleria1s.jpg',
alt: 'Description for Image 1',
title: 'Title 1'
},
...
`
}
};
},
mounted() {
PhotoService.getImages().then((data) => (this.images = data));
},
methods: {
next() {
2023-08-18 11:49:38 +00:00
this.activeIndex = this.activeIndex === this.images.length - 1 ? this.images.length - 1 : this.activeIndex + 1;
2023-02-28 08:29:30 +00:00
},
prev() {
2023-08-18 11:49:38 +00:00
this.activeIndex = this.activeIndex === 0 ? 0 : this.activeIndex - 1;
2023-02-28 08:29:30 +00:00
}
}
};
</script>