diff --git a/src/app/(site)/[locale]/projects/ermek-serkebayev/page.tsx b/src/app/(site)/[locale]/projects/ermek-serkebayev/page.tsx index 253d144..f2fabb2 100644 --- a/src/app/(site)/[locale]/projects/ermek-serkebayev/page.tsx +++ b/src/app/(site)/[locale]/projects/ermek-serkebayev/page.tsx @@ -1,6 +1,7 @@ import { loadLegal } from '@/lib/content' import { BookLink } from '@/components/BookLink' import { BookWhere } from '@/components/BookWhere' +import { PhotoGallery } from '@/components/PhotoGallery' import Image from 'next/image' import Link from 'next/link' import { notFound } from 'next/navigation' @@ -12,6 +13,7 @@ import { bookUrl } from '@/lib/home-model' export const dynamic = 'force-dynamic' +const photos = [1, 2, 3, 4].map(n => ({ src: `/books/serkebayev/photo-${n}.jpg`, alt: `PHOTO ${n}` })) const path = '/projects/ermek-serkebayev' export async function generateMetadata({ params }: { params: Promise<{ locale: string }> }) { @@ -43,9 +45,7 @@ export default async function BookProject({ params }: { params: Promise<{ locale {t.book.gallery} - - {[1, 2, 3, 4].map(n => )} - + ({ ...p, alt: p.alt.replace("PHOTO", t.book.photo) }))} t={t.book} /> diff --git a/src/components/PhotoGallery.tsx b/src/components/PhotoGallery.tsx new file mode 100644 index 0000000..d8efd27 --- /dev/null +++ b/src/components/PhotoGallery.tsx @@ -0,0 +1,41 @@ +'use client' +import Image from 'next/image' +import { useCallback, useEffect, useState } from 'react' + +type Photo = { src: string; alt: string } +type Labels = { photoClose: string; photoPrev: string; photoNext: string } + +export function PhotoGallery({ photos, t }: { photos: Photo[]; t: Labels }) { + const [open, setOpen] = useState(null) + const count = photos.length + const step = useCallback((d: number) => setOpen(i => (i === null ? i : (i + d + count) % count)), [count]) + useEffect(() => { + if (open === null) return + const onKey = (e: KeyboardEvent) => { + if (e.key === 'Escape') setOpen(null) + else if (e.key === 'ArrowRight') step(1) + else if (e.key === 'ArrowLeft') step(-1) + } + window.addEventListener('keydown', onKey) + return () => window.removeEventListener('keydown', onKey) + }, [open, step]) + if (count === 0) return null + const btn = 'absolute flex h-11 w-11 items-center justify-center rounded-full bg-paper text-2xl text-graphite' + return <> + + {photos.map((p, i) => + setOpen(i)} className="block aspect-square w-full overflow-hidden" aria-label={p.alt}> + + + )} + + {open !== null && setOpen(null)}> + e.stopPropagation()} className="h-auto max-h-[90vh] w-auto max-w-full object-contain" /> + setOpen(null)} className={`${btn} right-4 top-4`}>× + {count > 1 && <> + { e.stopPropagation(); step(-1) }} className={`${btn} left-3 top-1/2 -translate-y-1/2`}>‹ + { e.stopPropagation(); step(1) }} className={`${btn} right-3 top-1/2 -translate-y-1/2`}>› + >} + } + > +} diff --git a/src/i18n/en.ts b/src/i18n/en.ts index a999406..33c188c 100644 --- a/src/i18n/en.ts +++ b/src/i18n/en.ts @@ -95,6 +95,9 @@ export const en: Dict = { }, "cover": "Cover", "photo": "Photo", + "photoClose": "Close", + "photoPrev": "Previous photo", + "photoNext": "Next photo", "role": "The foundation’s role" }, footer: 'All rights reserved.', diff --git a/src/i18n/kk.ts b/src/i18n/kk.ts index 6c1f3c0..e75e635 100644 --- a/src/i18n/kk.ts +++ b/src/i18n/kk.ts @@ -95,6 +95,9 @@ export const kk: Dict = { }, "cover": "Мұқаба", "photo": "Фото", + "photoClose": "Жабу", + "photoPrev": "Алдыңғы фото", + "photoNext": "Келесі фото", "role": "Қордың рөлі" }, footer: 'Барлық құқықтар қорғалған.', diff --git a/src/i18n/ru.ts b/src/i18n/ru.ts index 1a7291f..2fbd2b1 100644 --- a/src/i18n/ru.ts +++ b/src/i18n/ru.ts @@ -95,6 +95,9 @@ export const ru: Dict = { }, "cover": "Обложка", "photo": "Фото", + "photoClose": "Закрыть", + "photoPrev": "Предыдущее фото", + "photoNext": "Следующее фото", "role": "Роль фонда" }, footer: 'Все права защищены.', diff --git a/src/i18n/types.ts b/src/i18n/types.ts index 506135f..1e599f9 100644 --- a/src/i18n/types.ts +++ b/src/i18n/types.ts @@ -13,7 +13,7 @@ export type Dict = { mission: { title: string; text: string; missing: string } directions: { title: string; items: { title: string; text: string }[] } projects: { title: string; more: string } - book: { title: string; author: string; paragraphs: string[]; get: string; getNote: string; buy: { intro: string; platforms: string[]; storesIntro: string; stores: string[]; note: string } | null; cover: string; photo: string; role: string; translationReview: string; gallery: string; additions: string[] } + book: { title: string; author: string; paragraphs: string[]; get: string; getNote: string; buy: { intro: string; platforms: string[]; storesIntro: string; stores: string[]; note: string } | null; cover: string; photo: string; photoClose: string; photoPrev: string; photoNext: string; role: string; translationReview: string; gallery: string; additions: string[] } news: { title: string; news: string; event: string } collaboration: { title: string; text: string; write: string; instagram: string } contacts: { title: string; description: string; lead: string; emailLabel: string; phoneLabel: string; addressLabel: string; socialsLabel: string }