x
This commit is contained in:
1 parent
62dec90f82
commit
9aea635e64
2 files changed
+12
-12
No files matched your search
@@ -12,15 +12,15 @@ export default function ProductImageGallery({ images, fallback, alt = 'Product I
|
|||||||
const [currentIndex, setCurrentIndex] = useState(0)
|
const [currentIndex, setCurrentIndex] = useState(0)
|
||||||
const scrollRef = useRef<HTMLDivElement>(null)
|
const scrollRef = useRef<HTMLDivElement>(null)
|
||||||
|
|
||||||
useEffect(() => {
|
const handleThumbnailClick = (idx: number) => {
|
||||||
|
setCurrentIndex(idx)
|
||||||
if (scrollRef.current) {
|
if (scrollRef.current) {
|
||||||
const container = scrollRef.current
|
const child = scrollRef.current.children[idx] as HTMLElement
|
||||||
const child = container.children[currentIndex] as HTMLElement
|
|
||||||
if (child) {
|
if (child) {
|
||||||
container.scrollTo({ left: child.offsetLeft, behavior: 'smooth' })
|
scrollRef.current.scrollTo({ left: child.offsetLeft, behavior: 'smooth' })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [currentIndex])
|
}
|
||||||
|
|
||||||
const handleScroll = (e: React.UIEvent<HTMLDivElement>) => {
|
const handleScroll = (e: React.UIEvent<HTMLDivElement>) => {
|
||||||
const container = e.currentTarget
|
const container = e.currentTarget
|
||||||
@@ -66,7 +66,7 @@ export default function ProductImageGallery({ images, fallback, alt = 'Product I
|
|||||||
<button
|
<button
|
||||||
key={image.id || idx}
|
key={image.id || idx}
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => setCurrentIndex(idx)}
|
onClick={() => handleThumbnailClick(idx)}
|
||||||
className={`relative aspect-square w-20 md:w-full flex-none overflow-hidden rounded-2xl border-2 transition-all snap-center ${
|
className={`relative aspect-square w-20 md:w-full flex-none overflow-hidden rounded-2xl border-2 transition-all snap-center ${
|
||||||
currentIndex === idx ? 'border-pop-pink shadow-md' : 'border-transparent opacity-60 hover:opacity-100'
|
currentIndex === idx ? 'border-pop-pink shadow-md' : 'border-transparent opacity-60 hover:opacity-100'
|
||||||
}`}
|
}`}
|
||||||
|
|||||||
@@ -13,15 +13,15 @@ export default function ProductGallery({ productName, categoryName, images }: Pr
|
|||||||
const [activeIndex, setActiveIndex] = useState(0)
|
const [activeIndex, setActiveIndex] = useState(0)
|
||||||
const scrollRef = useRef<HTMLDivElement>(null)
|
const scrollRef = useRef<HTMLDivElement>(null)
|
||||||
|
|
||||||
useEffect(() => {
|
const handleThumbnailClick = (idx: number) => {
|
||||||
|
setActiveIndex(idx)
|
||||||
if (scrollRef.current) {
|
if (scrollRef.current) {
|
||||||
const container = scrollRef.current
|
const child = scrollRef.current.children[idx] as HTMLElement
|
||||||
const child = container.children[activeIndex] as HTMLElement
|
|
||||||
if (child) {
|
if (child) {
|
||||||
container.scrollTo({ left: child.offsetLeft, behavior: 'smooth' })
|
scrollRef.current.scrollTo({ left: child.offsetLeft, behavior: 'smooth' })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [activeIndex])
|
}
|
||||||
|
|
||||||
const handleScroll = (e: React.UIEvent<HTMLDivElement>) => {
|
const handleScroll = (e: React.UIEvent<HTMLDivElement>) => {
|
||||||
const container = e.currentTarget
|
const container = e.currentTarget
|
||||||
@@ -65,7 +65,7 @@ export default function ProductGallery({ productName, categoryName, images }: Pr
|
|||||||
<button
|
<button
|
||||||
key={idx}
|
key={idx}
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => setActiveIndex(idx)}
|
onClick={() => handleThumbnailClick(idx)}
|
||||||
className={`relative aspect-square w-20 md:w-full flex-none overflow-hidden rounded-2xl border-2 transition-all snap-center ${
|
className={`relative aspect-square w-20 md:w-full flex-none overflow-hidden rounded-2xl border-2 transition-all snap-center ${
|
||||||
activeIndex === idx ? 'border-brand-primary opacity-100' : 'border-transparent opacity-60 hover:opacity-100'
|
activeIndex === idx ? 'border-brand-primary opacity-100' : 'border-transparent opacity-60 hover:opacity-100'
|
||||||
}`}
|
}`}
|
||||||
|
|||||||
Reference in new issue
Block a user