diff --git a/app/components/common/Link.tsx b/app/components/common/Link.tsx index a01dbbc..1dc34f5 100644 --- a/app/components/common/Link.tsx +++ b/app/components/common/Link.tsx @@ -5,13 +5,15 @@ export function Link(props: React.AnchorHTMLAttributes & { hr const { urlPathname } = usePageContext(); const isActive = props.href === "/" ? urlPathname === props.href : urlPathname.startsWith(props.href); const isSameDomain = !(props.href.startsWith("http") || props.href.startsWith("mailto")); + const isDownload = props.href.endsWith(".pdf") || props.href.endsWith(".zip"); return ( {props.children} diff --git a/app/components/syntax/Navigation.tsx b/app/components/syntax/Navigation.tsx index 3f70ec5..64b41dc 100644 --- a/app/components/syntax/Navigation.tsx +++ b/app/components/syntax/Navigation.tsx @@ -1,8 +1,105 @@ +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, @@ -10,35 +107,35 @@ export function Navigation({ className?: string; onLinkClick?: React.MouseEventHandler; }) { - const { urlPathname } = usePageContext(); + 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 (