import { Link } from "@onegeo-suite/gatsby-theme-onegeo" import { graphql, useStaticQuery } from "gatsby" import React from "react" interface Imenu { className?: string name: string } const Menu = (props: Imenu) => { const { className, name } = props const data = useStaticQuery(graphql` fragment MenuItem on DirectusData_menus { name url page { slug } } fragment MenusRecursive on DirectusData_menus { children { ...MenuItem children { ...MenuItem children { ...MenuItem } } } } query { directus { menus(filter: { status: { _eq: "published" } }) { name ...MenusRecursive } } } `) const menuContent = data.directus.menus const menu = menuContent.find( (menu: any) => name?.toLowerCase() === menu.name?.toLowerCase() )?.children || [] const items = (item: any) => { return ( <ul className="bg-base-100 z-50 p-2 shadow-md"> {item.children.map((itemChild: any, idx: number) => { return ( <li key={idx}> <Link to={ itemChild.url ? itemChild.url : itemChild.page?.slug ? itemChild.page?.slug : "#" } > {itemChild.name} </Link> {itemChild?.children?.length > 0 && items(itemChild)} </li> ) })} </ul> ) } return ( <> {/* MENU standart */} <ul className={className}> {menu?.map((item: any, key: number) => { return ( <li key={key}> <Link to={ item.url ? item.url : item.page?.slug ? item.page?.slug : "#" } > {item.name} {item?.children.length > 0 && ( <svg className="fill-current" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" > <path d="M7.41,8.58L12,13.17L16.59,8.58L18,10L12,16L6,10L7.41,8.58Z" /> </svg> )} </Link> {item?.children?.length > 0 && items(item)} </li> ) })} </ul> {/* END MENU standart */} </> ) } export default Menu