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

63 lines
1.6 KiB
TypeScript

import useDeviceType from "@/hooks/use-device-type";
interface PhotoCardSize {
width: number;
height: number;
}
interface PhotoCardProps {
image: string;
imageWebp?: string;
caption?: string;
rotation?: number;
size?: PhotoCardSize;
sizeLg?: PhotoCardSize;
width?: number;
height?: number;
className?: string;
}
export default function PhotoCard({
image,
imageWebp,
caption,
rotation = 4,
size = { width: 339, height: 241 },
sizeLg = { width: 969, height: 691 },
width,
height,
className = "",
}: Readonly<PhotoCardProps>) {
const { isMobile, isTablet } = useDeviceType();
const isCompact = isMobile || isTablet;
const computedSize = isCompact ? size : sizeLg;
const finalWidth = width ?? computedSize.width;
const finalHeight = height ?? computedSize.height;
return (
<div
className={`flex max-w-full shrink-0 flex-col items-center gap-2 transition-all duration-300 ${className}`}
style={{ width: finalWidth, maxWidth: "100%" }}
>
<div
className="w-full overflow-hidden rounded-[20px] bg-[#4E4E4E]"
style={{
aspectRatio: `${String(finalWidth)} / ${String(finalHeight)}`,
transform: `rotate(${String(rotation)}deg)`,
}}
>
<picture>
{imageWebp && <source srcSet={imageWebp} type="image/webp" />}
<img src={image} alt="" className="h-full w-full object-cover" />
</picture>
</div>
{caption && (
<p className="mt-4 w-full text-left font-poppins-light text-[12px] italic leading-[18px] text-bleu">
{caption}
</p>
)}
</div>
);
}