Merged in monorepo-step-1 (pull request #1080)
Migrate to a monorepo setup - step 1 * Move web to subfolder /apps/scandic-web * Yarn + transitive deps - Move to yarn - design-system package removed for now since yarn doesn't support the parameter for token (ie project currently broken) - Add missing transitive dependencies as Yarn otherwise prevents these imports - VS Code doesn't pick up TS path aliases unless you open /apps/scandic-web instead of root (will be fixed with monorepo) * Pin framer-motion to temporarily fix typing issue https://github.com/adobe/react-spectrum/issues/7494 * Pin zod to avoid typ error There seems to have been a breaking change in the types returned by zod where error is now returned as undefined instead of missing in the type. We should just handle this but to avoid merge conflicts just pin the dependency for now. * Pin react-intl version Pin version of react-intl to avoid tiny type issue where formatMessage does not accept a generic any more. This will be fixed in a future commit, but to avoid merge conflicts just pin for now. * Pin typescript version Temporarily pin version as newer versions as stricter and results in a type error. Will be fixed in future commit after merge. * Setup workspaces * Add design-system as a monorepo package * Remove unused env var DESIGN_SYSTEM_ACCESS_TOKEN * Fix husky for monorepo setup * Update netlify.toml * Add lint script to root package.json * Add stub readme * Fix react-intl formatMessage types * Test netlify.toml in root * Remove root toml * Update netlify.toml publish path * Remove package-lock.json * Update build for branch/preview builds Approved-by: Linus Flood
This commit is contained in:
committed by
Linus Flood
parent
667cab6fb6
commit
80100e7631
120
apps/scandic-web/components/Lightbox/FullView.tsx
Normal file
120
apps/scandic-web/components/Lightbox/FullView.tsx
Normal file
@@ -0,0 +1,120 @@
|
||||
"use client"
|
||||
|
||||
import { AnimatePresence, motion } from "framer-motion"
|
||||
import { useState } from "react"
|
||||
|
||||
import ArrowRightIcon from "@/components/Icons/ArrowRight"
|
||||
import CloseIcon from "@/components/Icons/Close"
|
||||
import Image from "@/components/Image"
|
||||
import Button from "@/components/TempDesignSystem/Button"
|
||||
import Body from "@/components/TempDesignSystem/Text/Body"
|
||||
import Caption from "@/components/TempDesignSystem/Text/Caption"
|
||||
|
||||
import styles from "./Lightbox.module.css"
|
||||
|
||||
import type { FullViewProps } from "@/types/components/lightbox/lightbox"
|
||||
|
||||
export default function FullView({
|
||||
image,
|
||||
onClose,
|
||||
onNext,
|
||||
onPrev,
|
||||
currentIndex,
|
||||
totalImages,
|
||||
}: FullViewProps) {
|
||||
const [animateLeft, setAnimateLeft] = useState(true)
|
||||
|
||||
function handleSwipe(offset: number) {
|
||||
if (offset > 30) onPrev()
|
||||
if (offset < -30) onNext()
|
||||
}
|
||||
|
||||
function handleNext() {
|
||||
setAnimateLeft(true)
|
||||
onNext()
|
||||
}
|
||||
|
||||
function handlePrev() {
|
||||
setAnimateLeft(false)
|
||||
onPrev()
|
||||
}
|
||||
|
||||
const variants = {
|
||||
initial: (animateLeft: boolean) => ({
|
||||
opacity: 0,
|
||||
x: animateLeft ? 300 : -300,
|
||||
}),
|
||||
animate: { opacity: 1, x: 0 },
|
||||
exit: (animateLeft: boolean) => ({
|
||||
opacity: 0,
|
||||
x: animateLeft ? -300 : 300,
|
||||
}),
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={styles.fullViewContainer}>
|
||||
<Button
|
||||
intent="text"
|
||||
size="small"
|
||||
variant="icon"
|
||||
className={styles.fullViewCloseButton}
|
||||
onClick={onClose}
|
||||
>
|
||||
<CloseIcon
|
||||
width={32}
|
||||
height={32}
|
||||
className={styles.fullViewCloseIcon}
|
||||
color="white"
|
||||
/>
|
||||
</Button>
|
||||
<div className={styles.fullViewHeader}>
|
||||
<span className={styles.imagePosition}>
|
||||
<Caption color="white">
|
||||
{`${currentIndex + 1} / ${totalImages}`}
|
||||
</Caption>
|
||||
</span>
|
||||
</div>
|
||||
<div className={styles.fullViewImageContainer}>
|
||||
<AnimatePresence initial={false} custom={animateLeft}>
|
||||
<motion.div
|
||||
key={image.src}
|
||||
custom={animateLeft}
|
||||
variants={variants}
|
||||
initial="initial"
|
||||
animate="animate"
|
||||
exit="exit"
|
||||
transition={{ duration: 0.3 }}
|
||||
className={styles.fullViewImage}
|
||||
drag="x"
|
||||
onDragEnd={(_e, info) => handleSwipe(info.offset.x)}
|
||||
>
|
||||
<Image
|
||||
alt={image.alt}
|
||||
fill
|
||||
sizes="(min-width: 1500px) 1500px, 100vw"
|
||||
src={image.src}
|
||||
style={{ objectFit: "cover" }}
|
||||
/>
|
||||
|
||||
<div className={styles.fullViewFooter}>
|
||||
{image.caption && <Body color="white">{image.caption}</Body>}
|
||||
</div>
|
||||
</motion.div>
|
||||
</AnimatePresence>
|
||||
</div>
|
||||
|
||||
<motion.button
|
||||
className={`${styles.navigationButton} ${styles.fullViewPrevButton}`}
|
||||
onClick={handlePrev}
|
||||
>
|
||||
<ArrowRightIcon color="burgundy" className={styles.leftTransformIcon} />
|
||||
</motion.button>
|
||||
<motion.button
|
||||
className={`${styles.navigationButton} ${styles.fullViewNextButton}`}
|
||||
onClick={handleNext}
|
||||
>
|
||||
<ArrowRightIcon color="burgundy" />
|
||||
</motion.button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
181
apps/scandic-web/components/Lightbox/Gallery.tsx
Normal file
181
apps/scandic-web/components/Lightbox/Gallery.tsx
Normal file
@@ -0,0 +1,181 @@
|
||||
"use client"
|
||||
import { AnimatePresence, motion } from "framer-motion"
|
||||
import { useState } from "react"
|
||||
import { useIntl } from "react-intl"
|
||||
|
||||
import { ChevronLeftIcon } from "@/components/Icons"
|
||||
import ArrowRightIcon from "@/components/Icons/ArrowRight"
|
||||
import CloseIcon from "@/components/Icons/Close"
|
||||
import Image from "@/components/Image"
|
||||
import Button from "@/components/TempDesignSystem/Button"
|
||||
import Caption from "@/components/TempDesignSystem/Text/Caption"
|
||||
|
||||
import styles from "./Lightbox.module.css"
|
||||
|
||||
import type { GalleryProps } from "@/types/components/lightbox/lightbox"
|
||||
|
||||
export default function Gallery({
|
||||
images,
|
||||
onClose,
|
||||
onSelectImage,
|
||||
onImageClick,
|
||||
selectedImage,
|
||||
}: GalleryProps) {
|
||||
const intl = useIntl()
|
||||
const [animateLeft, setAnimateLeft] = useState(true)
|
||||
const mainImage = selectedImage || images[0]
|
||||
const mainImageIndex = images.findIndex((img) => img === mainImage)
|
||||
|
||||
function getThumbImages() {
|
||||
const thumbs = []
|
||||
for (let i = 1; i <= Math.min(5, images.length); i++) {
|
||||
const index = (mainImageIndex + i) % images.length
|
||||
thumbs.push(images[index])
|
||||
}
|
||||
return thumbs
|
||||
}
|
||||
|
||||
function handleNext() {
|
||||
setAnimateLeft(true)
|
||||
const nextIndex = (mainImageIndex + 1) % images.length
|
||||
onSelectImage(images[nextIndex])
|
||||
}
|
||||
|
||||
function handlePrev() {
|
||||
setAnimateLeft(false)
|
||||
const prevIndex = (mainImageIndex - 1 + images.length) % images.length
|
||||
onSelectImage(images[prevIndex])
|
||||
}
|
||||
|
||||
const variants = {
|
||||
initial: (animateLeft: boolean) => ({
|
||||
opacity: 0,
|
||||
x: animateLeft ? 300 : -300,
|
||||
}),
|
||||
animate: { opacity: 1, x: 0 },
|
||||
exit: (animateLeft: boolean) => ({
|
||||
opacity: 0,
|
||||
x: animateLeft ? -300 : 300,
|
||||
}),
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={styles.galleryContainer}>
|
||||
<Button
|
||||
intent="text"
|
||||
size="small"
|
||||
className={styles.closeButton}
|
||||
onClick={onClose}
|
||||
aria-label={intl.formatMessage({ id: "Close" })}
|
||||
>
|
||||
<ChevronLeftIcon
|
||||
color="black"
|
||||
width={32}
|
||||
height={32}
|
||||
className={styles.mobileCloseIcon}
|
||||
/>
|
||||
<CloseIcon width={32} height={32} className={styles.desktopCloseIcon} />
|
||||
</Button>
|
||||
{/* Desktop Gallery */}
|
||||
<div className={styles.desktopGallery}>
|
||||
<div className={styles.galleryHeader}>
|
||||
{mainImage.caption && (
|
||||
<div className={styles.imageCaption}>
|
||||
<Caption color="textMediumContrast">{mainImage.caption}</Caption>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className={styles.mainImageWrapper}>
|
||||
<AnimatePresence initial={false} custom={animateLeft}>
|
||||
<motion.div
|
||||
key={mainImage.src}
|
||||
className={styles.mainImageContainer}
|
||||
custom={animateLeft}
|
||||
variants={variants}
|
||||
initial="initial"
|
||||
animate="animate"
|
||||
exit="exit"
|
||||
transition={{ duration: 0.3 }}
|
||||
>
|
||||
<Image
|
||||
src={mainImage.src}
|
||||
alt={mainImage.alt}
|
||||
fill
|
||||
sizes="(min-width: 1000px) 1000px, 100vw"
|
||||
className={styles.image}
|
||||
onClick={onImageClick}
|
||||
/>
|
||||
</motion.div>
|
||||
</AnimatePresence>
|
||||
<motion.button
|
||||
className={`${styles.navigationButton} ${styles.galleryPrevButton}`}
|
||||
onClick={handlePrev}
|
||||
>
|
||||
<ArrowRightIcon
|
||||
color="burgundy"
|
||||
className={styles.leftTransformIcon}
|
||||
/>
|
||||
</motion.button>
|
||||
<motion.button
|
||||
className={`${styles.navigationButton} ${styles.galleryNextButton}`}
|
||||
onClick={handleNext}
|
||||
>
|
||||
<ArrowRightIcon color="burgundy" />
|
||||
</motion.button>
|
||||
</div>
|
||||
<div className={styles.desktopThumbnailGrid}>
|
||||
<AnimatePresence initial={false}>
|
||||
{getThumbImages().map((image, index) => (
|
||||
<motion.div
|
||||
key={image.smallSrc || image.src}
|
||||
className={styles.thumbnailContainer}
|
||||
onClick={() => onSelectImage(image)}
|
||||
initial={{ opacity: 0, x: 50 }}
|
||||
animate={{ opacity: 1, x: 0 }}
|
||||
exit={{ opacity: 0, x: -50 }}
|
||||
transition={{ duration: 0.2, delay: index * 0.05 }}
|
||||
>
|
||||
<Image
|
||||
src={image.smallSrc || image.src}
|
||||
alt={image.alt}
|
||||
fill
|
||||
sizes="200px"
|
||||
className={styles.image}
|
||||
/>
|
||||
</motion.div>
|
||||
))}
|
||||
</AnimatePresence>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Mobile Gallery */}
|
||||
<div className={styles.mobileGallery}>
|
||||
<div className={styles.mobileGalleryContent}>
|
||||
<div className={styles.thumbnailGrid}>
|
||||
{images.map((image, index) => (
|
||||
<motion.div
|
||||
key={image.smallSrc || image.src}
|
||||
className={`${styles.thumbnailContainer} ${index % 3 === 0 ? styles.fullWidthImage : ""}`}
|
||||
onClick={() => {
|
||||
onSelectImage(image)
|
||||
onImageClick()
|
||||
}}
|
||||
initial={{ opacity: 0, y: 20 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
transition={{ duration: 0.3, delay: index * 0.05 }}
|
||||
>
|
||||
<Image
|
||||
src={image.smallSrc || image.src}
|
||||
alt={image.alt}
|
||||
fill
|
||||
sizes="100vw"
|
||||
className={styles.image}
|
||||
/>
|
||||
</motion.div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
348
apps/scandic-web/components/Lightbox/Lightbox.module.css
Normal file
348
apps/scandic-web/components/Lightbox/Lightbox.module.css
Normal file
@@ -0,0 +1,348 @@
|
||||
@keyframes darken-background {
|
||||
from {
|
||||
background-color: rgba(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
to {
|
||||
background-color: rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
}
|
||||
|
||||
.mobileGallery {
|
||||
height: 100%;
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--Spacing-x2);
|
||||
}
|
||||
|
||||
.closeButton {
|
||||
justify-content: flex-start;
|
||||
width: fit-content;
|
||||
}
|
||||
.closeButton .desktopCloseIcon {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.mobileGalleryContent {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.fullViewCloseButton {
|
||||
position: absolute;
|
||||
top: var(--Spacing-x-one-and-half);
|
||||
right: var(--Spacing-x-half);
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.fullViewCloseButton:hover .fullViewCloseIcon {
|
||||
background-color: var(--UI-Text-Medium-contrast);
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.leftTransformIcon {
|
||||
transform: scaleX(-1);
|
||||
}
|
||||
|
||||
.content {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border-radius: 0;
|
||||
position: fixed;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
z-index: var(--lightbox-z-index);
|
||||
}
|
||||
|
||||
.overlay {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
background-color: rgba(0, 0, 0, 0.5);
|
||||
z-index: var(--lightbox-z-index);
|
||||
}
|
||||
|
||||
.overlay[data-entering] {
|
||||
animation: darken-background 0.2s;
|
||||
}
|
||||
|
||||
.overlay[data-exiting] {
|
||||
animation: darken-background 0.2s reverse;
|
||||
}
|
||||
|
||||
.galleryContainer {
|
||||
background-color: var(--Base-Background-Primary-Normal);
|
||||
padding: var(--Spacing-x2);
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
position: relative;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.galleryHeader {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
height: 1.71875rem;
|
||||
}
|
||||
|
||||
.desktopGallery,
|
||||
.desktopThumbnailGrid,
|
||||
.navigationButton {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.imageCaption {
|
||||
background-color: var(--Base-Surface-Subtle-Normal);
|
||||
padding: var(--Spacing-x-half) var(--Spacing-x1);
|
||||
border-radius: var(--Corner-radius-Small);
|
||||
}
|
||||
|
||||
.mainImageWrapper {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.mainImageContainer {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
will-change: transform;
|
||||
overflow: hidden;
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
.mainImageContainer img,
|
||||
.thumbnailContainer img {
|
||||
border-radius: var(--Corner-radius-Small);
|
||||
cursor: pointer;
|
||||
transition: opacity 0.3s ease-in-out;
|
||||
}
|
||||
|
||||
.thumbnailGrid {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: var(--Spacing-x1);
|
||||
max-height: none;
|
||||
padding: var(--Spacing-x3) 0;
|
||||
}
|
||||
|
||||
.thumbnailContainer {
|
||||
position: relative;
|
||||
height: 242px;
|
||||
}
|
||||
|
||||
.fullWidthImage {
|
||||
grid-column: 1 / -1;
|
||||
height: 240px;
|
||||
}
|
||||
|
||||
.thumbnailContainer img {
|
||||
border-radius: var(--Corner-radius-Medium);
|
||||
}
|
||||
|
||||
.fullViewContainer {
|
||||
background-color: var(--UI-Text-High-contrast);
|
||||
height: 100%;
|
||||
padding: var(--Spacing-x2);
|
||||
position: relative;
|
||||
align-items: center;
|
||||
justify-items: center;
|
||||
display: grid;
|
||||
grid-template-rows: auto 1fr auto;
|
||||
grid-template-columns: 1fr;
|
||||
place-content: center;
|
||||
gap: var(--Spacing-x5);
|
||||
}
|
||||
|
||||
.fullViewHeader {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.fullViewImageContainer {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
max-height: 25rem;
|
||||
margin-bottom: var(--Spacing-x5);
|
||||
}
|
||||
|
||||
.fullViewImage {
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border-radius: var(--Corner-radius-Medium);
|
||||
}
|
||||
|
||||
.fullViewImageContainer img {
|
||||
border-radius: var(--Corner-radius-Medium);
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.fullViewFooter {
|
||||
position: absolute;
|
||||
bottom: calc(-1 * var(--Spacing-x5));
|
||||
}
|
||||
|
||||
.imagePosition {
|
||||
background-color: var(--UI-Grey-90);
|
||||
padding: var(--Spacing-x-quarter) var(--Spacing-x-half);
|
||||
border-radius: var(--Corner-radius-Small);
|
||||
}
|
||||
|
||||
.portraitImage {
|
||||
max-width: 548px;
|
||||
}
|
||||
|
||||
.image {
|
||||
object-fit: cover;
|
||||
}
|
||||
@media (min-width: 768px) and (max-width: 1367px) {
|
||||
.fullViewContainer {
|
||||
padding: var(--Spacing-x5);
|
||||
}
|
||||
|
||||
.fullViewImageContainer {
|
||||
height: 100%;
|
||||
max-height: 35rem;
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.mobileGallery,
|
||||
.thumbnailGrid {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.content {
|
||||
position: fixed;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.content:not(.fullViewContent) {
|
||||
border-radius: var(--Corner-radius-Large);
|
||||
}
|
||||
|
||||
.galleryContent {
|
||||
width: 1090px;
|
||||
width: min(var(--max-width-page), 1090px);
|
||||
height: min(725px, 85dvh);
|
||||
}
|
||||
|
||||
.fullViewContent {
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
}
|
||||
|
||||
.galleryContainer {
|
||||
padding: var(--Spacing-x5) var(--Spacing-x6);
|
||||
}
|
||||
|
||||
.desktopGallery {
|
||||
display: grid;
|
||||
grid-template-rows: 1.71875rem 1fr 7.8125rem;
|
||||
row-gap: var(--Spacing-x-one-and-half);
|
||||
background-color: var(--Base-Background-Primary-Normal);
|
||||
height: 100%;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.closeButton {
|
||||
display: block;
|
||||
position: absolute;
|
||||
top: var(--Spacing-x-one-and-half);
|
||||
right: var(--Spacing-x1);
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.closeButton .mobileCloseIcon {
|
||||
display: none;
|
||||
}
|
||||
.closeButton .desktopCloseIcon {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.closeButton:hover .desktopCloseIcon {
|
||||
background-color: var(--Base-Surface-Primary-light-Hover-alt);
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.desktopThumbnailGrid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(5, 1fr);
|
||||
gap: var(--Spacing-x1);
|
||||
max-height: 7.8125rem;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.thumbnailContainer {
|
||||
height: 125px;
|
||||
}
|
||||
|
||||
.fullViewCloseButton {
|
||||
position: fixed;
|
||||
top: var(--Spacing-x-one-and-half);
|
||||
right: var(--Spacing-x-half);
|
||||
}
|
||||
|
||||
.fullWidthImage {
|
||||
grid-column: auto;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.thumbnailContainer img {
|
||||
border-radius: var(--Corner-radius-Small);
|
||||
}
|
||||
|
||||
.fullViewContainer {
|
||||
margin-top: 0;
|
||||
padding: var(--Spacing-x5);
|
||||
grid-template-rows: auto 1fr auto;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.fullViewImageContainer {
|
||||
width: 70%;
|
||||
max-width: 90.875rem;
|
||||
max-height: 43.75rem;
|
||||
}
|
||||
|
||||
.navigationButton {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
background-color: var(--Base-Button-Inverted-Fill-Normal);
|
||||
border-radius: 50%;
|
||||
padding: var(--Spacing-x1);
|
||||
cursor: pointer;
|
||||
border: none;
|
||||
display: flex;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.galleryPrevButton {
|
||||
left: var(--Spacing-x2);
|
||||
}
|
||||
|
||||
.galleryNextButton {
|
||||
right: var(--Spacing-x2);
|
||||
}
|
||||
|
||||
.fullViewNextButton {
|
||||
right: var(--Spacing-x5);
|
||||
}
|
||||
|
||||
.fullViewPrevButton {
|
||||
left: var(--Spacing-x5);
|
||||
}
|
||||
|
||||
.fullViewFooter {
|
||||
text-align: left;
|
||||
}
|
||||
}
|
||||
97
apps/scandic-web/components/Lightbox/index.tsx
Normal file
97
apps/scandic-web/components/Lightbox/index.tsx
Normal file
@@ -0,0 +1,97 @@
|
||||
"use client"
|
||||
import { AnimatePresence, motion } from "framer-motion"
|
||||
import { useEffect, useState } from "react"
|
||||
import { Dialog, Modal, ModalOverlay } from "react-aria-components"
|
||||
|
||||
import FullView from "./FullView"
|
||||
import Gallery from "./Gallery"
|
||||
|
||||
import styles from "./Lightbox.module.css"
|
||||
|
||||
import type { LightboxProps } from "@/types/components/lightbox/lightbox"
|
||||
|
||||
export default function Lightbox({
|
||||
images,
|
||||
dialogTitle,
|
||||
onClose,
|
||||
isOpen,
|
||||
activeIndex = 0,
|
||||
}: LightboxProps) {
|
||||
const [selectedImageIndex, setSelectedImageIndex] = useState(activeIndex)
|
||||
const [isFullView, setIsFullView] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
if (isOpen) {
|
||||
setIsFullView(false)
|
||||
}
|
||||
}, [isOpen])
|
||||
|
||||
useEffect(() => {
|
||||
setSelectedImageIndex(activeIndex)
|
||||
}, [activeIndex])
|
||||
|
||||
function handleClose() {
|
||||
setSelectedImageIndex(0)
|
||||
onClose()
|
||||
}
|
||||
|
||||
function handleNext() {
|
||||
setSelectedImageIndex((prevIndex) => (prevIndex + 1) % images.length)
|
||||
}
|
||||
|
||||
function handlePrev() {
|
||||
setSelectedImageIndex(
|
||||
(prevIndex) => (prevIndex - 1 + images.length) % images.length
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<ModalOverlay
|
||||
isOpen={isOpen}
|
||||
onOpenChange={handleClose}
|
||||
className={styles.overlay}
|
||||
isDismissable
|
||||
>
|
||||
<Modal>
|
||||
<AnimatePresence>
|
||||
<Dialog aria-label={dialogTitle}>
|
||||
{isOpen && (
|
||||
<motion.div
|
||||
className={`${styles.content} ${
|
||||
isFullView ? styles.fullViewContent : styles.galleryContent
|
||||
}`}
|
||||
initial={{ opacity: 0, scale: 0.95 }}
|
||||
animate={{ opacity: 1, scale: 1, x: "-50%", y: "-50%" }}
|
||||
exit={{ opacity: 0, scale: 0.95 }}
|
||||
transition={{ duration: 0.2 }}
|
||||
>
|
||||
{isFullView ? (
|
||||
<FullView
|
||||
image={images[selectedImageIndex]}
|
||||
onClose={() => setIsFullView(false)}
|
||||
onNext={handleNext}
|
||||
onPrev={handlePrev}
|
||||
currentIndex={selectedImageIndex}
|
||||
totalImages={images.length}
|
||||
/>
|
||||
) : (
|
||||
<Gallery
|
||||
images={images}
|
||||
onClose={onClose}
|
||||
onSelectImage={(image) => {
|
||||
setSelectedImageIndex(
|
||||
images.findIndex((img) => img === image)
|
||||
)
|
||||
}}
|
||||
onImageClick={() => setIsFullView(true)}
|
||||
selectedImage={images[selectedImageIndex]}
|
||||
/>
|
||||
)}
|
||||
</motion.div>
|
||||
)}
|
||||
</Dialog>
|
||||
</AnimatePresence>
|
||||
</Modal>
|
||||
</ModalOverlay>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user