DropdownMenuTrigger.tsx 1004 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import clsx from "clsx";
  2. import { useDevice } from "../App";
  3. import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu";
  4. const MenuTrigger = ({
  5. className = "",
  6. children,
  7. onToggle,
  8. title,
  9. ...rest
  10. }: {
  11. className?: string;
  12. children: React.ReactNode;
  13. onToggle: () => void;
  14. title?: string;
  15. } & Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, "onSelect">) => {
  16. const device = useDevice();
  17. const classNames = clsx(
  18. `dropdown-menu-button ${className}`,
  19. "zen-mode-transition",
  20. {
  21. "dropdown-menu-button--mobile": device.isMobile,
  22. },
  23. ).trim();
  24. return (
  25. <DropdownMenuPrimitive.Trigger
  26. data-dropdown-menu-trigger
  27. data-prevent-outside-click
  28. className={classNames}
  29. onClick={onToggle}
  30. type="button"
  31. data-testid="dropdown-menu-button"
  32. title={title}
  33. {...rest}
  34. >
  35. {children}
  36. </DropdownMenuPrimitive.Trigger>
  37. );
  38. };
  39. export default MenuTrigger;
  40. MenuTrigger.displayName = "DropdownMenuTrigger";