1
1
import Link from "@mui/material/Link" ;
2
2
import Popover , { PopoverProps } from "@mui/material/Popover" ;
3
- import { makeStyles } from "@mui/styles" ;
4
3
import HelpIcon from "@mui/icons-material/HelpOutline" ;
5
4
import OpenInNewIcon from "@mui/icons-material/OpenInNew" ;
6
5
import {
@@ -11,9 +10,10 @@ import {
11
10
FC ,
12
11
PropsWithChildren ,
13
12
} from "react" ;
14
- import { combineClasses } from "utils/combineClasses" ;
15
13
import { Stack } from "components/Stack/Stack" ;
16
14
import Box , { BoxProps } from "@mui/material/Box" ;
15
+ import { type CSSObject , css as className } from "@emotion/css" ;
16
+ import { css , type Interpolation , type Theme , useTheme } from "@emotion/react" ;
17
17
18
18
type Icon = typeof HelpIcon ;
19
19
@@ -46,12 +46,24 @@ const useHelpTooltip = () => {
46
46
export const HelpPopover : FC <
47
47
PopoverProps & { onOpen : ( ) => void ; onClose : ( ) => void }
48
48
> = ( { onOpen, onClose, children, ...props } ) => {
49
- const styles = useStyles ( { size : "small" } ) ;
49
+ const theme = useTheme ( ) ;
50
50
51
51
return (
52
52
< Popover
53
- className = { styles . popover }
54
- classes = { { paper : styles . popoverPaper } }
53
+ className = { className `
54
+ pointer-events : none;
55
+ ` }
56
+ classes = { {
57
+ paper : className `
58
+ ${ theme . typography . body2 as CSSObject }
59
+
60
+ margin-top : ${ theme . spacing ( 0.5 ) } ;
61
+ width : ${ theme . spacing ( 38 ) } ;
62
+ padding : ${ theme . spacing ( 2.5 ) } ;
63
+ color : ${ theme . palette . text . secondary } ;
64
+ pointer-events : auto;
65
+ ` ,
66
+ } }
55
67
onClose = { onClose }
56
68
anchorOrigin = { {
57
69
vertical : "bottom" ,
@@ -80,7 +92,7 @@ export const HelpTooltip: FC<PropsWithChildren<HelpTooltipProps>> = ({
80
92
iconClassName,
81
93
buttonClassName,
82
94
} ) => {
83
- const styles = useStyles ( { size } ) ;
95
+ const theme = useTheme ( ) ;
84
96
const anchorRef = useRef < HTMLButtonElement > ( null ) ;
85
97
const [ isOpen , setIsOpen ] = useState ( Boolean ( open ) ) ;
86
98
const id = isOpen ? "help-popover" : undefined ;
@@ -94,7 +106,24 @@ export const HelpTooltip: FC<PropsWithChildren<HelpTooltipProps>> = ({
94
106
< button
95
107
ref = { anchorRef }
96
108
aria-describedby = { id }
97
- className = { combineClasses ( [ styles . button , buttonClassName ] ) }
109
+ css = { css `
110
+ display : flex;
111
+ align-items : center;
112
+ justify-content : center;
113
+ width : ${ theme . spacing ( getButtonSpacingFromSize ( size ) ) } ;
114
+ height : ${ theme . spacing ( getButtonSpacingFromSize ( size ) ) } ;
115
+ padding : 0 ;
116
+ border : 0 ;
117
+ background : transparent;
118
+ color : ${ theme . palette . text . primary } ;
119
+ opacity : 0.5 ;
120
+ cursor : pointer;
121
+
122
+ & : hover {
123
+ opacity : 0.75 ;
124
+ }
125
+ ` }
126
+ className = { buttonClassName }
98
127
onClick = { ( event ) => {
99
128
event . stopPropagation ( ) ;
100
129
setIsOpen ( true ) ;
@@ -107,7 +136,13 @@ export const HelpTooltip: FC<PropsWithChildren<HelpTooltipProps>> = ({
107
136
} }
108
137
aria-label = "More info"
109
138
>
110
- < Icon className = { combineClasses ( [ styles . icon , iconClassName ] ) } />
139
+ < Icon
140
+ css = { {
141
+ width : theme . spacing ( getIconSpacingFromSize ( size ) ) ,
142
+ height : theme . spacing ( getIconSpacingFromSize ( size ) ) ,
143
+ } }
144
+ className = { iconClassName }
145
+ />
111
146
</ button >
112
147
< HelpPopover
113
148
id = { id }
@@ -127,32 +162,20 @@ export const HelpTooltip: FC<PropsWithChildren<HelpTooltipProps>> = ({
127
162
export const HelpTooltipTitle : FC < PropsWithChildren < unknown > > = ( {
128
163
children,
129
164
} ) => {
130
- const styles = useStyles ( { } ) ;
131
-
132
- return < h4 className = { styles . title } > { children } </ h4 > ;
165
+ return < h4 css = { styles . title } > { children } </ h4 > ;
133
166
} ;
134
167
135
168
export const HelpTooltipText = ( props : BoxProps ) => {
136
- const styles = useStyles ( { } ) ;
137
-
138
- return (
139
- < Box
140
- component = "p"
141
- { ...props }
142
- className = { combineClasses ( [ styles . text , props . className ] ) }
143
- />
144
- ) ;
169
+ return < Box component = "p" css = { styles . text } { ...props } /> ;
145
170
} ;
146
171
147
172
export const HelpTooltipLink : FC < PropsWithChildren < { href : string } > > = ( {
148
173
children,
149
174
href,
150
175
} ) => {
151
- const styles = useStyles ( { } ) ;
152
-
153
176
return (
154
- < Link href = { href } target = "_blank" rel = "noreferrer" className = { styles . link } >
155
- < OpenInNewIcon className = { styles . linkIcon } />
177
+ < Link href = { href } target = "_blank" rel = "noreferrer" css = { styles . link } >
178
+ < OpenInNewIcon css = { styles . linkIcon } />
156
179
{ children }
157
180
</ Link >
158
181
) ;
@@ -165,20 +188,19 @@ export const HelpTooltipAction: FC<
165
188
ariaLabel ?: string ;
166
189
} >
167
190
> = ( { children, icon : Icon , onClick, ariaLabel } ) => {
168
- const styles = useStyles ( { } ) ;
169
191
const tooltip = useHelpTooltip ( ) ;
170
192
171
193
return (
172
194
< button
173
195
aria-label = { ariaLabel ?? "" }
174
- className = { styles . action }
196
+ css = { styles . action }
175
197
onClick = { ( event ) => {
176
198
event . stopPropagation ( ) ;
177
199
onClick ( ) ;
178
200
tooltip . onClose ( ) ;
179
201
} }
180
202
>
181
- < Icon className = { styles . actionIcon } />
203
+ < Icon css = { styles . actionIcon } />
182
204
{ children }
183
205
</ button >
184
206
) ;
@@ -187,10 +209,8 @@ export const HelpTooltipAction: FC<
187
209
export const HelpTooltipLinksGroup : FC < PropsWithChildren < unknown > > = ( {
188
210
children,
189
211
} ) => {
190
- const styles = useStyles ( { } ) ;
191
-
192
212
return (
193
- < Stack spacing = { 1 } className = { styles . linksGroup } >
213
+ < Stack spacing = { 1 } css = { styles . linksGroup } >
194
214
{ children }
195
215
</ Stack >
196
216
) ;
@@ -216,80 +236,40 @@ const getIconSpacingFromSize = (size?: Size): number => {
216
236
}
217
237
} ;
218
238
219
- const useStyles = makeStyles ( ( theme ) => ( {
220
- button : {
221
- display : "flex" ,
222
- alignItems : "center" ,
223
- justifyContent : "center" ,
224
- width : ( { size } : { size ?: Size } ) =>
225
- theme . spacing ( getButtonSpacingFromSize ( size ) ) ,
226
- height : ( { size } : { size ?: Size } ) =>
227
- theme . spacing ( getButtonSpacingFromSize ( size ) ) ,
228
- padding : 0 ,
229
- border : 0 ,
230
- background : "transparent" ,
231
- color : theme . palette . text . primary ,
232
- opacity : 0.5 ,
233
- cursor : "pointer" ,
234
-
235
- "&:hover" : {
236
- opacity : 0.75 ,
237
- } ,
238
- } ,
239
-
240
- icon : {
241
- width : ( { size } : { size ?: Size } ) =>
242
- theme . spacing ( getIconSpacingFromSize ( size ) ) ,
243
- height : ( { size } : { size ?: Size } ) =>
244
- theme . spacing ( getIconSpacingFromSize ( size ) ) ,
245
- } ,
246
-
247
- popover : {
248
- pointerEvents : "none" ,
249
- } ,
250
-
251
- popoverPaper : {
252
- marginTop : theme . spacing ( 0.5 ) ,
253
- width : theme . spacing ( 38 ) ,
254
- padding : theme . spacing ( 2.5 ) ,
255
- color : theme . palette . text . secondary ,
256
- pointerEvents : "auto" ,
257
- ...theme . typography . body2 ,
258
- } ,
259
-
260
- title : {
239
+ const styles = {
240
+ title : ( theme ) => ( {
261
241
marginTop : 0 ,
262
242
marginBottom : theme . spacing ( 1 ) ,
263
243
color : theme . palette . text . primary ,
264
244
fontSize : 14 ,
265
245
lineHeight : "120%" ,
266
246
fontWeight : 600 ,
267
- } ,
247
+ } ) ,
268
248
269
- text : {
249
+ text : ( theme ) => ( {
270
250
marginTop : theme . spacing ( 0.5 ) ,
271
251
marginBottom : theme . spacing ( 0.5 ) ,
272
- ...theme . typography . body2 ,
273
- } ,
252
+ ...( theme . typography . body2 as CSSObject ) ,
253
+ } ) ,
274
254
275
- link : {
255
+ link : ( theme ) => ( {
276
256
display : "flex" ,
277
257
alignItems : "center" ,
278
- ...theme . typography . body2 ,
279
- } ,
258
+ ...( theme . typography . body2 as CSSObject ) ,
259
+ } ) ,
280
260
281
- linkIcon : {
261
+ linkIcon : ( theme ) => ( {
282
262
color : "inherit" ,
283
263
width : 14 ,
284
264
height : 14 ,
285
265
marginRight : theme . spacing ( 1 ) ,
286
- } ,
266
+ } ) ,
287
267
288
- linksGroup : {
268
+ linksGroup : ( theme ) => ( {
289
269
marginTop : theme . spacing ( 2 ) ,
290
- } ,
270
+ } ) ,
291
271
292
- action : {
272
+ action : ( theme ) => ( {
293
273
display : "flex" ,
294
274
alignItems : "center" ,
295
275
background : "none" ,
@@ -298,12 +278,12 @@ const useStyles = makeStyles((theme) => ({
298
278
padding : 0 ,
299
279
cursor : "pointer" ,
300
280
fontSize : 14 ,
301
- } ,
281
+ } ) ,
302
282
303
- actionIcon : {
283
+ actionIcon : ( theme ) => ( {
304
284
color : "inherit" ,
305
285
width : 14 ,
306
286
height : 14 ,
307
287
marginRight : theme . spacing ( 1 ) ,
308
- } ,
309
- } ) ) ;
288
+ } ) ,
289
+ } satisfies Record < string , Interpolation < Theme > > ;
0 commit comments