ldc-bien-etre-animal/resources/ts/front/Components/Shared/Carousel/CustomPagination.tsx

91 lines
2.7 KiB
TypeScript

import { ChevronLeft, ChevronRight } from "lucide-react";
import useDeviceType from "@/hooks/use-device-type";
import { cn, GetTranslation } from "@/lib/utils";
export default function CustomPagination({
count,
color = "text-bleu border-bleu hover:bg-bleu/10",
dotColor = "bg-bleu",
activeIndex,
onClick,
handlePrev,
handleNext,
isEnd = false,
isBeginning = true,
}: {
count: number;
color?: string;
dotColor?: string;
activeIndex: number;
onClick: (index: number) => void;
isEnd?: boolean;
isBeginning?: boolean;
handlePrev: () => void;
handleNext: () => void;
}) {
const { isMobile } = useDeviceType();
const chevronSize = isMobile ? "h-11 w-11" : "h-[50px] w-[50px]";
const activeDotSize = isMobile ? "h-[38px] w-[38px]" : "h-[50px] w-[50px]";
const inactiveDotSize = isMobile
? count > 7
? "h-2.5 w-4"
: "h-3 w-8"
: "h-4 w-11";
return (
<div className="mt-4 flex items-center justify-center gap-2 sm:gap-4">
<button
type="button"
onClick={handlePrev}
disabled={isBeginning}
className={cn(
"disabled:opacity-0 disabled:pointer-events-none flex cursor-pointer items-center justify-center rounded-full border-4 transition-colors",
chevronSize,
color,
)}
>
<ChevronLeft size={isMobile ? 24 : 28} strokeWidth={3} />
</button>
<div className="flex items-center justify-center">
{Array.from({ length: count }).map((_, index) => {
const activeSlide = index === activeIndex;
return (
<button
// eslint-disable-next-line @eslint-react/no-array-index-key
key={index}
type="button"
onClick={() => {
onClick(index);
}}
aria-label={GetTranslation("front.slider_pagination_goto", {
params: { target: String(index + 1) },
})}
className={cn(
"mx-1 rounded-full transition-all",
activeSlide
? `${activeDotSize} bg-rouge`
: `${inactiveDotSize} cursor-pointer ${dotColor}`,
)}
disabled={activeSlide}
/>
);
})}
</div>
<button
type="button"
onClick={handleNext}
disabled={isEnd}
className={cn(
"disabled:opacity-0 disabled:pointer-events-none flex cursor-pointer items-center justify-center rounded-full border-4 transition-colors",
chevronSize,
color,
)}
>
<ChevronRight size={isMobile ? 24 : 28} strokeWidth={3} />
</button>
</div>
);
}