1 | // @mui
|
---|
2 | import { alpha, styled } from '@mui/material/styles';
|
---|
3 | import ListItemIcon from '@mui/material/ListItemIcon';
|
---|
4 | import ListSubheader from '@mui/material/ListSubheader';
|
---|
5 | import ListItemButton from '@mui/material/ListItemButton';
|
---|
6 | //
|
---|
7 | import { NavItemProps, NavConfigProps } from '../types';
|
---|
8 |
|
---|
9 | // ----------------------------------------------------------------------
|
---|
10 |
|
---|
11 | type StyledItemProps = Omit<NavItemProps, 'item'> & {
|
---|
12 | config: NavConfigProps;
|
---|
13 | };
|
---|
14 |
|
---|
15 | export const StyledItem = styled(ListItemButton, {
|
---|
16 | shouldForwardProp: (prop) => prop !== 'active',
|
---|
17 | })<StyledItemProps>(({ active, depth, config, theme }) => {
|
---|
18 | const subItem = depth !== 1;
|
---|
19 |
|
---|
20 | const deepSubItem = depth > 2;
|
---|
21 |
|
---|
22 | const activeStyles = {
|
---|
23 | root: {
|
---|
24 | color:
|
---|
25 | theme.palette.mode === 'light' ? theme.palette.primary.main : theme.palette.primary.light,
|
---|
26 | backgroundColor: alpha(theme.palette.primary.main, 0.08),
|
---|
27 | '&:hover': {
|
---|
28 | backgroundColor: alpha(theme.palette.primary.main, 0.16),
|
---|
29 | },
|
---|
30 | },
|
---|
31 | sub: {
|
---|
32 | color: theme.palette.text.primary,
|
---|
33 | backgroundColor: 'transparent',
|
---|
34 | '&:hover': {
|
---|
35 | backgroundColor: theme.palette.action.hover,
|
---|
36 | },
|
---|
37 | },
|
---|
38 | };
|
---|
39 |
|
---|
40 | return {
|
---|
41 | // Root item
|
---|
42 | padding: config.itemPadding,
|
---|
43 | marginBottom: config.itemGap,
|
---|
44 | borderRadius: config.itemRadius,
|
---|
45 | minHeight: config.itemRootHeight,
|
---|
46 | color: theme.palette.text.secondary,
|
---|
47 |
|
---|
48 | // Active root item
|
---|
49 | ...(active && {
|
---|
50 | ...activeStyles.root,
|
---|
51 | }),
|
---|
52 |
|
---|
53 | // Sub item
|
---|
54 | ...(subItem && {
|
---|
55 | minHeight: config.itemSubHeight,
|
---|
56 | // Active sub item
|
---|
57 | ...(active && {
|
---|
58 | ...activeStyles.sub,
|
---|
59 | }),
|
---|
60 | }),
|
---|
61 |
|
---|
62 | // Deep sub item
|
---|
63 | ...(deepSubItem && {
|
---|
64 | paddingLeft: theme.spacing(depth),
|
---|
65 | }),
|
---|
66 | };
|
---|
67 | });
|
---|
68 |
|
---|
69 | // ----------------------------------------------------------------------
|
---|
70 |
|
---|
71 | type StyledIconProps = {
|
---|
72 | size?: number;
|
---|
73 | };
|
---|
74 |
|
---|
75 | export const StyledIcon = styled(ListItemIcon)<StyledIconProps>(({ size }) => ({
|
---|
76 | width: size,
|
---|
77 | height: size,
|
---|
78 | alignItems: 'center',
|
---|
79 | justifyContent: 'center',
|
---|
80 | }));
|
---|
81 |
|
---|
82 | type StyledDotIconProps = {
|
---|
83 | active?: boolean;
|
---|
84 | };
|
---|
85 |
|
---|
86 | export const StyledDotIcon = styled('span')<StyledDotIconProps>(({ active, theme }) => ({
|
---|
87 | width: 4,
|
---|
88 | height: 4,
|
---|
89 | borderRadius: '50%',
|
---|
90 | backgroundColor: theme.palette.text.disabled,
|
---|
91 | transition: theme.transitions.create(['transform'], {
|
---|
92 | duration: theme.transitions.duration.shorter,
|
---|
93 | }),
|
---|
94 | ...(active && {
|
---|
95 | transform: 'scale(2)',
|
---|
96 | backgroundColor: theme.palette.primary.main,
|
---|
97 | }),
|
---|
98 | }));
|
---|
99 |
|
---|
100 | // ----------------------------------------------------------------------
|
---|
101 |
|
---|
102 | type StyledSubheaderProps = {
|
---|
103 | config: NavConfigProps;
|
---|
104 | };
|
---|
105 |
|
---|
106 | export const StyledSubheader = styled(ListSubheader)<StyledSubheaderProps>(({ config, theme }) => ({
|
---|
107 | ...theme.typography.overline,
|
---|
108 | fontSize: 11,
|
---|
109 | cursor: 'pointer',
|
---|
110 | display: 'inline-flex',
|
---|
111 | padding: config.itemPadding,
|
---|
112 | paddingTop: theme.spacing(2),
|
---|
113 | marginBottom: config.itemGap,
|
---|
114 | paddingBottom: theme.spacing(1),
|
---|
115 | color: theme.palette.text.disabled,
|
---|
116 | transition: theme.transitions.create(['color'], {
|
---|
117 | duration: theme.transitions.duration.shortest,
|
---|
118 | }),
|
---|
119 | '&:hover': {
|
---|
120 | color: theme.palette.text.primary,
|
---|
121 | },
|
---|
122 | }));
|
---|