2021-12-12 10:34:17 +03:00
|
|
|
import { alpha, ListItem, ListItemButton, ListItemText } from "@mui/material";
|
2021-12-08 18:36:34 +03:00
|
|
|
import { useMatch, useResolvedPath, useNavigate } from "react-router-dom";
|
|
|
|
import type { LinkProps } from "react-router-dom";
|
|
|
|
|
|
|
|
const ListItemLink = (props: LinkProps) => {
|
|
|
|
const { to, children } = props;
|
|
|
|
|
|
|
|
const resolved = useResolvedPath(to);
|
|
|
|
const match = useMatch({ path: resolved.pathname, end: true });
|
|
|
|
const navigate = useNavigate();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ListItem sx={{ py: 0.5, maxWidth: 250, mx: "auto" }}>
|
|
|
|
<ListItemButton
|
2021-12-12 10:34:17 +03:00
|
|
|
selected={!!match}
|
2021-12-09 18:28:57 +03:00
|
|
|
sx={[
|
|
|
|
{
|
|
|
|
borderRadius: 2,
|
|
|
|
textAlign: "center",
|
2021-12-12 10:34:17 +03:00
|
|
|
"& .MuiListItemText-primary": { color: "text.secondary" },
|
2021-12-09 18:28:57 +03:00
|
|
|
},
|
2021-12-12 10:34:17 +03:00
|
|
|
({ palette: { mode, primary } }) => {
|
|
|
|
const bgcolor =
|
|
|
|
mode === "light"
|
|
|
|
? alpha(primary.main, 0.15)
|
|
|
|
: alpha(primary.main, 0.35);
|
|
|
|
const color = mode === "light" ? primary.main : primary.light;
|
2021-12-09 18:28:57 +03:00
|
|
|
|
|
|
|
return {
|
2021-12-12 10:34:17 +03:00
|
|
|
"&.Mui-selected": { bgcolor },
|
|
|
|
"&.Mui-selected:hover": { bgcolor },
|
|
|
|
"&.Mui-selected .MuiListItemText-primary": { color },
|
2021-12-09 18:28:57 +03:00
|
|
|
};
|
|
|
|
},
|
|
|
|
]}
|
2021-12-08 18:36:34 +03:00
|
|
|
onClick={() => navigate(to)}
|
|
|
|
>
|
2021-12-12 10:34:17 +03:00
|
|
|
<ListItemText primary={children} />
|
2021-12-08 18:36:34 +03:00
|
|
|
</ListItemButton>
|
|
|
|
</ListItem>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ListItemLink;
|