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" ;
2
8
import VpnKeyOutlined from "@mui/icons-material/VpnKeyOutlined" ;
3
9
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" ;
8
16
import { NavLink } from "react-router-dom" ;
9
- import { combineClasses } from "utils/combineClasses" ;
10
17
import AccountIcon from "@mui/icons-material/Person" ;
11
18
import ScheduleIcon from "@mui/icons-material/EditCalendarOutlined" ;
12
19
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" ;
13
23
import { useDashboard } from "components/Dashboard/DashboardProvider" ;
24
+ import { combineClasses } from "utils/combineClasses" ;
14
25
15
26
const SidebarNavItem : FC <
16
27
PropsWithChildren < { href : string ; icon : ReactNode } >
17
28
> = ( { 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
+
19
64
return (
20
65
< NavLink
21
66
to = { href }
22
67
className = { ( { isActive } ) =>
23
68
combineClasses ( [
24
- styles . sidebarNavItem ,
25
- isActive ? styles . sidebarNavItemActive : undefined ,
69
+ sidebarNavItemStyles ,
70
+ isActive ? sidebarNavItemActiveStyles : undefined ,
26
71
] )
27
72
}
28
73
>
@@ -34,26 +79,31 @@ const SidebarNavItem: FC<
34
79
) ;
35
80
} ;
36
81
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
+ ) ;
42
93
} ;
43
94
44
95
export const Sidebar : React . FC < { user : User } > = ( { user } ) => {
45
- const styles = useStyles ( ) ;
46
96
const { entitlements } = useDashboard ( ) ;
47
97
const allowAutostopRequirement =
48
98
entitlements . features . template_autostop_requirement . enabled ;
49
99
50
100
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 } >
53
103
< 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 >
57
107
</ Stack >
58
108
</ Stack >
59
109
@@ -93,50 +143,15 @@ export const Sidebar: React.FC<{ user: User }> = ({ user }) => {
93
143
) ;
94
144
} ;
95
145
96
- const useStyles = makeStyles ( ( theme ) => ( {
146
+ const styles = {
97
147
sidebar : {
98
148
width : 245 ,
99
149
flexShrink : 0 ,
100
150
} ,
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 ) ,
138
153
marginBottom : theme . spacing ( 2 ) ,
139
- } ,
154
+ } ) ,
140
155
userData : {
141
156
overflow : "hidden" ,
142
157
} ,
@@ -146,10 +161,10 @@ const useStyles = makeStyles((theme) => ({
146
161
textOverflow : "ellipsis" ,
147
162
whiteSpace : "nowrap" ,
148
163
} ,
149
- email : {
164
+ email : ( theme ) => ( {
150
165
color : theme . palette . text . secondary ,
151
166
fontSize : 12 ,
152
167
overflow : "hidden" ,
153
168
textOverflow : "ellipsis" ,
154
- } ,
155
- } ) ) ;
169
+ } ) ,
170
+ } satisfies Record < string , Interpolation < Theme > > ;
0 commit comments