import * as React from 'react'; import { forwardRef } from 'react'; import Popover from '@mui/material/Popover'; import { useTheme,} from '@mui/material/styles'; import Box from '@mui/material/Box'; import Toolbar from '@mui/material/Toolbar'; import List from '@mui/material/List'; import CssBaseline from '@mui/material/CssBaseline'; import Divider from '@mui/material/Divider'; import IconButton from '@mui/material/IconButton'; // import MenuIcon from '@mui/icons-material/Menu'; import { IoMdMenu } from "react-icons/io"; import ListItem from '@mui/material/ListItem'; import ListItemButton from '@mui/material/ListItemButton'; import ListItemIcon from '@mui/material/ListItemIcon'; import ListItemText from '@mui/material/ListItemText'; import { Appbar } from './styles'; import {MdOutlineKeyboardArrowDown,MdOutlineKeyboardArrowRight} from "react-icons/md"; import { DrawerHeader } from './styles'; import Collapse from '@mui/material/Collapse'; import { hasChildren } from "./util"; import {StyleDrawer} from './styles'; import { useNavigate } from "react-router-dom"; import { useLocation } from 'react-router-dom'; import { Grid, Checkbox, FormControlLabel, Typography, Link } from "@mui/material"; interface SidebarProps { variant: 'permanent', anchor: 'left' , sx?:any, sidedata?:Array, appbar?:boolean, ProductName?:any, Year?:string, drawerheader?:boolean, handlecallback?:any, drawerWidth?:any, openDrawer?:boolean, ROUTE_MAPPER ?: { [key : string] : string }, } interface UrlLink{ id : string, label ?: string, url ?: string, isSubLinks ?: boolean, sublinks ?: Array, shouldOpenNewTab ?: boolean } export interface NavLink extends UrlLink{ icon ?: React.ReactNode, navigate ?: () => void } const SingleLevel = ({ item,open,ROUTE_MAPPER }:any) => { const [anchorEl, setAnchorEl] = React.useState(null); const navigate = useNavigate(); const handlePopoverOpen = (event: React.MouseEvent) => { setAnchorEl(event.currentTarget); }; const handlePopoverClose = () => { setAnchorEl(null); }; const openPopup = Boolean(anchorEl); const navigateTo=(url:string)=>()=>{ navigate(url) } const navigateToExternalUrl = (url: string) => () => { window.open(url, "_blank"); } const location = useLocation() return ( { {} }> {item.icon} } {/* { !open && } */} ); }; const MultiLevel = ({ item ,open}:any) => { const location = useLocation() const { sublinks: children } = item; const Filter=(child:any)=>{ const data = child.filter((item:any)=>{ if(item?.isSubLinks){ return item?.sublinks?.filter((item:any)=>item.url === location.pathname) .length >0 } else return (item.url === location.pathname) }) return data } const selectedChild=Filter(children) const [openchild, setOpenchild] = React.useState(false); const [anchorEl, setAnchorEl] = React.useState(null); const handlePopoverOpen = (event: React.MouseEvent) => { setAnchorEl(event.currentTarget); }; const handlePopoverClose = () => { setAnchorEl(null); }; const openPopup = Boolean(anchorEl); const handleClick = () => { setOpenchild((prev:any) => !prev ) }; return ( {} } aria-owns={openPopup ? 'mouse-over-popover' : undefined} aria-haspopup="true" onMouseEnter={handlePopoverOpen} sx={{ cursor:`${selectedChild?.url !== ''? 'pointer' : 'not-allowed'}`, backgroundColor:'transparent', "& .Mui-selected": { color:'#1c84ee', backgroundColor:'transparent', ':hover':{ backgroundColor: 'white' }, } }} // onMouseLeave={handlePopoverClose} > {item.icon} 0}> {openchild ? : } {children?.map((child:any, key:any) => ( ))} {/* {!open && {children?.map((child:string, key:any) => ( ))} } */} ); }; const MenuItem = ({ item ,open}:any) => { const Component = hasChildren(item) ? MultiLevel : SingleLevel; return ; }; const Sidebar = forwardRef(({ sidedata,ProductName,Year,appbar=false,drawerWidth=300,openDrawer=true,drawerheader=false,handlecallback,ROUTE_MAPPER,...other } : SidebarProps, ref) => { const theme = useTheme(); const [open, setOpen] = React.useState(false); const handleDrawerOpen = () => { setOpen(true); }; const handleDrawerClose = () => { setOpen(false); }; React.useEffect(()=>{ setOpen(!open) },[openDrawer]) return ( {appbar && } { drawerheader && {theme.direction === 'ltr' && } } {sidedata?.map((item, key) => )} {Year} © {ProductName}. Design & Developed by 3Insys ); } ); export default Sidebar;