import React, { useEffect, useRef } from 'react'; import { IconChevronDown } from '../Icon'; import { useAppNavContext } from './context'; export interface IAppNavMenuItem { link?: string; title: string; className?: string; isParent?: boolean; icon?: JSX.Element; visible?: boolean; onClick?(): void; [x: string]: any; } export const AppNavMenuItem: React.FC = (props) => { const { setUpdated } = useAppNavContext(); const { children, link = '#', title = '', className = '', isParent = false, icon, visible = null, onClick, ...otherProps } = props; const refMenuItem = useRef(null); function handleClick(e: React.MouseEvent) { e.preventDefault(); onClick && onClick(); } useEffect(() => { if (isParent && refMenuItem.current && visible !== false) { refMenuItem.current.dataset.parent = 'true'; } if (visible !== null && visible !== false) { setUpdated(); } }, [visible]); if (visible === false) { return null; } else { return (
  • handleClick(e)}> {icon && {icon}} {title} {isParent && } {children}
  • ); } };