import React, { useState, useEffect } from "react"; import { FunctionComponent } from "react"; import * as NavType from "./../type"; import { LinkButton, ButtonSize } from "./../../UI/Button"; export const NavigationBarItem: FunctionComponent<{ item: NavType.NavigationItem; }> = ({ item }) => { switch (item.schema) { case NavType.NAVIGATION_ITEM_TYPE.NavigationIconButton: return ; case NavType.NAVIGATION_ITEM_TYPE.NavigationLabelButton: return ; case NavType.NAVIGATION_ITEM_TYPE.NavigationDropDownList: return ; default: return ; } }; const NavigationLink: FunctionComponent<{ item: NavType.NavigationLink }> = ({ item, }) => { return ( <> {item.customLink ? ( item.customLink ) : ( {item.label} )} ); }; const LabelButton: FunctionComponent<{ item: NavType.NavigationLabelButton; }> = ({ item }) => { return ( <> {item.customLink ? ( item.customLink ) : ( {item.label} )} ); }; const IconButton: FunctionComponent<{ item: NavType.NavigationIconButton }> = ({ item, }) => { const ButtonIcon = item.icon; return ( <> {item.customLink ? ( item.customLink ) : ( )} ); }; const DropDownList: FunctionComponent<{ item: NavType.NavigationDropDownList; }> = ({ item }) => { const [isOpen, setIsOpen] = useState(false); useEffect(() => { if (isOpen) { document.body.addEventListener( "click", () => { setIsOpen(false); }, { once: true } ); } return () => { if (isOpen) { setIsOpen(false); } }; }, [isOpen]); return (
{ setIsOpen(true); }} > {item.label}
{isOpen && (
{item.dropdownItems?.map( ( dropdownItem: NavType.NavigationDropDownItems, index: number ) => { return (
{ setIsOpen(false); }} > {dropdownItem.customLink ? (
{dropdownItem.customLink}
) : ( {dropdownItem.label} )}
); } )}
)}
); };