import React, { useRef } from "react"; import { useOnClickOutside, useToggle } from "usehooks-ts"; import { cn, isHoverable } from "@/utils/helpers"; import ReactMarkdown from "react-markdown"; import Balancer from "react-wrap-balancer"; import Link from "next/link"; import { useRouter } from "next/router"; import { type LinkIcon, LinkIcons } from "@/utils/types"; import DependentImage from "@/components/DependentImage"; type ItemCardProps = { banner: string; bannerSettings?: { quality: number }; title: string; description: string; links?: LinkIcon[]; location: string; }; const ItemCard = ({ banner, title, description, links, location, bannerSettings, }: ItemCardProps) => { const itemRef = useRef(null); const mobileButtonRef = useRef(null); const [active, toggleActive, setActive] = useToggle(); const router = useRouter(); // @ts-expect-error Some kind of regression in usehooks-ts causes the useOnClickOutside hook to not accept 'null' types useOnClickOutside(itemRef, (event) => { if ( mobileButtonRef.current != null && mobileButtonRef.current?.contains(event.target as Node) ) return; else setActive(false); }); const navigate = () => { if (!isHoverable()) toggleActive(); else { router.push(location); } }; return ( <>
cn("object-cover", loaded ? null : "blur-xl") } alt={`Banner for ${title}`} />
{title}
{ e.stopPropagation(); navigate(); }} > {description}
{(links?.length ?? 0) > 0 ? (
{links!.map(({ icon, location, newTab }) => ( e.stopPropagation()} > {LinkIcons[icon]?.({})} ))}
) : null}
Learn More ); }; export default ItemCard;