import Avatar from "@mui/material/Avatar"; import Box from "@mui/material/Box"; 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 Typography from "@mui/material/Typography"; import type {} from "@mui/material/themeCssVarsAugmentation"; import * as React from "react"; import { Link, matchPath, useLocation } from "react-router"; import DashboardSidebarContext from "./DashboardSidebarContext"; import { MINI_DRAWER_WIDTH } from "./constants"; export interface DashboardSidebarPageItemProps { title: string; icon?: React.ReactNode; href: string; action?: React.ReactNode; disabled?: boolean; } export default function DashboardSidebarPageItem({ title, icon, href, action, disabled = false, }: DashboardSidebarPageItemProps) { const { pathname } = useLocation(); const sidebarContext = React.useContext(DashboardSidebarContext); if (!sidebarContext) { throw new Error("Sidebar context was used without a provider."); } const { onPageItemClick, mini = false, fullyExpanded = true, } = sidebarContext; const hasExternalHref = href ? href.startsWith("http://") || href.startsWith("https://") : false; const LinkComponent = hasExternalHref ? "a" : Link; const selected = !!matchPath(href, pathname); return ( {icon || mini ? ( {icon ?? null} {!icon && mini ? ( {title .split(" ") .slice(0, 2) .map((titleWord) => titleWord.charAt(0).toUpperCase())} ) : null} {mini ? ( {title} ) : null} ) : null} {!mini ? ( ) : null} {action && !mini && fullyExpanded ? action : null} ); }