Merged in fix/remove-deafult-centering-behaviour-in-carousels (pull request #1543)
refactor(SW-1941): clean up custom Carousel component centering * refactor: clean up custom Carousel component centering - Removed unused centerContent class from carousel.module.css. - Simplified CarouselContent component by eliminating unnecessary state and effect hooks. - Updated HotelCardCarousel to include responsive breakpoints for scrolling behavior. * refactor: simplify scrolling options in HotelCardCarousel - Updated the HotelCardCarousel component to streamline scrolling options by removing responsive breakpoints and setting containScroll to false. Approved-by: Matilda Landström
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import { cx } from "class-variance-authority"
|
import { cx } from "class-variance-authority"
|
||||||
import { useEffect, useState } from "react"
|
|
||||||
|
|
||||||
import { useCarousel } from "./CarouselContext"
|
import { useCarousel } from "./CarouselContext"
|
||||||
|
|
||||||
@@ -12,21 +11,11 @@ export function CarouselContent({
|
|||||||
children,
|
children,
|
||||||
...props
|
...props
|
||||||
}: React.HTMLAttributes<HTMLDivElement>) {
|
}: React.HTMLAttributes<HTMLDivElement>) {
|
||||||
const { carouselRef, canScrollNext, canScrollPrev } = useCarousel()
|
const { carouselRef } = useCarousel()
|
||||||
const [isOneItem, setIsOneItem] = useState(false)
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setIsOneItem(!canScrollPrev() && !canScrollNext())
|
|
||||||
}, [canScrollPrev, canScrollNext])
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div ref={carouselRef} className={styles.viewport}>
|
<div ref={carouselRef} className={styles.viewport}>
|
||||||
<div
|
<div className={cx(styles.container, className)} {...props}>
|
||||||
className={cx(styles.container, className, {
|
|
||||||
[styles.centerContent]: isOneItem,
|
|
||||||
})}
|
|
||||||
{...props}
|
|
||||||
>
|
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -13,10 +13,6 @@
|
|||||||
gap: var(--Spacing-x2);
|
gap: var(--Spacing-x2);
|
||||||
}
|
}
|
||||||
|
|
||||||
.centerContent {
|
|
||||||
justify-content: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.item {
|
.item {
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ export default function HotelCardCarousel({
|
|||||||
className={styles.carousel}
|
className={styles.carousel}
|
||||||
scrollToIdx={selectedHotelIdx}
|
scrollToIdx={selectedHotelIdx}
|
||||||
align="center"
|
align="center"
|
||||||
|
opts={{ containScroll: false }}
|
||||||
>
|
>
|
||||||
<Carousel.Content className={styles.carouselContent}>
|
<Carousel.Content className={styles.carouselContent}>
|
||||||
{visibleHotels.map(({ hotel, url }) => (
|
{visibleHotels.map(({ hotel, url }) => (
|
||||||
|
|||||||
Reference in New Issue
Block a user