initial commit
This commit is contained in:
@@ -0,0 +1,207 @@
|
||||
.carouselContainer {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
touch-action: pan-y;
|
||||
}
|
||||
|
||||
.productImage {
|
||||
width: 99%;
|
||||
height: auto;
|
||||
object-fit: contain;
|
||||
// transition: transform 0.3s ease-in-out, opacity 0.3s ease-in-out;
|
||||
}
|
||||
|
||||
/* Fixed frame container to prevent layout shifts */
|
||||
.fixedFrameContainer {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
aspect-ratio: 1; /* Square container */
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background-color: white;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* Style for product card (non-detail view) images */
|
||||
.cardImage {
|
||||
width: auto;
|
||||
height: 300px; /* Increased height for card view */
|
||||
max-width: 100%;
|
||||
margin: auto;
|
||||
object-fit: contain;
|
||||
}
|
||||
|
||||
/* Style for images inside detail view */
|
||||
.detailImage {
|
||||
width: auto;
|
||||
height: auto;
|
||||
max-width: 90%;
|
||||
max-height: 90%;
|
||||
margin: auto;
|
||||
object-fit: contain;
|
||||
}
|
||||
|
||||
/* Specific styles for the detail carousel */
|
||||
.detailCarousel {
|
||||
.carouselContainer {
|
||||
height: auto;
|
||||
min-height: 400px;
|
||||
}
|
||||
|
||||
.fixedFrameContainer {
|
||||
min-height: 400px;
|
||||
}
|
||||
}
|
||||
|
||||
.imageWrapper {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
// .transitioning img {
|
||||
// opacity: 0.8;
|
||||
// transition: opacity 0.3s ease-in-out;
|
||||
// }
|
||||
|
||||
.arrowButton {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
border-radius: 50%;
|
||||
background-color: rgba(255, 255, 255, 0.8);
|
||||
border: none;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
cursor: pointer;
|
||||
opacity: 0;
|
||||
transition: opacity 0.2s ease, background-color 0.2s ease;
|
||||
z-index: 10;
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||
|
||||
&:hover {
|
||||
background-color: white;
|
||||
}
|
||||
|
||||
svg {
|
||||
color: #333;
|
||||
}
|
||||
}
|
||||
|
||||
/* Fixed positions for arrows - they won't move with image size changes */
|
||||
.leftArrow {
|
||||
left: 8px;
|
||||
}
|
||||
|
||||
.rightArrow {
|
||||
right: 8px;
|
||||
}
|
||||
|
||||
/* Make sure the carousel wrapper has a defined position */
|
||||
.carouselWrapper {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.carouselContainer:hover .arrowButton {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.indicators {
|
||||
position: absolute;
|
||||
bottom: 8px;
|
||||
left: 0;
|
||||
right: 0;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.indicator {
|
||||
width: 6px;
|
||||
height: 6px;
|
||||
border-radius: 50%;
|
||||
background-color: rgba(200, 200, 200, 0.7);
|
||||
transition: background-color 0.2s ease;
|
||||
|
||||
&:hover {
|
||||
background-color: rgba(255, 255, 255, 0.8);
|
||||
}
|
||||
|
||||
&.active {
|
||||
background-color: #333;
|
||||
}
|
||||
}
|
||||
|
||||
.thumbnailContainer {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
margin-top: 5px;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.thumbnail {
|
||||
width: 60px;
|
||||
height: 60px;
|
||||
border-radius: 4px;
|
||||
overflow: hidden;
|
||||
cursor: pointer;
|
||||
border: 1px solid #e0e0e0;
|
||||
opacity: 0.7;
|
||||
transition: all 0.2s ease;
|
||||
|
||||
&:hover {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
}
|
||||
|
||||
.activeThumbnail {
|
||||
opacity: 1;
|
||||
border: 2px solid #ff6b00;
|
||||
}
|
||||
|
||||
/* Responsive styling */
|
||||
@media (max-width: 768px) {
|
||||
.thumbnailContainer {
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.thumbnail {
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
}
|
||||
|
||||
.detailCarousel {
|
||||
.carouselContainer {
|
||||
min-height: 300px;
|
||||
}
|
||||
|
||||
.fixedFrameContainer {
|
||||
min-height: 300px;
|
||||
}
|
||||
}
|
||||
|
||||
.cardImage {
|
||||
height: 180px; /* Adjusted height for mobile view */
|
||||
}
|
||||
}
|
||||
218
src/components/ProductCard/imageCarousel/index.jsx
Normal file
218
src/components/ProductCard/imageCarousel/index.jsx
Normal file
@@ -0,0 +1,218 @@
|
||||
import { useState, useRef, useEffect } from "react";
|
||||
import styles from "./ImageCarousel.module.scss";
|
||||
|
||||
const ImageCarousel = ({
|
||||
images,
|
||||
altText,
|
||||
showThumbnails = false,
|
||||
isDetailView = false, // Prop to differentiate between card and detail view
|
||||
}) => {
|
||||
const [currentIndex, setCurrentIndex] = useState(0);
|
||||
const touchStartX = useRef(0);
|
||||
const touchEndX = useRef(0);
|
||||
const carouselRef = useRef(null);
|
||||
|
||||
// Check if there are multiple images
|
||||
const hasMultipleImages = Array.isArray(images) && images.length > 1;
|
||||
|
||||
// Get current image URL
|
||||
const currentImage =
|
||||
hasMultipleImages && images[currentIndex]
|
||||
? images[currentIndex].images_400x400
|
||||
: images[0]?.images_400x400 || "";
|
||||
|
||||
// Auto-slide functionality - every 9 seconds
|
||||
useEffect(() => {
|
||||
if (!hasMultipleImages) return;
|
||||
|
||||
const interval = setInterval(() => {
|
||||
setCurrentIndex((prev) => (prev === images.length - 1 ? 0 : prev + 1));
|
||||
}, 9000);
|
||||
|
||||
return () => clearInterval(interval);
|
||||
}, [hasMultipleImages, images]);
|
||||
|
||||
// Navigate to previous image
|
||||
const handlePrev = (e) => {
|
||||
if (e) e.stopPropagation();
|
||||
if (!hasMultipleImages) return;
|
||||
setCurrentIndex((prev) => (prev === 0 ? images.length - 1 : prev - 1));
|
||||
};
|
||||
|
||||
// Navigate to next image
|
||||
const handleNext = (e) => {
|
||||
if (e) e.stopPropagation();
|
||||
if (!hasMultipleImages) return;
|
||||
setCurrentIndex((prev) => (prev === images.length - 1 ? 0 : prev + 1));
|
||||
};
|
||||
|
||||
// Handle thumbnail click
|
||||
const handleThumbnailClick = (index, e) => {
|
||||
if (e) e.stopPropagation();
|
||||
setCurrentIndex(index);
|
||||
};
|
||||
|
||||
// Touch event handlers
|
||||
const handleTouchStart = (e) => {
|
||||
touchStartX.current = e.touches[0].clientX;
|
||||
};
|
||||
|
||||
const handleTouchMove = (e) => {
|
||||
touchEndX.current = e.touches[0].clientX;
|
||||
};
|
||||
|
||||
const handleTouchEnd = () => {
|
||||
if (!hasMultipleImages) return;
|
||||
|
||||
const touchDiff = touchStartX.current - touchEndX.current;
|
||||
|
||||
// Swipe threshold - only respond to intentional swipes
|
||||
if (Math.abs(touchDiff) > 50) {
|
||||
if (touchDiff > 0) {
|
||||
// Swipe left -> Next image
|
||||
handleNext();
|
||||
} else {
|
||||
// Swipe right -> Previous image
|
||||
handlePrev();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Apply transition effect using CSS
|
||||
useEffect(() => {
|
||||
if (carouselRef.current) {
|
||||
carouselRef.current.classList.add(styles.transitioning);
|
||||
|
||||
const timer = setTimeout(() => {
|
||||
if (carouselRef.current) {
|
||||
carouselRef.current.classList.remove(styles.transitioning);
|
||||
}
|
||||
}, 900); // Match this timing with CSS transition duration
|
||||
|
||||
return () => clearTimeout(timer);
|
||||
}
|
||||
}, [currentIndex]);
|
||||
|
||||
// If there's only one image, just show it - applying different classes based on view
|
||||
if (!hasMultipleImages) {
|
||||
return (
|
||||
<div className={isDetailView ? styles.fixedFrameContainer : undefined}>
|
||||
<img
|
||||
src={currentImage || "/placeholder.svg"}
|
||||
alt={altText || "Ürün resmi"}
|
||||
className={`${styles.productImage} ${
|
||||
isDetailView ? styles.detailImage : styles.cardImage
|
||||
}`}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`${styles.carouselWrapper} ${
|
||||
isDetailView ? styles.detailCarousel : ""
|
||||
}`}
|
||||
>
|
||||
<div
|
||||
className={styles.carouselContainer}
|
||||
onTouchStart={handleTouchStart}
|
||||
onTouchMove={handleTouchMove}
|
||||
onTouchEnd={handleTouchEnd}
|
||||
>
|
||||
<div
|
||||
ref={carouselRef}
|
||||
className={`${styles.imageWrapper} ${
|
||||
isDetailView ? styles.fixedFrameContainer : ""
|
||||
}`}
|
||||
>
|
||||
<img
|
||||
src={currentImage || "/placeholder.svg"}
|
||||
alt={altText || "Ürün resmi"}
|
||||
className={`${styles.productImage} ${
|
||||
isDetailView ? styles.detailImage : styles.cardImage
|
||||
}`}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Navigation arrows */}
|
||||
<button
|
||||
onClick={handlePrev}
|
||||
className={`${styles.arrowButton} ${styles.leftArrow}`}
|
||||
aria-label="Önceki resim"
|
||||
>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="16"
|
||||
height="16"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
>
|
||||
<polyline points="15 18 9 12 15 6"></polyline>
|
||||
</svg>
|
||||
</button>
|
||||
|
||||
<button
|
||||
onClick={handleNext}
|
||||
className={`${styles.arrowButton} ${styles.rightArrow}`}
|
||||
aria-label="Sonraki resim"
|
||||
>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="16"
|
||||
height="16"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
>
|
||||
<polyline points="9 18 15 12 9 6"></polyline>
|
||||
</svg>
|
||||
</button>
|
||||
|
||||
{/* Indicators (dots) */}
|
||||
<div className={styles.indicators}>
|
||||
{images.map((_, idx) => (
|
||||
<span
|
||||
key={idx}
|
||||
className={`${styles.indicator} ${
|
||||
currentIndex === idx ? styles.active : ""
|
||||
}`}
|
||||
onClick={(e) => handleThumbnailClick(idx, e)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Thumbnails - only show if showThumbnails is true */}
|
||||
{showThumbnails && (
|
||||
<div className={styles.thumbnailContainer}>
|
||||
{images.map((image, idx) => (
|
||||
<div
|
||||
key={idx}
|
||||
className={`${styles.thumbnail} ${
|
||||
currentIndex === idx ? styles.activeThumbnail : ""
|
||||
}`}
|
||||
onClick={(e) => handleThumbnailClick(idx, e)}
|
||||
>
|
||||
<img
|
||||
src={
|
||||
image.thumbnail || image.images_400x400 || "/placeholder.svg"
|
||||
}
|
||||
alt={`${altText || "Ürün"} thumbnail ${idx + 1}`}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ImageCarousel;
|
||||
Reference in New Issue
Block a user