Skip to content

Commit b2370af

Browse files
committed
refactor: replace deprecated Popover in Notifications
1 parent 44e14ac commit b2370af

File tree

1 file changed

+41
-34
lines changed

1 file changed

+41
-34
lines changed

site/src/pages/WorkspacePage/WorkspaceNotifications/Notifications.tsx

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { type Interpolation, type Theme, useTheme } from "@emotion/react";
1+
import { useTheme, type Interpolation, type Theme } from "@emotion/react";
22
import type { AlertProps } from "components/Alert/Alert";
33
import { Button, type ButtonProps } from "components/Button/Button";
4-
import {
5-
Popover,
6-
PopoverContent,
7-
PopoverTrigger,
8-
usePopover,
9-
} from "components/deprecated/Popover/Popover";
104
import { Pill } from "components/Pill/Pill";
11-
import type { FC, ReactNode } from "react";
5+
import {
6+
Tooltip,
7+
TooltipContent,
8+
TooltipProvider,
9+
TooltipTrigger,
10+
} from "components/Tooltip/Tooltip";
11+
import { useState, type FC, type ReactNode } from "react";
1212
import type { ThemeRole } from "theme/roles";
1313

1414
export type NotificationItem = {
@@ -22,55 +22,62 @@ type NotificationsProps = {
2222
items: NotificationItem[];
2323
severity: ThemeRole;
2424
icon: ReactNode;
25+
isTooltipOpen: boolean;
2526
};
2627

2728
export const Notifications: FC<NotificationsProps> = ({
2829
items,
2930
severity,
3031
icon,
3132
}) => {
33+
const [isOpen, setIsOpen] = useState(false);
3234
const theme = useTheme();
3335

3436
return (
35-
<Popover mode="hover">
36-
<PopoverTrigger>
37-
<div
38-
css={styles.pillContainer}
39-
data-testid={`${severity}-notifications`}
40-
>
41-
<NotificationPill items={items} severity={severity} icon={icon} />
42-
</div>
43-
</PopoverTrigger>
44-
<PopoverContent
45-
horizontal="right"
46-
css={{
47-
"& .MuiPaper-root": {
37+
<TooltipProvider>
38+
<Tooltip open={isOpen} onOpenChange={setIsOpen} delayDuration={0}>
39+
<TooltipTrigger asChild>
40+
<div
41+
css={styles.pillContainer}
42+
data-testid={`${severity}-notifications`}
43+
>
44+
<NotificationPill
45+
items={items}
46+
severity={severity}
47+
icon={icon}
48+
isTooltipOpen={isOpen}
49+
/>
50+
</div>
51+
</TooltipTrigger>
52+
<TooltipContent
53+
align="end"
54+
collisionPadding={16}
55+
className="max-w-[400px] p-0 bg-surface-secondary border-surface-quaternary text-sm text-white"
56+
style={{
4857
borderColor: theme.roles[severity].outline,
49-
maxWidth: 400,
50-
},
51-
}}
52-
>
53-
{items.map((n) => (
54-
<NotificationItem notification={n} key={n.title} />
55-
))}
56-
</PopoverContent>
57-
</Popover>
58+
}}
59+
>
60+
{items.map((n) => (
61+
<NotificationItem notification={n} key={n.title} />
62+
))}
63+
</TooltipContent>
64+
</Tooltip>
65+
</TooltipProvider>
5866
);
5967
};
6068

6169
const NotificationPill: FC<NotificationsProps> = ({
6270
items,
6371
severity,
6472
icon,
73+
isTooltipOpen,
6574
}) => {
66-
const popover = usePopover();
67-
6875
return (
6976
<Pill
7077
icon={icon}
7178
css={(theme) => ({
7279
"& svg": { color: theme.roles[severity].outline },
73-
borderColor: popover.open ? theme.roles[severity].outline : undefined,
80+
borderColor: isTooltipOpen ? theme.roles[severity].outline : undefined,
7481
})}
7582
>
7683
{items.length}
@@ -99,7 +106,7 @@ export const NotificationActionButton: FC<ButtonProps> = (props) => {
99106
};
100107

101108
const styles = {
102-
// Adds some spacing from the popover content
109+
// Adds some spacing from the Tooltip content
103110
pillContainer: {
104111
padding: "8px 0",
105112
},

0 commit comments

Comments
 (0)