Updates after merge

This commit is contained in:
Catalin Pinte 2022-12-22 09:36:30 +02:00
parent 4276ba147b
commit 1330bc3162
3 changed files with 7 additions and 35 deletions

View File

@ -17,15 +17,11 @@
} }
.imageContainer { .imageContainer {
@apply text-center h-full relative flex-shrink-0; @apply flex items-center justify-center w-full h-full relative flex-shrink-0;
}
.imageContainer > span {
height: 100% !important;
} }
.sliderContainer .img { .sliderContainer .img {
@apply w-full h-full max-h-full object-cover transition duration-500 ease-in-out; @apply object-cover h-full;
} }
.button { .button {

View File

@ -18,11 +18,7 @@
} }
.thumb img { .thumb img {
@apply w-full h-full object-cover transition duration-300; @apply h-full w-full object-cover transition duration-500;
}
.thumb:hover img {
@apply scale-105;
} }
.album { .album {

View File

@ -10,8 +10,6 @@ import cn from 'clsx'
import { a } from '@react-spring/web' import { a } from '@react-spring/web'
import s from './ProductSlider.module.css' import s from './ProductSlider.module.css'
import ProductSliderControl from '../ProductSliderControl' import ProductSliderControl from '../ProductSliderControl'
import { useProduct } from '../context'
import { Image as ProductImage } from '@commerce/types/common'
interface ProductSliderProps { interface ProductSliderProps {
children?: React.ReactNode[] children?: React.ReactNode[]
@ -22,9 +20,7 @@ const ProductSlider: React.FC<ProductSliderProps> = ({
children, children,
className = '', className = '',
}) => { }) => {
const { product, variant } = useProduct()
const [currentSlide, setCurrentSlide] = useState(0) const [currentSlide, setCurrentSlide] = useState(0)
const sliderContainerRef = useRef<HTMLDivElement>(null) const sliderContainerRef = useRef<HTMLDivElement>(null)
const thumbsContainerRef = useRef<HTMLDivElement>(null) const thumbsContainerRef = useRef<HTMLDivElement>(null)
@ -34,6 +30,7 @@ const ProductSlider: React.FC<ProductSliderProps> = ({
slideChanged(s) { slideChanged(s) {
const slideNumber = s.track.details.rel const slideNumber = s.track.details.rel
setCurrentSlide(slideNumber) setCurrentSlide(slideNumber)
if (thumbsContainerRef.current) { if (thumbsContainerRef.current) {
const $el = document.getElementById(`thumb-${slideNumber}`) const $el = document.getElementById(`thumb-${slideNumber}`)
if (slideNumber >= 3) { if (slideNumber >= 3) {
@ -45,18 +42,6 @@ const ProductSlider: React.FC<ProductSliderProps> = ({
}, },
}) })
useEffect(() => {
const index = product.images.findIndex((image: ProductImage) => {
return image.url === variant?.image?.url
})
if (index !== -1) {
slider.current?.moveToIdx(index, false, {
duration: 0,
})
}
}, [variant, product, slider])
// Stop the history navigation gesture on touch devices // Stop the history navigation gesture on touch devices
useEffect(() => { useEffect(() => {
const preventNavigation = (event: TouchEvent) => { const preventNavigation = (event: TouchEvent) => {
@ -87,13 +72,8 @@ const ProductSlider: React.FC<ProductSliderProps> = ({
} }
}, []) }, [])
const onPrev = React.useCallback(() => { const onPrev = React.useCallback(() => slider.current?.prev(), [slider])
slider.current?.prev() const onNext = React.useCallback(() => slider.current?.next(), [slider])
}, [slider])
const onNext = React.useCallback(() => {
slider.current?.next()
}, [slider])
return ( return (
<div className={cn(s.root, className)} ref={sliderContainerRef}> <div className={cn(s.root, className)} ref={sliderContainerRef}>
@ -124,7 +104,7 @@ const ProductSlider: React.FC<ProductSliderProps> = ({
...child, ...child,
props: { props: {
...child.props, ...child.props,
className: cn(child.props.className, s.thumb, { className: cn(s.thumb, {
[s.selected]: currentSlide === idx, [s.selected]: currentSlide === idx,
}), }),
id: `thumb-${idx}`, id: `thumb-${idx}`,