1
- import { makeStyles } from "@mui/styles" ;
1
+ import { css } from "@emotion/css" ;
2
+ import {
3
+ useTheme ,
4
+ type CSSObject ,
5
+ type Interpolation ,
6
+ type Theme ,
7
+ } from "@emotion/react" ;
2
8
import ScheduleIcon from "@mui/icons-material/TimerOutlined" ;
3
9
import VariablesIcon from "@mui/icons-material/CodeOutlined" ;
4
- import { Template } from "api/typesGenerated" ;
10
+ import type { Template } from "api/typesGenerated" ;
5
11
import { Stack } from "components/Stack/Stack" ;
6
- import { FC , ElementType , PropsWithChildren , ReactNode } from "react" ;
12
+ import {
13
+ type FC ,
14
+ type ElementType ,
15
+ type PropsWithChildren ,
16
+ type ReactNode ,
17
+ } from "react" ;
7
18
import { Link , NavLink } from "react-router-dom" ;
8
- import { combineClasses } from "utils/combineClasses" ;
9
19
import GeneralIcon from "@mui/icons-material/SettingsOutlined" ;
10
20
import SecurityIcon from "@mui/icons-material/LockOutlined" ;
11
21
import { Avatar } from "components/Avatar/Avatar" ;
22
+ import { combineClasses } from "utils/combineClasses" ;
12
23
13
24
const SidebarNavItem : FC <
14
25
PropsWithChildren < { href : string ; icon : ReactNode } >
15
26
> = ( { children, href, icon } ) => {
16
- const styles = useStyles ( ) ;
27
+ const theme = useTheme ( ) ;
28
+
29
+ const sidebarNavItemStyles = css `
30
+ color : inherit;
31
+ display : block;
32
+ font-size : 14px ;
33
+ text-decoration : none;
34
+ padding : ${ theme . spacing ( 1.5 , 1.5 , 1.5 , 2 ) } ;
35
+ border-radius : ${ theme . shape . borderRadius / 2 } px;
36
+ transition : background-color 0.15s ease-in-out;
37
+ margin-bottom : 1px ;
38
+ position : relative;
39
+
40
+ & : hover {
41
+ background-color : ${ theme . palette . action . hover } ;
42
+ }
43
+ ` ;
44
+
45
+ const sidebarNavItemActiveStyles = css `
46
+ background-color : ${ theme . palette . action . hover } ;
47
+
48
+ & : before {
49
+ content : "" ;
50
+ display : block;
51
+ width : 3px ;
52
+ height : 100% ;
53
+ position : absolute;
54
+ left : 0 ;
55
+ top : 0 ;
56
+ background-color : ${ theme . palette . secondary . dark } ;
57
+ border-top-left-radius : ${ theme . shape . borderRadius } px;
58
+ border-bottom-left-radius : ${ theme . shape . borderRadius } px;
59
+ }
60
+ ` ;
61
+
17
62
return (
18
63
< NavLink
19
64
end
20
65
to = { href }
21
66
className = { ( { isActive } ) =>
22
67
combineClasses ( [
23
- styles . sidebarNavItem ,
24
- isActive ? styles . sidebarNavItemActive : undefined ,
68
+ sidebarNavItemStyles ,
69
+ isActive ? sidebarNavItemActiveStyles : undefined ,
25
70
] )
26
71
}
27
72
>
@@ -36,28 +81,21 @@ const SidebarNavItem: FC<
36
81
const SidebarNavItemIcon : React . FC < { icon : ElementType } > = ( {
37
82
icon : Icon ,
38
83
} ) => {
39
- const styles = useStyles ( ) ;
40
- return < Icon className = { styles . sidebarNavItemIcon } /> ;
84
+ return < Icon css = { styles . sidebarNavItemIcon } /> ;
41
85
} ;
42
86
43
87
export const Sidebar : React . FC < { template : Template } > = ( { template } ) => {
44
- const styles = useStyles ( ) ;
45
-
46
88
return (
47
- < nav className = { styles . sidebar } >
48
- < Stack
49
- direction = "row"
50
- alignItems = "center"
51
- className = { styles . templateInfo }
52
- >
89
+ < nav css = { styles . sidebar } >
90
+ < Stack direction = "row" alignItems = "center" css = { styles . templateInfo } >
53
91
< Avatar src = { template . icon } variant = "square" fitImage />
54
- < Stack spacing = { 0 } className = { styles . templateData } >
55
- < Link className = { styles . name } to = { `/templates/${ template . name } ` } >
92
+ < Stack spacing = { 0 } css = { styles . templateData } >
93
+ < Link css = { styles . name } to = { `/templates/${ template . name } ` } >
56
94
{ template . display_name !== ""
57
95
? template . display_name
58
96
: template . name }
59
97
</ Link >
60
- < span className = { styles . secondary } > { template . name } </ span >
98
+ < span css = { styles . secondary } > { template . name } </ span >
61
99
</ Stack >
62
100
</ Stack >
63
101
@@ -86,65 +124,34 @@ export const Sidebar: React.FC<{ template: Template }> = ({ template }) => {
86
124
) ;
87
125
} ;
88
126
89
- const useStyles = makeStyles ( ( theme ) => ( {
127
+ const styles = {
90
128
sidebar : {
91
129
width : 245 ,
92
130
flexShrink : 0 ,
93
131
} ,
94
- sidebarNavItem : {
95
- color : "inherit" ,
96
- display : "block" ,
97
- fontSize : 14 ,
98
- textDecoration : "none" ,
99
- padding : theme . spacing ( 1.5 , 1.5 , 1.5 , 2 ) ,
100
- borderRadius : theme . shape . borderRadius / 2 ,
101
- transition : "background-color 0.15s ease-in-out" ,
102
- marginBottom : 1 ,
103
- position : "relative" ,
104
-
105
- "&:hover" : {
106
- backgroundColor : theme . palette . action . hover ,
107
- } ,
108
- } ,
109
- sidebarNavItemActive : {
110
- backgroundColor : theme . palette . action . hover ,
111
-
112
- "&:before" : {
113
- content : '""' ,
114
- display : "block" ,
115
- width : 3 ,
116
- height : "100%" ,
117
- position : "absolute" ,
118
- left : 0 ,
119
- top : 0 ,
120
- backgroundColor : theme . palette . secondary . dark ,
121
- borderTopLeftRadius : theme . shape . borderRadius ,
122
- borderBottomLeftRadius : theme . shape . borderRadius ,
123
- } ,
124
- } ,
125
- sidebarNavItemIcon : {
132
+ sidebarNavItemIcon : ( theme ) => ( {
126
133
width : theme . spacing ( 2 ) ,
127
134
height : theme . spacing ( 2 ) ,
128
- } ,
129
- templateInfo : {
130
- ...theme . typography . body2 ,
135
+ } ) ,
136
+ templateInfo : ( theme ) => ( {
137
+ ...( theme . typography . body2 as CSSObject ) ,
131
138
marginBottom : theme . spacing ( 2 ) ,
132
- } ,
139
+ } ) ,
133
140
templateData : {
134
141
overflow : "hidden" ,
135
142
} ,
136
- name : {
143
+ name : ( theme ) => ( {
137
144
fontWeight : 600 ,
138
145
overflow : "hidden" ,
139
146
textOverflow : "ellipsis" ,
140
147
whiteSpace : "nowrap" ,
141
148
color : theme . palette . text . primary ,
142
149
textDecoration : "none" ,
143
- } ,
144
- secondary : {
150
+ } ) ,
151
+ secondary : ( theme ) => ( {
145
152
color : theme . palette . text . secondary ,
146
153
fontSize : 12 ,
147
154
overflow : "hidden" ,
148
155
textOverflow : "ellipsis" ,
149
- } ,
150
- } ) ) ;
156
+ } ) ,
157
+ } satisfies Record < string , Interpolation < Theme > > ;
0 commit comments