Skip to content

Commit e06c71b

Browse files
committed
emotion: HelpTooltip
1 parent 627d09b commit e06c71b

File tree

1 file changed

+68
-88
lines changed

1 file changed

+68
-88
lines changed

site/src/components/HelpTooltip/HelpTooltip.tsx

Lines changed: 68 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import Link from "@mui/material/Link";
22
import Popover, { PopoverProps } from "@mui/material/Popover";
3-
import { makeStyles } from "@mui/styles";
43
import HelpIcon from "@mui/icons-material/HelpOutline";
54
import OpenInNewIcon from "@mui/icons-material/OpenInNew";
65
import {
@@ -11,9 +10,10 @@ import {
1110
FC,
1211
PropsWithChildren,
1312
} from "react";
14-
import { combineClasses } from "utils/combineClasses";
1513
import { Stack } from "components/Stack/Stack";
1614
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";
1717

1818
type Icon = typeof HelpIcon;
1919

@@ -46,12 +46,24 @@ const useHelpTooltip = () => {
4646
export const HelpPopover: FC<
4747
PopoverProps & { onOpen: () => void; onClose: () => void }
4848
> = ({ onOpen, onClose, children, ...props }) => {
49-
const styles = useStyles({ size: "small" });
49+
const theme = useTheme();
5050

5151
return (
5252
<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+
}}
5567
onClose={onClose}
5668
anchorOrigin={{
5769
vertical: "bottom",
@@ -80,7 +92,7 @@ export const HelpTooltip: FC<PropsWithChildren<HelpTooltipProps>> = ({
8092
iconClassName,
8193
buttonClassName,
8294
}) => {
83-
const styles = useStyles({ size });
95+
const theme = useTheme();
8496
const anchorRef = useRef<HTMLButtonElement>(null);
8597
const [isOpen, setIsOpen] = useState(Boolean(open));
8698
const id = isOpen ? "help-popover" : undefined;
@@ -94,7 +106,24 @@ export const HelpTooltip: FC<PropsWithChildren<HelpTooltipProps>> = ({
94106
<button
95107
ref={anchorRef}
96108
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}
98127
onClick={(event) => {
99128
event.stopPropagation();
100129
setIsOpen(true);
@@ -107,7 +136,13 @@ export const HelpTooltip: FC<PropsWithChildren<HelpTooltipProps>> = ({
107136
}}
108137
aria-label="More info"
109138
>
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+
/>
111146
</button>
112147
<HelpPopover
113148
id={id}
@@ -127,32 +162,20 @@ export const HelpTooltip: FC<PropsWithChildren<HelpTooltipProps>> = ({
127162
export const HelpTooltipTitle: FC<PropsWithChildren<unknown>> = ({
128163
children,
129164
}) => {
130-
const styles = useStyles({});
131-
132-
return <h4 className={styles.title}>{children}</h4>;
165+
return <h4 css={styles.title}>{children}</h4>;
133166
};
134167

135168
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} />;
145170
};
146171

147172
export const HelpTooltipLink: FC<PropsWithChildren<{ href: string }>> = ({
148173
children,
149174
href,
150175
}) => {
151-
const styles = useStyles({});
152-
153176
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} />
156179
{children}
157180
</Link>
158181
);
@@ -165,20 +188,19 @@ export const HelpTooltipAction: FC<
165188
ariaLabel?: string;
166189
}>
167190
> = ({ children, icon: Icon, onClick, ariaLabel }) => {
168-
const styles = useStyles({});
169191
const tooltip = useHelpTooltip();
170192

171193
return (
172194
<button
173195
aria-label={ariaLabel ?? ""}
174-
className={styles.action}
196+
css={styles.action}
175197
onClick={(event) => {
176198
event.stopPropagation();
177199
onClick();
178200
tooltip.onClose();
179201
}}
180202
>
181-
<Icon className={styles.actionIcon} />
203+
<Icon css={styles.actionIcon} />
182204
{children}
183205
</button>
184206
);
@@ -187,10 +209,8 @@ export const HelpTooltipAction: FC<
187209
export const HelpTooltipLinksGroup: FC<PropsWithChildren<unknown>> = ({
188210
children,
189211
}) => {
190-
const styles = useStyles({});
191-
192212
return (
193-
<Stack spacing={1} className={styles.linksGroup}>
213+
<Stack spacing={1} css={styles.linksGroup}>
194214
{children}
195215
</Stack>
196216
);
@@ -216,80 +236,40 @@ const getIconSpacingFromSize = (size?: Size): number => {
216236
}
217237
};
218238

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) => ({
261241
marginTop: 0,
262242
marginBottom: theme.spacing(1),
263243
color: theme.palette.text.primary,
264244
fontSize: 14,
265245
lineHeight: "120%",
266246
fontWeight: 600,
267-
},
247+
}),
268248

269-
text: {
249+
text: (theme) => ({
270250
marginTop: theme.spacing(0.5),
271251
marginBottom: theme.spacing(0.5),
272-
...theme.typography.body2,
273-
},
252+
...(theme.typography.body2 as CSSObject),
253+
}),
274254

275-
link: {
255+
link: (theme) => ({
276256
display: "flex",
277257
alignItems: "center",
278-
...theme.typography.body2,
279-
},
258+
...(theme.typography.body2 as CSSObject),
259+
}),
280260

281-
linkIcon: {
261+
linkIcon: (theme) => ({
282262
color: "inherit",
283263
width: 14,
284264
height: 14,
285265
marginRight: theme.spacing(1),
286-
},
266+
}),
287267

288-
linksGroup: {
268+
linksGroup: (theme) => ({
289269
marginTop: theme.spacing(2),
290-
},
270+
}),
291271

292-
action: {
272+
action: (theme) => ({
293273
display: "flex",
294274
alignItems: "center",
295275
background: "none",
@@ -298,12 +278,12 @@ const useStyles = makeStyles((theme) => ({
298278
padding: 0,
299279
cursor: "pointer",
300280
fontSize: 14,
301-
},
281+
}),
302282

303-
actionIcon: {
283+
actionIcon: (theme) => ({
304284
color: "inherit",
305285
width: 14,
306286
height: 14,
307287
marginRight: theme.spacing(1),
308-
},
309-
}));
288+
}),
289+
} satisfies Record<string, Interpolation<Theme>>;

0 commit comments

Comments
 (0)