Skip to content

Commit 5993ea1

Browse files
committed
Popover supports both Button and LinkButton
1 parent d18db78 commit 5993ea1

1 file changed

Lines changed: 30 additions & 17 deletions

File tree

apps/webapp/app/components/primitives/Popover.tsx

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as React from "react";
77
import { DropdownIcon } from "~/assets/icons/DropdownIcon";
88
import * as useShortcutKeys from "~/hooks/useShortcutKeys";
99
import { cn } from "~/utils/cn";
10-
import { type ButtonContentPropsType, LinkButton } from "./Buttons";
10+
import { type ButtonContentPropsType, Button, LinkButton } from "./Buttons";
1111
import { Paragraph, type ParagraphVariant } from "./Paragraph";
1212
import { ShortcutKey } from "./ShortcutKey";
1313
import { type RenderIcon } from "./Icon";
@@ -60,32 +60,45 @@ function PopoverMenuItem({
6060
variant = { variant: "small-menu-item" },
6161
leadingIconClassName,
6262
className,
63+
onClick,
64+
disabled,
6365
}: {
64-
to: string;
66+
to?: string;
6567
icon?: RenderIcon;
6668
title: React.ReactNode;
6769
isSelected?: boolean;
6870
variant?: ButtonContentPropsType;
6971
leadingIconClassName?: string;
7072
className?: string;
73+
onClick?: React.MouseEventHandler;
74+
disabled?: boolean;
7175
}) {
76+
const commonProps = {
77+
variant: variant.variant,
78+
LeadingIcon: icon,
79+
leadingIconClassName,
80+
fullWidth: true,
81+
textAlignLeft: true,
82+
TrailingIcon: isSelected ? CheckIcon : undefined,
83+
className: cn(
84+
"group-hover:bg-charcoal-700",
85+
isSelected ? "bg-charcoal-750 group-hover:bg-charcoal-600/50" : undefined,
86+
className
87+
),
88+
} as const;
89+
90+
if (to) {
91+
return (
92+
<LinkButton to={to} {...commonProps} onClick={onClick}>
93+
{title}
94+
</LinkButton>
95+
);
96+
}
97+
7298
return (
73-
<LinkButton
74-
to={to}
75-
variant={variant.variant}
76-
LeadingIcon={icon}
77-
leadingIconClassName={leadingIconClassName}
78-
fullWidth
79-
textAlignLeft
80-
TrailingIcon={isSelected ? CheckIcon : undefined}
81-
className={cn(
82-
"group-hover:bg-charcoal-700",
83-
isSelected ? "bg-charcoal-750 group-hover:bg-charcoal-600/50" : undefined,
84-
className
85-
)}
86-
>
99+
<Button {...commonProps} onClick={onClick} disabled={disabled} type="button">
87100
{title}
88-
</LinkButton>
101+
</Button>
89102
);
90103
}
91104

0 commit comments

Comments
 (0)