forked from fahrPool/fahrPool
feat: add FotoGalerie component with thumbnail grid and lightbox
This commit is contained in:
parent
0a0b0b3112
commit
97ac267158
|
|
@ -0,0 +1,69 @@
|
|||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import { buttonClasses } from "@/components/ui/Button";
|
||||
import type { AuftragFoto } from "@/lib/auftraege/fotos";
|
||||
|
||||
export function FotoGalerie({ fotos }: { fotos: AuftragFoto[] }) {
|
||||
const [offenerIndex, setOffenerIndex] = useState<number | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (offenerIndex === null) return;
|
||||
function onKeyDown(event: KeyboardEvent) {
|
||||
if (event.key === "Escape") setOffenerIndex(null);
|
||||
}
|
||||
window.addEventListener("keydown", onKeyDown);
|
||||
return () => window.removeEventListener("keydown", onKeyDown);
|
||||
}, [offenerIndex]);
|
||||
|
||||
const offenesFoto = offenerIndex !== null ? fotos[offenerIndex] : null;
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="grid grid-cols-3 gap-3 sm:grid-cols-4">
|
||||
{fotos.map((foto, index) => (
|
||||
<button
|
||||
key={`${foto.position}-${index}`}
|
||||
type="button"
|
||||
onClick={() => setOffenerIndex(index)}
|
||||
className="aspect-square overflow-hidden rounded-md border border-aluminium-grey focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-performance-blue"
|
||||
>
|
||||
<img src={foto.url} alt={foto.label} className="h-full w-full object-cover" />
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{offenesFoto && (
|
||||
<div className="fixed inset-0 z-50">
|
||||
<button
|
||||
type="button"
|
||||
aria-label="Schließen"
|
||||
onClick={() => setOffenerIndex(null)}
|
||||
className="absolute inset-0 bg-black/80"
|
||||
/>
|
||||
<div className="pointer-events-none absolute inset-0 flex flex-col items-center justify-center gap-4 p-4">
|
||||
<button
|
||||
type="button"
|
||||
aria-label="Schließen"
|
||||
onClick={() => setOffenerIndex(null)}
|
||||
className="pointer-events-auto absolute right-4 top-4 flex min-h-11 min-w-11 items-center justify-center rounded-md bg-white/90 text-asphalt-grey focus-visible:outline focus-visible:outline-2 focus-visible:outline-performance-blue"
|
||||
>
|
||||
<svg viewBox="0 0 24 24" className="h-6 w-6" fill="none" stroke="currentColor" strokeWidth={2}>
|
||||
<path strokeLinecap="round" strokeLinejoin="round" d="M6 18L18 6M6 6l12 12" />
|
||||
</svg>
|
||||
</button>
|
||||
<img
|
||||
src={offenesFoto.url}
|
||||
alt={offenesFoto.label}
|
||||
className="pointer-events-none max-h-[80vh] max-w-[90vw] rounded-md object-contain"
|
||||
/>
|
||||
<p className="pointer-events-none text-white">{offenesFoto.label}</p>
|
||||
<a href={offenesFoto.downloadUrl} className={`${buttonClasses("secondary", false)} pointer-events-auto`}>
|
||||
Download
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
Loading…
Reference in New Issue