import { useContext, useState, Fragment } from "react"; import { generatePath, Link } from "react-router-dom"; import { KeyboardArrowDown, KeyboardArrowUp } from "@rimble/icons"; import { Flex, Text } from "rimble-ui"; import { SertoUiContext, SertoUiContextInterface } from "../../../context/SertoUiContext"; import { baseColors, colors } from "../../../themes"; import { NavItemPrimary, NavItemStyled, NavItemTabsStyled, SubNavItemStyled } from "./NavComponents"; export interface NavProps { currentUrl: string; hasPermissions?: boolean; navItems?: NavItemProps[]; currentSection?: string; } export const Nav: React.FunctionComponent = (props) => { const context = useContext(SertoUiContext); const navItems = props.navItems || context.navItems; return ( <> {navItems?.map((navItemProps) => ( ))} ); }; // props from SertoUiWrapper navItem export interface NavItemProps { icon: React.FunctionComponent; section?: string; subNav?: any[]; text: string; url: string; } // props from Global Layout export interface NavItemGlobalProps { currentSection?: string; currentUrl: string; hasPermissions?: boolean; } const NavItem: React.FunctionComponent = (props) => { const { currentSection, currentUrl, hasPermissions, icon, section, subNav, text, url } = props; const sectionActive = section ? section === currentSection : url === currentUrl; const [isOpen, setIsOpen] = useState(sectionActive); if (subNav) { return ( setIsOpen(!isOpen)} p="8px" width="100%" > {isOpen ? : } {isOpen && subNav?.map((tab: any, i: number) => { const subNavActive = currentUrl === tab.url; if (tab.admin && !hasPermissions) { return ; } return ( {tab.text} ); })} ); } return ( ); };