Skip to content

Commit 13cabea

Browse files
committed
frontend: ListItemLink: adjust styles to use new theme tokens
Signed-off-by: Oleksandr Dubenko <[email protected]>
1 parent e0b4bf5 commit 13cabea

File tree

1 file changed

+129
-9
lines changed

1 file changed

+129
-9
lines changed

frontend/src/components/Sidebar/ListItemLink.tsx

Lines changed: 129 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Icon, IconProps } from '@iconify/react';
2-
import { styled, Tooltip } from '@mui/material';
3-
import ListItem from '@mui/material/ListItem';
2+
import { alpha, ListItemButton, styled, Tooltip } from '@mui/material';
43
import ListItemIcon from '@mui/material/ListItemIcon';
54
import ListItemText from '@mui/material/ListItemText';
65
import React from 'react';
@@ -17,17 +16,32 @@ interface ListItemLinkProps {
1716
subtitle?: string;
1817
icon?: IconProps['icon'];
1918
iconOnly?: boolean;
19+
hasParent?: boolean;
20+
fullWidth?: boolean;
2021
containerProps?: {
2122
[prop: string]: any;
2223
};
2324
}
2425

25-
// make a styled() li
26-
const StyledLi = styled('li')();
26+
const StyledLi = styled('li')<{ hasParent?: boolean }>(({ hasParent }) => ({
27+
marginRight: '5px',
28+
marginLeft: hasParent ? '35px' : '5px',
29+
marginBottom: '1px',
30+
}));
2731

2832
export default function ListItemLink(props: ListItemLinkProps) {
29-
const { primary, pathname, search, icon, name, containerProps, iconOnly, subtitle, ...other } =
30-
props;
33+
const {
34+
primary,
35+
pathname,
36+
search,
37+
icon,
38+
name,
39+
iconOnly,
40+
subtitle,
41+
hasParent,
42+
fullWidth,
43+
...other
44+
} = props;
3145

3246
const iconSize = React.useMemo(
3347
() => (iconOnly ? CollapsedIconSize : ExpandedIconSize),
@@ -72,12 +86,118 @@ export default function ListItemLink(props: ListItemLinkProps) {
7286
);
7387
}
7488

89+
const hasSubtitle = Boolean(subtitle);
90+
7591
return (
76-
<StyledLi {...containerProps}>
77-
<ListItem button component={renderLink} {...other}>
92+
<StyledLi hasParent={hasParent}>
93+
<ListItemButton
94+
component={renderLink}
95+
{...other}
96+
sx={theme => ({
97+
color:
98+
theme.palette.sidebar.color ??
99+
theme.palette.getContrastText(theme.palette.sidebar.background),
100+
margin: 0,
101+
borderRadius: theme.shape.borderRadius + 'px',
102+
height: iconOnly ? '50px' : undefined,
103+
opacity: hasParent ? 0.9 : 1.0,
104+
fontSize: hasParent ? '0.85rem' : '1rem',
105+
106+
svg: {
107+
color: 'currentColor',
108+
},
109+
110+
'&.Mui-selected': hasParent
111+
? {
112+
':before': {
113+
content: "''",
114+
width: '4px',
115+
borderRadius: theme.shape.borderRadius + 'px',
116+
background: theme.palette.sidebar.selectedColor,
117+
position: 'absolute',
118+
left: '4px',
119+
top: '7px',
120+
bottom: '7px',
121+
},
122+
opacity: 1.0,
123+
color: theme.palette.sidebar.selectedColor,
124+
background: 'none',
125+
}
126+
: {
127+
opacity: 1.0,
128+
boxShadow: '1px 1px 4px rgb(0 0 0 / 12%)',
129+
background: theme.palette.sidebar.selectedBackground,
130+
color: theme.palette.getContrastText(theme.palette.sidebar.selectedBackground),
131+
},
132+
133+
'&.Mui-selected:hover': hasParent
134+
? {
135+
backgroundColor: alpha(
136+
theme.palette.getContrastText(theme.palette.sidebar.background),
137+
0.07
138+
),
139+
}
140+
: {
141+
backgroundColor: alpha(theme.palette.sidebar.selectedBackground, 0.8),
142+
},
143+
144+
':hover': {
145+
backgroundColor: alpha(
146+
theme.palette.getContrastText(theme.palette.sidebar.background),
147+
0.07
148+
),
149+
},
150+
151+
'.MuiListItemIcon-root': {
152+
color: 'unset',
153+
},
154+
155+
'.MuiListItemText-root': {
156+
margin: 0,
157+
},
158+
159+
'& *': {
160+
fontSize: '.875rem',
161+
textTransform: 'none',
162+
},
163+
'& .MuiListItem-root': {
164+
paddingTop: '4px',
165+
paddingBottom: '4px',
166+
},
167+
168+
'& .MuiListItemIcon-root': {
169+
minWidth: 0,
170+
alignSelf: fullWidth && hasSubtitle ? 'stretch' : 'auto',
171+
paddingTop: fullWidth && hasSubtitle ? theme.spacing(1) : 0,
172+
marginRight: fullWidth ? '8px' : '0',
173+
},
174+
'& .MuiListItemText-secondary': {
175+
fontSize: '.85rem',
176+
fontStyle: 'italic',
177+
whiteSpace: 'nowrap',
178+
textOverflow: 'ellipsis',
179+
overflowWrap: 'anywhere',
180+
overflow: 'hidden',
181+
color: 'currentColor',
182+
},
183+
184+
...(!hasParent && {
185+
'& .MuiListItem-root': {
186+
paddingTop: hasSubtitle ? '0' : '7px',
187+
paddingBottom: hasSubtitle ? '0' : '7px',
188+
paddingLeft: '19px',
189+
minHeight: !fullWidth ? '56px' : 'unset',
190+
},
191+
192+
'& *': {
193+
fontSize: '1rem',
194+
},
195+
}),
196+
})}
197+
>
78198
{listItemLinkContainer}
79199
{!iconOnly && <ListItemText primary={primary} secondary={subtitle} />}
80-
</ListItem>
200+
</ListItemButton>
81201
</StyledLi>
82202
);
83203
}

0 commit comments

Comments
 (0)