91 lines
2.6 KiB
TypeScript
91 lines
2.6 KiB
TypeScript
import {
|
|
ChevronLeft,
|
|
ChevronRight,
|
|
ChevronUp,
|
|
ChevronDown,
|
|
} from "lucide-react";
|
|
|
|
import useDeviceType from "@/hooks/use-device-type";
|
|
|
|
interface CarouselControlsProps {
|
|
total: number;
|
|
activeIndex: number;
|
|
color?: string;
|
|
dotColor?: string;
|
|
orientation?: "horizontal" | "vertical";
|
|
onPrev: () => void;
|
|
onNext: () => void;
|
|
onSelect: (index: number) => void;
|
|
}
|
|
|
|
export default function CarouselControls({
|
|
total,
|
|
activeIndex,
|
|
color = "text-white border-white hover:bg-white/10",
|
|
dotColor = "bg-white",
|
|
orientation = "horizontal",
|
|
onPrev,
|
|
onNext,
|
|
onSelect,
|
|
}: Readonly<CarouselControlsProps>) {
|
|
const { isMobile } = useDeviceType();
|
|
const isVertical = orientation === "vertical";
|
|
|
|
const chevronSize = isMobile ? "h-11 w-11" : "h-[50px] w-[50px]";
|
|
const activeDotSize = isMobile ? "h-[38px] w-[38px]" : "h-[50px] w-[50px]";
|
|
const inactiveDotSize = isVertical
|
|
? isMobile
|
|
? "w-3 h-8"
|
|
: "w-4 h-11"
|
|
: isMobile
|
|
? "h-3 w-8"
|
|
: "h-4 w-11";
|
|
|
|
const PrevIcon = isVertical ? ChevronUp : ChevronLeft;
|
|
const NextIcon = isVertical ? ChevronDown : ChevronRight;
|
|
|
|
return (
|
|
<div
|
|
className={`flex items-center justify-center ${isVertical ? "flex-col" : ""} ${isMobile ? "gap-2" : "gap-8"}`}
|
|
>
|
|
<button
|
|
type="button"
|
|
onClick={onPrev}
|
|
aria-label="Précédent"
|
|
className={`flex cursor-pointer items-center justify-center rounded-full border-4 transition-colors ${chevronSize} ${color}`}
|
|
>
|
|
<PrevIcon size={isMobile ? 24 : 28} strokeWidth={3} />
|
|
</button>
|
|
|
|
<div
|
|
className={`flex items-center ${isVertical ? "flex-col gap-2 lg:gap-3" : "gap-2 lg:gap-4"}`}
|
|
>
|
|
{Array.from({ length: total }).map((_, index) => (
|
|
<button
|
|
// eslint-disable-next-line @eslint-react/no-array-index-key
|
|
key={index}
|
|
type="button"
|
|
onClick={() => {
|
|
onSelect(index);
|
|
}}
|
|
aria-label={`Aller à l'élément ${String(index + 1)}`}
|
|
className={`rounded-full transition-all ${
|
|
index === activeIndex
|
|
? `${activeDotSize} bg-rouge`
|
|
: `${inactiveDotSize} ${dotColor}`
|
|
}`}
|
|
/>
|
|
))}
|
|
</div>
|
|
|
|
<button
|
|
type="button"
|
|
onClick={onNext}
|
|
aria-label="Suivant"
|
|
className={`flex cursor-pointer items-center justify-center rounded-full border-4 transition-colors ${chevronSize} ${color}`}
|
|
>
|
|
<NextIcon size={isMobile ? 24 : 28} strokeWidth={3} />
|
|
</button>
|
|
</div>
|
|
);
|
|
}
|