import { ChevronDownIcon, ChevronUpIcon } from "@heroicons/react/24/solid"; import { usePageContext } from "vike-react/usePageContext"; import { Link } from "@/components/common/Link"; import { navigation } from "@/lib/navigation"; import { useState } from "react"; import clsx from "clsx"; type NavigationItemProps = { section: (typeof navigation)[number]; onLinkClick?: React.MouseEventHandler; }; function NavigationItem(props: NavigationItemProps) { const { urlPathname } = usePageContext(); const [isOpened, setIsOpened] = useState(() => { return props.section.links.some( (link) => link.href === urlPathname || link.subitems?.some((subitem) => subitem.href === urlPathname), ); }); return ( <>

{ if (e.key === "Enter" || e.key === " ") { setIsOpened((prev) => !prev); e.preventDefault(); } }} className={clsx( "font-display font-medium cursor-pointer", isOpened ? "text-violet-600 dark:text-violet-200" : "text-slate-900 dark:text-white ", )} onClick={() => setIsOpened((prev) => !prev)} > {isOpened ? ( ) : ( )} {isOpened ? "Masquer" : "Afficher"} {props.section.title} ({props.section.links.length})

{isOpened && ( )} ); } export function Navigation({ className, onLinkClick, }: { className?: string; onLinkClick?: React.MouseEventHandler; }) { const firstSections = navigation.filter((section) => section.position === "start"); const filteredSections = navigation .filter((section) => section.position === "auto" || section.position === undefined) .reduce( (acc, section) => { if (!acc[section.type]) { acc[section.type] = []; } acc[section.type].push(section); return acc; }, {} as Record, ); return ( ); }