Files
web/components/ImageGallery/index.tsx
Bianca Widstam bed674df87 Merged in fix/SW-1128-side-peek (pull request #1031)
Fix/SW-1128/SW-1124 side peek and gallery

* fix(SW-1128): updated style and mobile design for sidepeek select hotel

* fix(SW-1128): update link sidepeek

* fix(SW-1124): fix padding gallery

* fix(SW-1128): fix sidepeek mobile design

* fix(SW-1128): fix mobile design

* fix(SW-1128): fix gallery icon caption


Approved-by: Niclas Edenvin
2024-12-05 07:39:06 +00:00

64 lines
1.6 KiB
TypeScript

"use client"
import { memo, useState } from "react"
import { useIntl } from "react-intl"
import { GalleryIcon } from "@/components/Icons"
import Image from "@/components/Image"
import Lightbox from "@/components/Lightbox"
import Caption from "../TempDesignSystem/Text/Caption"
import styles from "./imageGallery.module.css"
import type { ImageGalleryProps } from "@/types/components/imageGallery"
function ImageGallery({
images,
title,
fill,
height = 280,
}: ImageGalleryProps) {
const intl = useIntl()
const [lightboxIsOpen, setLightboxIsOpen] = useState(false)
const [imageError, setImageError] = useState(false)
const imageProps = fill ? { fill } : { height, width: height * 1.5 }
if (!images || images.length === 0 || imageError) {
return <div className={styles.imagePlaceholder} />
}
return (
<>
<div
className={styles.triggerArea}
role="button"
onClick={() => setLightboxIsOpen(true)}
aria-label={intl.formatMessage({ id: "Open image gallery" })}
>
<Image
className={styles.image}
src={images[0].imageSizes.medium}
alt={images[0].metaData.altText}
onError={() => setImageError(true)}
{...imageProps}
/>
<div className={styles.imageCount}>
<GalleryIcon color="white" />
<Caption color="white" type="label">
{images.length}
</Caption>
</div>
</div>
<Lightbox
images={images}
dialogTitle={title}
isOpen={lightboxIsOpen}
onClose={() => setLightboxIsOpen(false)}
/>
</>
)
}
export default memo(ImageGallery)