Add open in new tab for custom links (#2568)

This commit is contained in:
Chris Weaver 2024-09-26 13:01:35 -07:00 committed by GitHub
parent deee2b3513
commit 1f61447b4b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -23,6 +23,7 @@ interface DropdownOptionProps {
onClick?: () => void; onClick?: () => void;
icon: React.ReactNode; icon: React.ReactNode;
label: string; label: string;
openInNewTab?: boolean;
} }
const DropdownOption: React.FC<DropdownOptionProps> = ({ const DropdownOption: React.FC<DropdownOptionProps> = ({
@ -30,6 +31,7 @@ const DropdownOption: React.FC<DropdownOptionProps> = ({
onClick, onClick,
icon, icon,
label, label,
openInNewTab,
}) => { }) => {
const content = ( const content = (
<div className="flex py-3 px-4 cursor-pointer rounded hover:bg-hover-light"> <div className="flex py-3 px-4 cursor-pointer rounded hover:bg-hover-light">
@ -38,11 +40,19 @@ const DropdownOption: React.FC<DropdownOptionProps> = ({
</div> </div>
); );
return href ? ( if (href) {
<Link href={href}>{content}</Link> return (
) : ( <Link
<div onClick={onClick}>{content}</div> href={href}
target={openInNewTab ? "_blank" : undefined}
rel={openInNewTab ? "noopener noreferrer" : undefined}
>
{content}
</Link>
); );
} else {
return <div onClick={onClick}>{content}</div>;
}
}; };
export function UserDropdown({ export function UserDropdown({
@ -173,6 +183,7 @@ export function UserDropdown({
) )
} }
label={item.title} label={item.title}
openInNewTab
/> />
))} ))}