'use client' import { memo, useState } from 'react' import { Button as ButtonRAC } from 'react-aria-components' import { useIntl } from 'react-intl' import { MaterialIcon } from '../Icons/MaterialIcon' import Image from '../Image' import ImageFallback from '../ImageFallback' import Lightbox from '../Lightbox' import { Typography } from '../Typography' import styles from './imageGallery.module.css' export interface GalleryImage { src: string alt: string caption?: string | null } type ImageGalleryProps = { images?: GalleryImage[] title: string fill?: boolean width?: number height?: number sizes?: string hideLabel?: boolean imageCountPosition?: 'top' | 'bottom' } function ImageGallery({ images, title, fill, height = 280, sizes, hideLabel, imageCountPosition = 'bottom', }: ImageGalleryProps) { const intl = useIntl() const [isOpen, setIsOpen] = useState(false) const [imageError, setImageError] = useState(false) const imageProps = fill ? { fill, sizes: sizes ?? 'auto, (max-width: 400px) 100vw, (min-width: 401px) 500px', } : { height, width: height * 1.5 } if (!images?.length || imageError) { return } const firstImage = images[0] return ( <>
{firstImage.alt} setImageError(true)} {...imageProps} /> {images.length} setIsOpen(true)} aria-label={intl.formatMessage({ defaultMessage: 'Open image gallery', })} />
setIsOpen(false)} isOpen={isOpen} hideLabel={hideLabel} /> ) } export default memo(ImageGallery)