DropdownMenuItemLink.tsx 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import React from "react";
  2. import MenuItemContent from "./DropdownMenuItemContent";
  3. import {
  4. getDropdownMenuItemClassName,
  5. useHandleDropdownMenuItemClick,
  6. } from "./common";
  7. import type { JSX } from "react";
  8. const DropdownMenuItemLink = ({
  9. icon,
  10. shortcut,
  11. href,
  12. children,
  13. onSelect,
  14. className = "",
  15. selected,
  16. rel = "noopener",
  17. ...rest
  18. }: {
  19. href: string;
  20. icon?: JSX.Element;
  21. children: React.ReactNode;
  22. shortcut?: string;
  23. className?: string;
  24. selected?: boolean;
  25. onSelect?: (event: Event) => void;
  26. rel?: string;
  27. } & React.AnchorHTMLAttributes<HTMLAnchorElement>) => {
  28. const handleClick = useHandleDropdownMenuItemClick(rest.onClick, onSelect);
  29. return (
  30. // eslint-disable-next-line react/jsx-no-target-blank
  31. <a
  32. {...rest}
  33. href={href}
  34. target="_blank"
  35. rel={rel || "noopener"}
  36. className={getDropdownMenuItemClassName(className, selected)}
  37. title={rest.title ?? rest["aria-label"]}
  38. onClick={handleClick}
  39. >
  40. <MenuItemContent icon={icon} shortcut={shortcut}>
  41. {children}
  42. </MenuItemContent>
  43. </a>
  44. );
  45. };
  46. export default DropdownMenuItemLink;
  47. DropdownMenuItemLink.displayName = "DropdownMenuItemLink";