next-enterprise/components/officeLightbox/OfficeLightbox.tsx

91 lines
3.3 KiB
TypeScript
Raw Normal View History

2024-01-02 13:57:20 +01:00
'use client'
2024-01-03 11:42:00 +01:00
import { ChevronLeftIcon, ChevronRightIcon } from '@heroicons/react/24/outline';
import { Mouse } from '@playwright/test';
2024-01-02 13:57:20 +01:00
import Image from 'next/image';
import React, { useState } from 'react';
const OfficeLightbox: React.FC = () => {
const [selectedImage, setSelectedImage] = useState<string | null>(null);
2024-01-03 11:42:00 +01:00
const [currentIndex, setCurrentIndex] = useState<number>(0);
2024-01-02 13:57:20 +01:00
const images = [
'/office1.jpeg',
'/office5.jpeg',
'/office3.jpeg',
'/office2.jpeg',
'/office6.jpeg',
'/office8.jpeg'
];
2024-01-03 11:42:00 +01:00
const openLightbox = (image: string, index: number) => {
2024-01-02 13:57:20 +01:00
setSelectedImage(image);
2024-01-03 11:42:00 +01:00
setCurrentIndex(index);
2024-01-02 13:57:20 +01:00
};
const closeLightbox = () => {
setSelectedImage(null);
};
2024-01-03 11:42:00 +01:00
const handlePrev = (event: React.MouseEvent<HTMLButtonElement>) => {
event.stopPropagation();
setCurrentIndex(prevIndex => (prevIndex === 0 ? images.length -1 : prevIndex -1));
setSelectedImage(images[currentIndex -1 < 0 ? images.length -1 : currentIndex -1]);
};
const handleNext = (event: React.MouseEvent<HTMLButtonElement>) => {
event.stopPropagation();
setCurrentIndex(prevIndex => (prevIndex === images.length -1 ? 0 : prevIndex +1));
setSelectedImage(images[currentIndex +1 >= images.length ? 0 : currentIndex +1])
}
2024-01-02 13:57:20 +01:00
return (
2024-01-03 11:42:00 +01:00
<div className='px-6 pb-24 pt-12 sm:pt-32'>
<div className='flex flex-col justify-center items-center text-center'>
<h2 className='text-3xl font-bold tracking-tight text-primary-800 sm:text-4xl'>Coworking copy</h2>
<p className='mt-4 text-lg leading-8 text-primary-800'>Lorem ipsum dolor sit amet consectetur adipisicing elit. Dolorem quo quibusdam ipsam aliquid sequi, qui alias. Repellat quasi exercitationem impedit, officia odio veniam pariatur temporibus reprehenderit aspernatur, perferendis soluta quaerat.</p>
</div>
<div className='mx-auto my-4 p-4 relative sm:p-4'>
<div className="flex flex-wrap justify-center items-center gap-1">
2024-01-02 13:57:20 +01:00
{images.map((image, index) => (
<Image
key={index}
src={image}
alt={`Image ${index}`}
2024-01-03 11:42:00 +01:00
onClick={() => openLightbox(image, index)}
2024-01-02 13:57:20 +01:00
className="cursor-pointer"
width={600}
height={275}
/>
))}
</div>
2024-01-03 11:42:00 +01:00
</div>
2024-01-02 13:57:20 +01:00
{/* Render the lightbox when an image is selected */}
{selectedImage && (
<div
className="fixed top-0 left-0 w-full h-full flex items-center justify-center bg-black/80"
onClick={closeLightbox}
>
<div className="max-w-2xl max-h-2xl">
<Image
src={selectedImage}
alt="Selected Image"
fill={true}
2024-01-03 11:42:00 +01:00
className="object-contain p-1"/>
2024-01-02 13:57:20 +01:00
</div>
2024-01-03 11:42:00 +01:00
<button
className='absolute top-1/2 left-4 transform -translate-y-1/2 bg-white rounded-full p-1 text-black'
onClick={handlePrev}
>
<ChevronLeftIcon className='h-8 w-8 p-1' />
</button>
<button
className='absolute top-1/2 right-4 transform -translate-y-1/2 bg-white rounded-full p-1 text-black'
onClick={handleNext}
>
<ChevronRightIcon className='h-8 w-8 p-1'/>
</button>
2024-01-02 13:57:20 +01:00
</div>
)}
</div>
);
};
export default OfficeLightbox;
2024-01-03 11:42:00 +01:00