Skip to content

Commit

Permalink
image popup in carousel
Browse files Browse the repository at this point in the history
  • Loading branch information
GraemeFulton committed Feb 10, 2024
1 parent 783ec45 commit 5555ec2
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 8 deletions.
37 changes: 36 additions & 1 deletion components/Primitives/Dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const overlayShow = keyframes({

const StyledOverlay = styled(DialogPrimitive.Overlay, {
backgroundColor: `rgba(0,0,0,0.75)`,
zIndex: 50,
zIndex: 99,
position: "fixed",
inset: 0,
"@media (prefers-reduced-motion: no-preference)": {
Expand Down Expand Up @@ -75,6 +75,32 @@ const overlayShow = keyframes({
"&:focus": { outline: "none" },
});

const StyledContentImage = styled(DialogPrimitive.Content, {
zIndex: 999,
// backgroundColor: "white",
borderRadius: 6,
boxShadow:
"hsl(206 22% 7% / 35%) 0px 10px 38px -10px, hsl(206 22% 7% / 20%) 0px 10px 20px -15px",
position: "fixed",
// display:'flex',
// flexDirection:'column',
// justifyContent:'space-between',
top: "50%",
left: "50%",
transform: "translate(-50%, -50%)",
width: "auto",
maxWidth: "90vw",
minWidth:"300px",
minHeight:"200px",
height: "auto",
// minHeight: "60vh",
// padding: 25,
"@media (prefers-reduced-motion: no-preference)": {
animation: `${contentShow} 150ms cubic-bezier(0.16, 1, 0.3, 1)`,
},
"&:focus": { outline: "none" },
});

function ContentLarge({ children, ...props }) {
return (
<DialogPrimitive.Portal>
Expand All @@ -83,6 +109,14 @@ const overlayShow = keyframes({
</DialogPrimitive.Portal>
);
}
function ContentImage({ children, ...props }) {
return (
<DialogPrimitive.Portal>
<StyledOverlay />
<StyledContentImage {...props}>{children}</StyledContentImage>
</DialogPrimitive.Portal>
);
}

const StyledTitle = styled(DialogPrimitive.Title, {
margin: 0,
Expand Down Expand Up @@ -121,6 +155,7 @@ const overlayShow = keyframes({
export const DialogTrigger = DialogPrimitive.Trigger;
export const DialogContent = Content;
export const DialogContentLarge = ContentLarge;
export const DialogContentImage = ContentImage;
export const DialogTitle = StyledTitle;
export const DialogDescription = StyledDescription;
export const DialogClose = DialogPrimitive.Close;
Expand Down
32 changes: 28 additions & 4 deletions components/carousel/EmblaCarousel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
NextButton,
usePrevNextButtons
} from './EmblaCarouselArrowButtons'
import { ImageDialog } from './ImageDialog.js/ImageDialog';

const EmblaCarousel = (props) => {
const { slides, options } = props
Expand All @@ -28,6 +29,11 @@ const EmblaCarousel = (props) => {
[emblaMainApi, emblaThumbsApi]
)

const [currentImage, setCurrentImage] = useState(slides[0]?.original)
useEffect(()=>{
setCurrentImage(slides[selectedIndex]?.original)
},[selectedIndex])

const onSelect = useCallback(() => {
if (!emblaMainApi || !emblaThumbsApi) return
setSelectedIndex(emblaMainApi.selectedScrollSnap())
Expand All @@ -45,12 +51,20 @@ const EmblaCarousel = (props) => {
prevBtnDisabled,
nextBtnDisabled,
onPrevButtonClick,
onNextButtonClick
onNextButtonClick,
} = usePrevNextButtons(emblaMainApi)



const [dialogOpenImage, setDialogOpenImage] = useState(false)

const toggleDialogOpen = () =>{
setDialogOpenImage(!dialogOpenImage)
}

return (
<div className="embla px-14 py-6 -ml-[1.6rem] -mt-[1.6rem] relative">
<div className="embla__buttons absolute top-0 w-full flex justify-between -mt-[2rem]">
<div className="embla__buttons absolute top-0 w-full flex justify-between -mt-[2.45rem]">
<PrevButton onClick={onPrevButtonClick} disabled={prevBtnDisabled} />
<NextButton onClick={onNextButtonClick} disabled={nextBtnDisabled} />
</div>
Expand All @@ -66,8 +80,12 @@ const EmblaCarousel = (props) => {
src={item.original}
alt="Your alt text"
/> */}
<div className="relative shadow-md w-full rounded-xl h-[200px] sm:h-[300px] w-full lg:max-h-full relative overflow-hidden flex justify-center">
<div className="relative shadow-md w-full rounded-xl h-[100px] sm:h-[264px] w-full lg:max-h-full relative overflow-hidden flex justify-center">
<Image
onClick={()=>{
setCurrentImage(item.original)
setDialogOpenImage(item.original)
}}
loader={gumletLoader}
layout="fill"
objectFit="cover"
Expand All @@ -80,7 +98,7 @@ const EmblaCarousel = (props) => {
// data-src={current.original}
alt={`Gallery Image ${index}`}
sizes={"(max-width: 300px) 100vw, 600px"}
className='embla__slide__img rounded-xl shadow-xl p-[4px] bg-white border border-gray-200'
className='embla__slide__img cursor-pointer rounded-xl shadow-xl p-[4px] bg-white border border-gray-200'
/>
</div>
</div>
Expand All @@ -103,6 +121,12 @@ const EmblaCarousel = (props) => {
</div>
</div>
</div>
<ImageDialog
onPrevButtonClick={onPrevButtonClick}
prevBtnDisabled={prevBtnDisabled}
nextBtnDisabled={nextBtnDisabled}
onNextButtonClick={onNextButtonClick}
image={currentImage} open={dialogOpenImage?true:false} toggleOpen={toggleDialogOpen}/>
</div>
)
}
Expand Down
2 changes: 1 addition & 1 deletion components/carousel/EmblaCarouselThumbsButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const Thumb = (props) => {
>
<button
onClick={onClick}
className="embla-thumbs__slide__button"
className="embla-thumbs__slide__button rounded-lg"
type="button"
>
<div className="embla-thumbs__slide__number">
Expand Down
82 changes: 82 additions & 0 deletions components/carousel/ImageDialog.js/ImageDialog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import dynamic from "next/dynamic";
import { Cross2Icon } from "@radix-ui/react-icons";
import { Dialog, DialogTrigger, DialogContentLarge, DialogTitle, DialogDescription, DialogClose, IconButton, DialogContentImage } from "@/components/Primitives/Dialog";
import { useState, useEffect } from "react";
import { useRouter } from "next/router";
import Image from "next/image";
import {
PrevButton,
NextButton,
usePrevNextButtons
} from '../EmblaCarouselArrowButtons'

const Spinner = dynamic(() => import("@/components/atom/Spinner/Spinner"));

export const ImageDialog = ({open, toggleOpen, image, onPrevButtonClick, onNextButtonClick, prevBtnDisabled, nextBtnDisabled}) =>{
const router = useRouter();

const [loading, setLoading] = useState(true)

useEffect(()=>{
if(open){
setLoading(true)
}else{
setLoading(true)
}
},[open])

const navigate = (direction) =>{
// setLoading(true)
if(direction=='prev'){
onPrevButtonClick()
}else{
onNextButtonClick()
}
}

return(
<Dialog open={open} onOpenChange={toggleOpen}>
<DialogContentImage className="w-[70vw]" variant="">
<div>
{/* <DialogTitle>Submit for Review</DialogTitle> */}
<DialogDescription>
<div className="w-full h-full relative">
<div className="absolute w-full h-full">
<div className={`${loading?'h-[100px]':'opacity-0'} flex justify-center`}>
<div className="my-auto">
<div className="text-white -mt-[80px] flex flex-col">
<div className="mx-auto mb-3">
<Spinner/>
</div>
{/* <p className="text-gray-100/70 text-center">Loading image...</p> */}
</div>
</div>
</div>
</div>
<Image
key={image}
width={0}
onLoadingComplete={()=>setLoading(false)}
height={0}
sizes="100vw"
className={`w-auto h-auto max-w-full mx-auto`}
// width={'100%'}
// height={'100%'}
src={image}/>
<div className="embla__buttons absolute top-0 w-[110%] -ml-[5%] flex justify-between -mt-[2.45rem]">
<PrevButton onClick={()=>navigate('prev')} disabled={prevBtnDisabled} />
<NextButton onClick={()=>navigate('next')} disabled={nextBtnDisabled} />
</div>
</div>
</DialogDescription>
</div>

{!loading && <DialogClose className="-mr-12" asChild>
<IconButton className="bg-gray-200 shadow border border-gray-800 cursor-pointer" aria-label="Close">
<Cross2Icon />
</IconButton>
</DialogClose>}
</DialogContentImage>
</Dialog>
)
}
4 changes: 2 additions & 2 deletions pages/toolbox/[slug].js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const ToolContent = ({ post, gallery, relatedPosts, popularTags }) => {
<Container padding={false} maxWidth="w-full relative z-0" >
<img src='/static/images/toolbox/squares.svg' className="border-b border-gray-200/90 opacity absolute w-full h-full object-cover top-0 left-0"/>

<div className="pt-[132px] shadow-md -mt-[96px] md:pt-[112px] pb-[194px] relative overflow-hidden p-6 border-gray-200">
<div className="pt-[132px] shadow-md -mt-[96px] md:pt-[112px] pb-[182px] relative overflow-hidden p-6 border-gray-200">
<div
style={{
// backgroundColor:`${stc(post?.attributes?.title)}`,
Expand Down Expand Up @@ -165,7 +165,7 @@ const ToolContent = ({ post, gallery, relatedPosts, popularTags }) => {
<Container maxWidth="w-full bg-white relative z-10 pt-8">
<div className="max-w-[1320px] mx-auto grid grid-cols-12 gap-6 xl:gap-0 px-3 md:px-0 h-full">
<div className="col-span-12 lg:col-span-12">
<div className="-mt-[214px] mt-8 mb-6 rounded-xl">
<div className="-mt-[190px] mt-8 mb-6 rounded-xl">
{/* <h3 class="text-lg font-bold">Gallery</h3> */}
{/* {post?.attributes && (
<PopupGallery
Expand Down

0 comments on commit 5555ec2

Please sign in to comment.