Skip to content

Commit

Permalink
Merge pull request #296 from k-t18/main
Browse files Browse the repository at this point in the history
feat: ❇️ added image magnification library
  • Loading branch information
karan1633 authored Dec 1, 2024
2 parents f15a395 + 60eb0d9 commit 4ac28ad
Show file tree
Hide file tree
Showing 4 changed files with 307 additions and 135 deletions.
23 changes: 23 additions & 0 deletions hooks/ProductImageGalleryHandler/useImageGallery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { useState } from 'react';
import { CONSTANTS } from '../../services/config/app-config';

const useImageGallery = ({ slideShowImages }: any) => {
const [enlargeImg, setEnlargeImg] = useState<string>(slideShowImages?.[0] || ''); // Track the enlarged image
const [activeImgIndex, setActiveImgIndex] = useState<number>(0); // Track the active thumbnail index

const handleSelectedImage = (imageLink: string, imgIndex: number) => {
setEnlargeImg(imageLink);
setActiveImgIndex(imgIndex); // Update the active index
};

// Create srcSet for different screen resolutions
const generateSrcSet = (image: string) => {
return `${CONSTANTS.API_BASE_URL}/${image} 600w,
${CONSTANTS.API_BASE_URL}/${image} 1200w,
${CONSTANTS.API_BASE_URL}/${image} 1800w`;
};

return { enlargeImg, activeImgIndex, handleSelectedImage, generateSrcSet };
};

export default useImageGallery;
3 changes: 3 additions & 0 deletions interfaces/product-slideshow-images.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface ProductSlideshowImages {
slideShowImages: string[];
}
Loading

0 comments on commit 4ac28ad

Please sign in to comment.