source: src/components/nav-section/mini/nav-item.tsx@ 5d6f37a

main
Last change on this file since 5d6f37a was 5d6f37a, checked in by Naum Shapkarovski <naumshapkarovski@…>, 7 weeks ago

add customer

  • Property mode set to 100644
File size: 3.6 KB
Line 
1import { forwardRef } from 'react';
2// @mui
3import { useTheme } from '@mui/material/styles';
4import Link from '@mui/material/Link';
5import Tooltip from '@mui/material/Tooltip';
6import ListItemText from '@mui/material/ListItemText';
7// routes
8import { RouterLink } from 'src/routes/components';
9//
10import Iconify from '../../iconify';
11//
12import { NavItemProps, NavConfigProps } from '../types';
13import { StyledItem, StyledIcon } from './styles';
14
15// ----------------------------------------------------------------------
16
17type Props = NavItemProps & {
18 config: NavConfigProps;
19};
20
21const NavItem = forwardRef<HTMLDivElement, Props>(
22 ({ item, depth, open, active, externalLink, config, ...other }, ref) => {
23 const theme = useTheme();
24
25 const { title, path, icon, children, disabled, caption, roles } = item;
26
27 const subItem = depth !== 1;
28
29 const renderContent = (
30 <StyledItem
31 disableGutters
32 ref={ref}
33 open={open}
34 depth={depth}
35 active={active}
36 disabled={disabled}
37 config={config}
38 {...other}
39 >
40 {icon && (
41 <StyledIcon
42 size={config.iconSize}
43 sx={{
44 ...(subItem && { mr: 1.5 }),
45 }}
46 >
47 {icon}
48 </StyledIcon>
49 )}
50
51 {!(config.hiddenLabel && !subItem) && (
52 <ListItemText
53 sx={{
54 width: 1,
55 flex: 'unset',
56 ...(!subItem && {
57 px: 0.5,
58 mt: 0.5,
59 }),
60 }}
61 primary={title}
62 primaryTypographyProps={{
63 noWrap: true,
64 fontSize: 10,
65 lineHeight: '16px',
66 textAlign: 'center',
67 textTransform: 'capitalize',
68 fontWeight: active ? 'fontWeightBold' : 'fontWeightSemiBold',
69 ...(subItem && {
70 textAlign: 'unset',
71 fontSize: theme.typography.body2.fontSize,
72 lineHeight: theme.typography.body2.lineHeight,
73 fontWeight: active ? 'fontWeightSemiBold' : 'fontWeightMedium',
74 }),
75 }}
76 />
77 )}
78
79 {caption && (
80 <Tooltip title={caption} arrow placement="right">
81 <Iconify
82 width={16}
83 icon="eva:info-outline"
84 sx={{
85 color: 'text.disabled',
86 ...(!subItem && {
87 top: 11,
88 left: 6,
89 position: 'absolute',
90 }),
91 }}
92 />
93 </Tooltip>
94 )}
95
96 {!!children && (
97 <Iconify
98 width={16}
99 icon="eva:arrow-ios-forward-fill"
100 sx={{
101 top: 11,
102 right: 6,
103 position: 'absolute',
104 }}
105 />
106 )}
107 </StyledItem>
108 );
109
110 // Hidden item by role
111 if (roles && !roles.includes(`${config.currentRole}`)) {
112 return null;
113 }
114
115 // External link
116 if (externalLink)
117 return (
118 <Link
119 href={path}
120 target="_blank"
121 rel="noopener"
122 underline="none"
123 sx={{
124 width: 1,
125 ...(disabled && {
126 cursor: 'default',
127 }),
128 }}
129 >
130 {renderContent}
131 </Link>
132 );
133
134 // Default
135 return (
136 <Link
137 component={RouterLink}
138 href={path}
139 underline="none"
140 sx={{
141 width: 1,
142 ...(disabled && {
143 cursor: 'default',
144 }),
145 }}
146 >
147 {renderContent}
148 </Link>
149 );
150 }
151);
152
153export default NavItem;
Note: See TracBrowser for help on using the repository browser.