1 | // @mui
|
---|
2 | import { alpha, styled } from '@mui/material/styles';
|
---|
3 | import ListItemIcon from '@mui/material/ListItemIcon';
|
---|
4 | import ListItemButton from '@mui/material/ListItemButton';
|
---|
5 | //
|
---|
6 | import { NavItemProps, NavConfigProps } from '../types';
|
---|
7 |
|
---|
8 | // ----------------------------------------------------------------------
|
---|
9 |
|
---|
10 | type StyledItemProps = Omit<NavItemProps, 'item'> & {
|
---|
11 | config: NavConfigProps;
|
---|
12 | };
|
---|
13 |
|
---|
14 | export const StyledItem = styled(ListItemButton, {
|
---|
15 | shouldForwardProp: (prop) => prop !== 'active',
|
---|
16 | })<StyledItemProps>(({ active, open, depth, config, theme }) => {
|
---|
17 | const subItem = depth !== 1;
|
---|
18 |
|
---|
19 | const activeStyles = {
|
---|
20 | root: {
|
---|
21 | color:
|
---|
22 | theme.palette.mode === 'light' ? theme.palette.primary.main : theme.palette.primary.light,
|
---|
23 | backgroundColor: alpha(theme.palette.primary.main, 0.08),
|
---|
24 | '&:hover': {
|
---|
25 | backgroundColor: alpha(theme.palette.primary.main, 0.16),
|
---|
26 | },
|
---|
27 | },
|
---|
28 | sub: {
|
---|
29 | color: theme.palette.text.primary,
|
---|
30 | backgroundColor: theme.palette.action.selected,
|
---|
31 | '&:hover': {
|
---|
32 | backgroundColor: theme.palette.action.hover,
|
---|
33 | },
|
---|
34 | },
|
---|
35 | };
|
---|
36 |
|
---|
37 | return {
|
---|
38 | // Root item
|
---|
39 | flexDirection: 'column',
|
---|
40 | justifyContent: 'center',
|
---|
41 | borderRadius: config.itemRadius,
|
---|
42 | minHeight: config.itemRootHeight,
|
---|
43 | color: theme.palette.text.secondary,
|
---|
44 | margin: `0 ${config.itemGap}px ${config.itemGap}px ${config.itemGap}px`,
|
---|
45 | ...(config.hiddenLabel &&
|
---|
46 | !subItem && {
|
---|
47 | padding: config.itemPadding,
|
---|
48 | }),
|
---|
49 |
|
---|
50 | // Active root item
|
---|
51 | ...(active && {
|
---|
52 | ...activeStyles.root,
|
---|
53 | }),
|
---|
54 |
|
---|
55 | // Sub item
|
---|
56 | ...(subItem && {
|
---|
57 | margin: 0,
|
---|
58 | flexDirection: 'row',
|
---|
59 | padding: theme.spacing(0, 1),
|
---|
60 | minHeight: config.itemSubHeight,
|
---|
61 | // Active sub item
|
---|
62 | ...(active && {
|
---|
63 | ...activeStyles.sub,
|
---|
64 | }),
|
---|
65 | }),
|
---|
66 |
|
---|
67 | // Open
|
---|
68 | ...(open &&
|
---|
69 | !active && {
|
---|
70 | color: theme.palette.text.primary,
|
---|
71 | backgroundColor: theme.palette.action.hover,
|
---|
72 | }),
|
---|
73 | };
|
---|
74 | });
|
---|
75 |
|
---|
76 | // ----------------------------------------------------------------------
|
---|
77 |
|
---|
78 | type StyledIconProps = {
|
---|
79 | size?: number;
|
---|
80 | };
|
---|
81 |
|
---|
82 | export const StyledIcon = styled(ListItemIcon)<StyledIconProps>(({ size }) => ({
|
---|
83 | width: size,
|
---|
84 | height: size,
|
---|
85 | marginRight: 0,
|
---|
86 | }));
|
---|