Files
Checkmate/client/src/Components/Sidebar/components/navItem.jsx
T

97 lines
2.1 KiB
React
Raw Normal View History

2025-07-31 15:37:40 -07:00
import Tooltip from "@mui/material/Tooltip";
import ListItemButton from "@mui/material/ListItemButton";
import ListItemIcon from "@mui/material/ListItemIcon";
import Box from "@mui/material/Box";
import Typography from "@mui/material/Typography";
import { useTheme } from "@emotion/react";
2025-08-01 15:45:43 -07:00
import PropTypes from "prop-types";
2025-07-31 15:37:40 -07:00
const NavItem = ({ item, collapsed, selected, onClick }) => {
const theme = useTheme();
2025-08-01 15:52:55 -07:00
const iconStroke = selected
? theme.palette.primary.contrastText
: theme.palette.primary.contrastTextTertiary;
2025-07-31 15:37:40 -07:00
2025-08-01 15:52:55 -07:00
const buttonBgColor = selected ? theme.palette.secondary.main : "transparent";
const buttonBgHoverColor = selected
? theme.palette.secondary.main
: theme.palette.tertiary.main;
const fontWeight = selected ? 600 : 400;
2025-07-31 15:37:40 -07:00
return (
<Tooltip
placement="right"
title={collapsed ? item.name : ""}
slotProps={{
popper: {
modifiers: [
{
name: "offset",
options: {
offset: [0, -16],
},
},
],
},
}}
disableInteractive
>
<ListItemButton
sx={{
2025-08-01 15:52:55 -07:00
backgroundColor: buttonBgColor,
2025-07-31 15:37:40 -07:00
"&:hover": {
2025-08-01 15:52:55 -07:00
backgroundColor: buttonBgHoverColor,
2025-07-31 15:37:40 -07:00
},
2025-08-01 15:52:55 -07:00
height: 37,
2025-07-31 15:37:40 -07:00
gap: theme.spacing(4),
borderRadius: theme.shape.borderRadius,
px: theme.spacing(4),
pl: theme.spacing(5),
}}
onClick={onClick}
>
<ListItemIcon
sx={{
minWidth: 0,
"& svg": {
2025-08-01 15:52:55 -07:00
height: 20,
width: 20,
2025-07-31 15:37:40 -07:00
opacity: 0.81,
},
"& svg path": {
2025-08-01 15:52:55 -07:00
stroke: iconStroke,
2025-07-31 15:37:40 -07:00
},
}}
>
{item.icon}
</ListItemIcon>
<Box
sx={{
overflow: "hidden",
transition: "opacity 900ms ease",
opacity: collapsed ? 0 : 1,
whiteSpace: "nowrap",
}}
>
<Typography
variant="body1"
color={theme.palette.primary.contrastText}
sx={{
2025-08-01 15:52:55 -07:00
fontWeight: fontWeight,
2025-07-31 15:37:40 -07:00
opacity: 0.9,
}}
>
{item.name}
</Typography>
</Box>
</ListItemButton>
</Tooltip>
);
};
2025-08-01 15:45:43 -07:00
NavItem.propTypes = {
item: PropTypes.object,
collapsed: PropTypes.bool,
selected: PropTypes.bool,
onClick: PropTypes.func,
};
2025-07-31 15:37:40 -07:00
export default NavItem;