feat(SW-2064): Lightbox updates * chore(SW-2064): add opacity to not selected images * chore(SW-2064): set main image as the first image in thumbnail * chore(SW-2064): disable navigation buttons on first and last image * fix(SW-2064): use cx * Revert "chore(SW-2064): disable navigation buttons on first and last image" This reverts commit 9c5acd8a02b83740f35d1cfa88bfba6b006ba947. * refactor(SW-2064): create ImageCounter component * refactor(SW-2064) * chore(SW-2064): add enter keu down on main image Approved-by: Erik Tiekstra
123 lines
3.1 KiB
TypeScript
123 lines
3.1 KiB
TypeScript
"use client"
|
|
|
|
import { AnimatePresence, motion } from "motion/react"
|
|
import { useState } from "react"
|
|
import { useIntl } from "react-intl"
|
|
|
|
import Image from "../../Image"
|
|
|
|
import { IconButton } from "../../IconButton"
|
|
import { Typography } from "../../Typography"
|
|
|
|
import { LightboxImage } from "../index"
|
|
import styles from "./fullView.module.css"
|
|
import { cx } from "class-variance-authority"
|
|
import { ImageCounter } from "../../ImageCounter"
|
|
import { animationVariants, useKeyboardNavigation } from "../util"
|
|
|
|
type FullViewProps = {
|
|
image: LightboxImage
|
|
onClose: () => void
|
|
onNext: () => void
|
|
onPrev: () => void
|
|
currentIndex: number
|
|
totalImages: number
|
|
hideLabel?: boolean
|
|
}
|
|
|
|
export function FullView({
|
|
image,
|
|
onClose,
|
|
onNext,
|
|
onPrev,
|
|
currentIndex,
|
|
totalImages,
|
|
hideLabel,
|
|
}: FullViewProps) {
|
|
const intl = useIntl()
|
|
const [slideDirection, setSlideDirection] = useState<"left" | "right">("left")
|
|
|
|
function handleSwipe(offset: number) {
|
|
if (offset > 30) {
|
|
setSlideDirection("right")
|
|
onPrev()
|
|
}
|
|
if (offset < -30) {
|
|
setSlideDirection("left")
|
|
onNext()
|
|
}
|
|
}
|
|
|
|
function handleNext() {
|
|
setSlideDirection("left")
|
|
onNext()
|
|
}
|
|
function handlePrev() {
|
|
setSlideDirection("right")
|
|
onPrev()
|
|
}
|
|
useKeyboardNavigation(handlePrev, handleNext)
|
|
|
|
return (
|
|
<div className={styles.fullView}>
|
|
<IconButton
|
|
variant="Muted"
|
|
className={styles.closeButton}
|
|
onPress={onClose}
|
|
aria-label={intl.formatMessage({
|
|
id: "common.close",
|
|
defaultMessage: "Close",
|
|
})}
|
|
iconName="close"
|
|
/>
|
|
<div className={styles.header}>
|
|
<ImageCounter number={`${currentIndex + 1} / ${totalImages}`} />
|
|
</div>
|
|
<div className={styles.content}>
|
|
<AnimatePresence initial={false} custom={slideDirection}>
|
|
<motion.div
|
|
key={image.src}
|
|
custom={slideDirection}
|
|
variants={animationVariants}
|
|
initial="initial"
|
|
animate="animate"
|
|
exit="exit"
|
|
transition={{ duration: 0.3 }}
|
|
className={styles.motionContainer}
|
|
drag="x"
|
|
onDragEnd={(_e, info) => handleSwipe(info.offset.x)}
|
|
>
|
|
<div className={styles.imageWrapper}>
|
|
<Image
|
|
alt={image.alt}
|
|
fill
|
|
sizes="90vw"
|
|
src={image.src}
|
|
className={styles.image}
|
|
/>
|
|
{image.caption && !hideLabel ? (
|
|
<Typography variant="Body/Paragraph/mdRegular">
|
|
<p className={styles.caption}>{image.caption}</p>
|
|
</Typography>
|
|
) : null}
|
|
</div>
|
|
</motion.div>
|
|
</AnimatePresence>
|
|
</div>
|
|
|
|
<IconButton
|
|
variant="Muted"
|
|
onPress={handlePrev}
|
|
className={cx(styles.navigationButton, styles.prev)}
|
|
iconName="arrow_back"
|
|
/>
|
|
<IconButton
|
|
variant="Muted"
|
|
onPress={handleNext}
|
|
className={cx(styles.navigationButton, styles.next)}
|
|
iconName="arrow_forward"
|
|
/>
|
|
</div>
|
|
)
|
|
}
|