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