Loheide-eu-mitarbeiterplatt.../resources/js/pagebuilder/blocks/Gallery.vue
Friederich Loheide bdd21a38cb
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 3m42s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 4m3s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 4m32s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 4m9s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 5m41s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 6m5s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 4m57s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 4m59s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m35s
Beiträge mit dem Baukasten der Seiten, Galerie-Großansicht mit Blättern
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-26 19:43:05 +00:00

80 lines
4.2 KiB
Vue

<script setup>
import { computed, inject, ref } from 'vue';
import { ChevronLeft, ChevronRight, ImageIcon } from '@lucide/vue';
import { Dialog, DialogContent, DialogTitle } from '@/components/ui/dialog';
const props = defineProps({ block: { type: Object, required: true } });
const editing = inject('pagebuilder:editing', false);
const columns = { 2: '@xl:grid-cols-2', 3: '@xl:grid-cols-2 @3xl:grid-cols-3', 4: '@xl:grid-cols-3 @3xl:grid-cols-4' };
const images = computed(() => props.block.data.images.map((image, index) => ({ ...image, url: props.block.props?.urls?.[index] ?? null })));
const viewable = computed(() => images.value.filter((image) => image.url));
// Großansicht mit Blättern (Pfeiltasten, Wischen, Knöpfe)
const openIndex = ref(null);
const current = computed(() => (openIndex.value === null ? null : viewable.value[openIndex.value]));
function show(image) {
openIndex.value = viewable.value.indexOf(image);
}
function step(direction) {
if (openIndex.value === null || viewable.value.length < 2) return;
openIndex.value = (openIndex.value + direction + viewable.value.length) % viewable.value.length;
}
function onKey(event) {
if (event.key === 'ArrowRight') step(1);
if (event.key === 'ArrowLeft') step(-1);
}
let touchX = null;
const touchStart = (event) => (touchX = event.touches[0].clientX);
function touchEnd(event) {
if (touchX === null) return;
const delta = event.changedTouches[0].clientX - touchX;
if (Math.abs(delta) > 50) step(delta < 0 ? 1 : -1);
touchX = null;
}
</script>
<template>
<div class="grid grid-cols-2 gap-3" :class="columns[block.data.columns]">
<figure v-for="(image, index) in images" :key="index">
<button
v-if="image.url"
type="button"
class="block w-full cursor-zoom-in overflow-hidden rounded-lg focus-visible:ring-3 focus-visible:ring-ring/40 focus-visible:outline-none"
:aria-label="`${image.alt || 'Bild'} vergrößern`"
@click="show(image)"
>
<img :src="image.url" :alt="image.alt" loading="lazy" class="aspect-[4/3] w-full object-cover transition-transform duration-300 hover:scale-[1.03]" />
</button>
<div v-else class="grid aspect-[4/3] place-items-center rounded-lg border border-dashed bg-muted text-muted-foreground"><ImageIcon class="size-6" /></div>
<figcaption v-if="image.caption" class="mt-1.5 text-xs text-muted-foreground">{{ image.caption }}</figcaption>
</figure>
<p v-if="editing && !images.length" class="col-span-full text-sm text-muted-foreground">Noch keine Bilder.</p>
</div>
<Dialog :open="current !== null" @update:open="(value) => !value && (openIndex = null)">
<DialogContent class="max-w-6xl border-0 bg-black/95 p-0 text-white sm:max-w-6xl" @keydown="onKey">
<DialogTitle class="sr-only">{{ current?.alt || 'Bild' }}</DialogTitle>
<div class="relative" @touchstart.passive="touchStart" @touchend="touchEnd">
<img v-if="current" :key="current.url" :src="current.url" :alt="current.alt" class="max-h-[82vh] w-full object-contain" />
<template v-if="viewable.length > 1">
<button type="button" class="absolute top-1/2 left-3 grid size-11 -translate-y-1/2 place-items-center rounded-full bg-black/50 text-white hover:bg-black/75" aria-label="Vorheriges Bild" @click="step(-1)">
<ChevronLeft class="size-6" />
</button>
<button type="button" class="absolute top-1/2 right-3 grid size-11 -translate-y-1/2 place-items-center rounded-full bg-black/50 text-white hover:bg-black/75" aria-label="Nächstes Bild" @click="step(1)">
<ChevronRight class="size-6" />
</button>
</template>
</div>
<div class="flex items-center justify-between gap-4 px-4 pt-1 pb-3 text-sm">
<p class="text-white/80">{{ current?.caption }}</p>
<span v-if="viewable.length > 1" class="shrink-0 text-white/60 tabular-nums">{{ openIndex + 1 }} / {{ viewable.length }}</span>
</div>
</DialogContent>
</Dialog>
</template>