diff --git a/components/shared/Carousel/v2/Carousel.tsx b/components/shared/Carousel/v2/Carousel.tsx index aaed1570..5c010fd7 100644 --- a/components/shared/Carousel/v2/Carousel.tsx +++ b/components/shared/Carousel/v2/Carousel.tsx @@ -1,22 +1,23 @@ -import { FC, useState } from "react"; +import { CSSProperties, FC, useEffect, useRef, useState } from "react"; import Icon from "../../Icon/v2/Icon"; -import { cn } from "@/lib/utils"; interface CarouselProps< - T extends Record, - K extends keyof T = keyof T, + Item extends Record, + Key extends keyof Item = keyof Item, > { - items: (T & Record)[]; - uniqueKey: K; - Component: FC; + items: (Item & Record)[]; + uniqueKey: Key; + Component: FC; } -export default function Carousel>({ +export default function Carousel>({ items, uniqueKey, Component, -}: Readonly>) { +}: Readonly>) { const [showIndex, setShowIndex] = useState(0); + const [maxWidth, setMaxWidth] = useState(0); + const carouselRef = useRef(null); const handleChangePage = (action: "prev" | "next") => () => { const maxIndex = items.length - 1; @@ -42,6 +43,10 @@ export default function Carousel>({ "p-2.5 shrink-0 bg-white/4 shadow-default rounded-2xl"; const buttonIconClassName = "stroke-white w-6 h-6 pointer-events-none"; + useEffect(() => { + setMaxWidth(carouselRef.current?.clientWidth || 0); + }, []); + return (
-
    - {Array.isArray(items) && - items.map((item, index) => ( -
  • - -
  • - ))} -
+
+
    + {Array.isArray(items) && + items.map((item) => ( +
  • + +
  • + ))} +
+
+
- - - ); }