Skip to content

Commit 5a49ded

Browse files
committed
emotion: Sidebar
1 parent 9e453d1 commit 5a49ded

File tree

1 file changed

+77
-62
lines changed

1 file changed

+77
-62
lines changed
Lines changed: 77 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,73 @@
1-
import { makeStyles } from "@mui/styles";
1+
import { css } from "@emotion/css";
2+
import {
3+
type CSSObject,
4+
type Interpolation,
5+
type Theme,
6+
useTheme,
7+
} from "@emotion/react";
28
import VpnKeyOutlined from "@mui/icons-material/VpnKeyOutlined";
39
import FingerprintOutlinedIcon from "@mui/icons-material/FingerprintOutlined";
4-
import { User } from "api/typesGenerated";
5-
import { Stack } from "components/Stack/Stack";
6-
import { UserAvatar } from "components/UserAvatar/UserAvatar";
7-
import { FC, ElementType, PropsWithChildren, ReactNode } from "react";
10+
import {
11+
type FC,
12+
type ComponentType,
13+
type PropsWithChildren,
14+
type ReactNode,
15+
} from "react";
816
import { NavLink } from "react-router-dom";
9-
import { combineClasses } from "utils/combineClasses";
1017
import AccountIcon from "@mui/icons-material/Person";
1118
import ScheduleIcon from "@mui/icons-material/EditCalendarOutlined";
1219
import SecurityIcon from "@mui/icons-material/LockOutlined";
20+
import type { User } from "api/typesGenerated";
21+
import { Stack } from "components/Stack/Stack";
22+
import { UserAvatar } from "components/UserAvatar/UserAvatar";
1323
import { useDashboard } from "components/Dashboard/DashboardProvider";
24+
import { combineClasses } from "utils/combineClasses";
1425

1526
const SidebarNavItem: FC<
1627
PropsWithChildren<{ href: string; icon: ReactNode }>
1728
> = ({ children, href, icon }) => {
18-
const styles = useStyles();
29+
const theme = useTheme();
30+
31+
const sidebarNavItemStyles = css`
32+
color: inherit;
33+
display: block;
34+
font-size: 14px;
35+
text-decoration: none;
36+
padding: ${theme.spacing(1.5, 1.5, 1.5, 2)};
37+
border-radius: ${theme.shape.borderRadius / 2}px;
38+
transition: background-color 0.15s ease-in-out;
39+
margin-bottom: 1px;
40+
position: relative;
41+
42+
&:hover {
43+
background-color: theme.palette.action.hover;
44+
}
45+
`;
46+
47+
const sidebarNavItemActiveStyles = css`
48+
background-color: ${theme.palette.action.hover};
49+
50+
&:before {
51+
content: "";
52+
display: block;
53+
width: 3px;
54+
height: 100%;
55+
position: absolute;
56+
left: 0;
57+
top: 0;
58+
background-color: ${theme.palette.secondary.dark};
59+
border-top-left-radius: ${theme.shape.borderRadius};
60+
border-bottom-left-radius: ${theme.shape.borderRadius};
61+
}
62+
`;
63+
1964
return (
2065
<NavLink
2166
to={href}
2267
className={({ isActive }) =>
2368
combineClasses([
24-
styles.sidebarNavItem,
25-
isActive ? styles.sidebarNavItemActive : undefined,
69+
sidebarNavItemStyles,
70+
isActive ? sidebarNavItemActiveStyles : undefined,
2671
])
2772
}
2873
>
@@ -34,26 +79,31 @@ const SidebarNavItem: FC<
3479
);
3580
};
3681

37-
const SidebarNavItemIcon: React.FC<{ icon: ElementType }> = ({
38-
icon: Icon,
39-
}) => {
40-
const styles = useStyles();
41-
return <Icon className={styles.sidebarNavItemIcon} />;
82+
const SidebarNavItemIcon: React.FC<{
83+
icon: ComponentType<{ className?: string }>;
84+
}> = ({ icon: Icon }) => {
85+
return (
86+
<Icon
87+
css={(theme) => ({
88+
width: theme.spacing(2),
89+
height: theme.spacing(2),
90+
})}
91+
/>
92+
);
4293
};
4394

4495
export const Sidebar: React.FC<{ user: User }> = ({ user }) => {
45-
const styles = useStyles();
4696
const { entitlements } = useDashboard();
4797
const allowAutostopRequirement =
4898
entitlements.features.template_autostop_requirement.enabled;
4999

50100
return (
51-
<nav className={styles.sidebar}>
52-
<Stack direction="row" alignItems="center" className={styles.userInfo}>
101+
<nav css={styles.sidebar}>
102+
<Stack direction="row" alignItems="center" css={styles.userInfo}>
53103
<UserAvatar username={user.username} avatarURL={user.avatar_url} />
54-
<Stack spacing={0} className={styles.userData}>
55-
<span className={styles.username}>{user.username}</span>
56-
<span className={styles.email}>{user.email}</span>
104+
<Stack spacing={0} css={styles.userData}>
105+
<span css={styles.username}>{user.username}</span>
106+
<span css={styles.email}>{user.email}</span>
57107
</Stack>
58108
</Stack>
59109

@@ -93,50 +143,15 @@ export const Sidebar: React.FC<{ user: User }> = ({ user }) => {
93143
);
94144
};
95145

96-
const useStyles = makeStyles((theme) => ({
146+
const styles = {
97147
sidebar: {
98148
width: 245,
99149
flexShrink: 0,
100150
},
101-
sidebarNavItem: {
102-
color: "inherit",
103-
display: "block",
104-
fontSize: 14,
105-
textDecoration: "none",
106-
padding: theme.spacing(1.5, 1.5, 1.5, 2),
107-
borderRadius: theme.shape.borderRadius / 2,
108-
transition: "background-color 0.15s ease-in-out",
109-
marginBottom: 1,
110-
position: "relative",
111-
112-
"&:hover": {
113-
backgroundColor: theme.palette.action.hover,
114-
},
115-
},
116-
sidebarNavItemActive: {
117-
backgroundColor: theme.palette.action.hover,
118-
119-
"&:before": {
120-
content: '""',
121-
display: "block",
122-
width: 3,
123-
height: "100%",
124-
position: "absolute",
125-
left: 0,
126-
top: 0,
127-
backgroundColor: theme.palette.secondary.dark,
128-
borderTopLeftRadius: theme.shape.borderRadius,
129-
borderBottomLeftRadius: theme.shape.borderRadius,
130-
},
131-
},
132-
sidebarNavItemIcon: {
133-
width: theme.spacing(2),
134-
height: theme.spacing(2),
135-
},
136-
userInfo: {
137-
...theme.typography.body2,
151+
userInfo: (theme) => ({
152+
...(theme.typography.body2 as CSSObject),
138153
marginBottom: theme.spacing(2),
139-
},
154+
}),
140155
userData: {
141156
overflow: "hidden",
142157
},
@@ -146,10 +161,10 @@ const useStyles = makeStyles((theme) => ({
146161
textOverflow: "ellipsis",
147162
whiteSpace: "nowrap",
148163
},
149-
email: {
164+
email: (theme) => ({
150165
color: theme.palette.text.secondary,
151166
fontSize: 12,
152167
overflow: "hidden",
153168
textOverflow: "ellipsis",
154-
},
155-
}));
169+
}),
170+
} satisfies Record<string, Interpolation<Theme>>;

0 commit comments

Comments
 (0)