ldc-bien-etre-animal/resources/ts/front/Components/Shared/SliderCustomCard.tsx
2026-09-04 19:40:48 +02:00

158 lines
4.7 KiB
TypeScript

import { ArrowRight } from "lucide-react";
import { type ReactNode, useState } from "react";
import flipIcon from "&/images/globals/flipIcon.png";
import CtaButton from "@/front/Components/Layout/CtaButton";
import { cardType, type CardTypeName } from "@/front/lib/constants";
import useDeviceType from "@/hooks/use-device-type";
type CardState = "active" | "inactive";
interface StyleConfig {
size: string;
numberText: string;
titleText: string;
}
export interface CommunityCardProps {
number: string;
title: string;
type?: CardTypeName;
isActive?: boolean;
rotation?: number;
compactRotation?: number;
ctaLabel?: string;
ctaHref?: string;
onCtaClick?: () => void;
// for flip animation
verso?: ReactNode;
className?: string;
}
const CARD_STYLES: Record<CardTypeName, Record<CardState, StyleConfig>> = {
default: {
active: {
size: "w-full max-w-[294px] lg:max-w-none lg:w-[310px] h-[370px] lg:h-[450px] scale-105",
numberText: "lg:text-[128px] text-[96px]",
titleText: "text-[24px] lg:text-h3 leading-6 lg:leading-9",
},
inactive: {
size: "w-full max-w-[180px] lg:max-w-none lg:w-[300px] lg:h-[400px] scale-95",
numberText: "text-[96px]",
titleText: "text-[22px] leading-6 lg:leading-9",
},
},
cta: {
active: {
size: "w-full max-w-[278px] lg:max-w-none lg:w-[300px] h-[397px] lg:h-[400px] scale-105",
numberText: "text-[96px]",
titleText: "text-[20px] lg:text-[22px] leading-6 lg:leading-7",
},
inactive: {
size: "w-full max-w-[278px] lg:max-w-none lg:w-[300px] lg:h-[400px] scale-95",
numberText: "text-[96px]",
titleText: "text-[20px] lg:text-[22px] leading-6 lg:leading-7",
},
},
flip: {
active: {
size: "w-full max-w-[320px] h-[400px] lg:max-w-none lg:w-[330px] scale-105",
numberText: "lg:text-[128px] text-[96px]",
titleText: "text-[24px] lg:text-[22px] leading-6 lg:leading-9",
},
inactive: {
size: "w-full max-w-[180px] h-[400px] lg:max-w-none lg:w-[280px] scale-95",
numberText: "text-[96px]",
titleText: "text-[24px] lg:text-[22px] leading-6 lg:leading-9",
},
},
};
export default function SliderCustomCard({
number,
title,
type = cardType.DEFAULT,
isActive = false,
rotation = 3,
compactRotation = 2,
ctaLabel = "En savoir plus",
ctaHref,
onCtaClick,
verso,
className = "",
}: Readonly<CommunityCardProps>) {
const { isMobile, isTablet } = useDeviceType();
const isCompact = isMobile || isTablet;
const effectiveRotation = isCompact ? compactRotation : rotation;
const effectiveIsActive = isCompact ? true : isActive;
const isBlue = type === "cta" || type === "flip";
const textColor = isBlue ? "text-white" : "text-bleu";
const bgColor = isBlue
? "bg-bleu"
: effectiveIsActive
? "bg-white"
: "bg-[#D9D8E8]";
const styles = CARD_STYLES[type][effectiveIsActive ? "active" : "inactive"];
// for flip
const [isFlipped, setIsFlipped] = useState(false);
return (
<div
className={`drop-shadow-card relative flex shrink-0 flex-col items-center justify-center gap-6 rounded-[10px] p-8 transition-all duration-300 ${bgColor} ${styles.size} ${className}`}
style={{ transform: `rotate(${String(effectiveRotation)}deg)` }}
>
{type === "flip" && (
<button
type="button"
onClick={() => {
setIsFlipped((prev) => !prev);
}}
aria-label=""
className="absolute bottom-4 right-4 flex h-8 w-8 cursor-pointer items-center justify-center text-white transition-colors hover:text-white/80 "
>
<img
src={flipIcon}
alt="Icône de retournement de carte"
className="h-8"
/>
</button>
)}
{type === "flip" && isFlipped ? (
<p
className="text-center font-poppins-regular text-[12px] text-white py-4 [&_li]:list-inside"
dangerouslySetInnerHTML={{ __html: verso ?? "" }}
/>
) : (
<>
<p
className={`font-poppins-bold leading-none ${textColor} ${styles.numberText}`}
>
{number}
</p>
<p
className={`text-center font-lato-bold ${textColor} ${styles.titleText} ${type === "flip" ? "uppercase" : ""}`}
>
{title}
</p>
</>
)}
{type === "cta" && (
<CtaButton
onClick={onCtaClick}
icon={<ArrowRight />}
iconPosition="right"
color="rouge"
size={isMobile ? "sm" : isTablet ? "md" : "lg"}
className="mt-6"
href={ctaHref}
>
{ctaLabel}
</CtaButton>
)}
</div>
);
}