[5d6f37a] | 1 | // @mui
|
---|
| 2 | import Box from '@mui/material/Box';
|
---|
| 3 | import Link from '@mui/material/Link';
|
---|
| 4 | import Tooltip from '@mui/material/Tooltip';
|
---|
| 5 | import ListItemText from '@mui/material/ListItemText';
|
---|
| 6 | // routes
|
---|
| 7 | import { RouterLink } from 'src/routes/components';
|
---|
| 8 | //
|
---|
| 9 | import Iconify from '../../iconify';
|
---|
| 10 | //
|
---|
| 11 | import { NavItemProps, NavConfigProps } from '../types';
|
---|
| 12 | import { StyledItem, StyledIcon, StyledDotIcon } from './styles';
|
---|
| 13 |
|
---|
| 14 | // ----------------------------------------------------------------------
|
---|
| 15 |
|
---|
| 16 | type Props = NavItemProps & {
|
---|
| 17 | config: NavConfigProps;
|
---|
| 18 | };
|
---|
| 19 |
|
---|
| 20 | export default function NavItem({
|
---|
| 21 | item,
|
---|
| 22 | open,
|
---|
| 23 | depth,
|
---|
| 24 | active,
|
---|
| 25 | config,
|
---|
| 26 | externalLink,
|
---|
| 27 | ...other
|
---|
| 28 | }: Props) {
|
---|
| 29 | const { title, path, icon, info, children, disabled, caption, roles } = item;
|
---|
| 30 |
|
---|
| 31 | const subItem = depth !== 1;
|
---|
| 32 |
|
---|
| 33 | const renderContent = (
|
---|
| 34 | <StyledItem
|
---|
| 35 | disableGutters
|
---|
| 36 | disabled={disabled}
|
---|
| 37 | active={active}
|
---|
| 38 | depth={depth}
|
---|
| 39 | config={config}
|
---|
| 40 | {...other}
|
---|
| 41 | >
|
---|
| 42 | <>
|
---|
| 43 | {icon && <StyledIcon size={config.iconSize}>{icon}</StyledIcon>}
|
---|
| 44 |
|
---|
| 45 | {subItem && (
|
---|
| 46 | <StyledIcon size={config.iconSize}>
|
---|
| 47 | <StyledDotIcon active={active} />
|
---|
| 48 | </StyledIcon>
|
---|
| 49 | )}
|
---|
| 50 | </>
|
---|
| 51 |
|
---|
| 52 | {!(config.hiddenLabel && !subItem) && (
|
---|
| 53 | <ListItemText
|
---|
| 54 | primary={title}
|
---|
| 55 | secondary={
|
---|
| 56 | caption ? (
|
---|
| 57 | <Tooltip title={caption} placement="top-start">
|
---|
| 58 | <span>{caption}</span>
|
---|
| 59 | </Tooltip>
|
---|
| 60 | ) : null
|
---|
| 61 | }
|
---|
| 62 | primaryTypographyProps={{
|
---|
| 63 | noWrap: true,
|
---|
| 64 | typography: 'body2',
|
---|
| 65 | textTransform: 'capitalize',
|
---|
| 66 | fontWeight: active ? 'fontWeightSemiBold' : 'fontWeightMedium',
|
---|
| 67 | }}
|
---|
| 68 | secondaryTypographyProps={{
|
---|
| 69 | noWrap: true,
|
---|
| 70 | component: 'span',
|
---|
| 71 | typography: 'caption',
|
---|
| 72 | color: 'text.disabled',
|
---|
| 73 | }}
|
---|
| 74 | />
|
---|
| 75 | )}
|
---|
| 76 |
|
---|
| 77 | {info && (
|
---|
| 78 | <Box component="span" sx={{ ml: 1, lineHeight: 0 }}>
|
---|
| 79 | {info}
|
---|
| 80 | </Box>
|
---|
| 81 | )}
|
---|
| 82 |
|
---|
| 83 | {!!children && (
|
---|
| 84 | <Iconify
|
---|
| 85 | width={16}
|
---|
| 86 | icon={open ? 'eva:arrow-ios-downward-fill' : 'eva:arrow-ios-forward-fill'}
|
---|
| 87 | sx={{ ml: 1, flexShrink: 0 }}
|
---|
| 88 | />
|
---|
| 89 | )}
|
---|
| 90 | </StyledItem>
|
---|
| 91 | );
|
---|
| 92 |
|
---|
| 93 | // Hidden item by role
|
---|
| 94 | if (roles && !roles.includes(`${config.currentRole}`)) {
|
---|
| 95 | return null;
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 | // External link
|
---|
| 99 | if (externalLink)
|
---|
| 100 | return (
|
---|
| 101 | <Link
|
---|
| 102 | href={path}
|
---|
| 103 | target="_blank"
|
---|
| 104 | rel="noopener"
|
---|
| 105 | underline="none"
|
---|
| 106 | color="inherit"
|
---|
| 107 | sx={{
|
---|
| 108 | ...(disabled && {
|
---|
| 109 | cursor: 'default',
|
---|
| 110 | }),
|
---|
| 111 | }}
|
---|
| 112 | >
|
---|
| 113 | {renderContent}
|
---|
| 114 | </Link>
|
---|
| 115 | );
|
---|
| 116 |
|
---|
| 117 | // Has child
|
---|
| 118 | if (children) {
|
---|
| 119 | return renderContent;
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 | // Default
|
---|
| 123 | return (
|
---|
| 124 | <Link
|
---|
| 125 | component={RouterLink}
|
---|
| 126 | href={path}
|
---|
| 127 | underline="none"
|
---|
| 128 | color="inherit"
|
---|
| 129 | sx={{
|
---|
| 130 | ...(disabled && {
|
---|
| 131 | cursor: 'default',
|
---|
| 132 | }),
|
---|
| 133 | }}
|
---|
| 134 | >
|
---|
| 135 | {renderContent}
|
---|
| 136 | </Link>
|
---|
| 137 | );
|
---|
| 138 | }
|
---|