EnteMenuItem.tsx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. import {
  2. SpaceBetweenFlex,
  3. VerticallyCenteredFlex,
  4. } from "@ente/shared/components/Container";
  5. import {
  6. Box,
  7. ButtonProps,
  8. MenuItem,
  9. Typography,
  10. TypographyProps,
  11. } from "@mui/material";
  12. import React from "react";
  13. import { CaptionedText } from "../CaptionedText";
  14. import PublicShareSwitch from "../Collections/CollectionShare/publicShare/switch";
  15. import ChangeDirectoryOption from "../Directory/changeOption";
  16. interface Iprops {
  17. onClick: () => void;
  18. color?: ButtonProps["color"];
  19. variant?:
  20. | "primary"
  21. | "captioned"
  22. | "toggle"
  23. | "secondary"
  24. | "mini"
  25. | "path";
  26. fontWeight?: TypographyProps["fontWeight"];
  27. startIcon?: React.ReactNode;
  28. endIcon?: React.ReactNode;
  29. label?: string;
  30. subText?: string;
  31. subIcon?: React.ReactNode;
  32. checked?: boolean;
  33. labelComponent?: React.ReactNode;
  34. disabled?: boolean;
  35. }
  36. export function EnteMenuItem({
  37. onClick,
  38. color = "primary",
  39. startIcon,
  40. endIcon,
  41. label,
  42. subText,
  43. subIcon,
  44. checked,
  45. variant = "primary",
  46. fontWeight = "bold",
  47. labelComponent,
  48. disabled = false,
  49. }: Iprops) {
  50. const handleButtonClick = () => {
  51. if (variant === "path" || variant === "toggle") {
  52. return;
  53. }
  54. onClick();
  55. };
  56. const handleIconClick = () => {
  57. if (variant !== "path" && variant !== "toggle") {
  58. return;
  59. }
  60. onClick();
  61. };
  62. return (
  63. <MenuItem
  64. disabled={disabled}
  65. onClick={handleButtonClick}
  66. sx={{
  67. width: "100%",
  68. color: (theme) =>
  69. variant !== "captioned" && theme.palette[color].main,
  70. ...(variant !== "secondary" &&
  71. variant !== "mini" && {
  72. backgroundColor: (theme) => theme.colors.fill.faint,
  73. }),
  74. "&:hover": {
  75. backgroundColor: (theme) => theme.colors.fill.faintPressed,
  76. },
  77. "& .MuiSvgIcon-root": {
  78. fontSize: "20px",
  79. },
  80. p: 0,
  81. borderRadius: "4px",
  82. }}
  83. >
  84. <SpaceBetweenFlex sx={{ pl: "16px", pr: "12px" }}>
  85. <VerticallyCenteredFlex sx={{ py: "14px" }} gap={"10px"}>
  86. {startIcon && startIcon}
  87. <Box px={"2px"}>
  88. {labelComponent ? (
  89. labelComponent
  90. ) : variant === "captioned" ? (
  91. <CaptionedText
  92. color={color}
  93. mainText={label}
  94. subText={subText}
  95. subIcon={subIcon}
  96. />
  97. ) : variant === "mini" ? (
  98. <Typography variant="mini" color="text.muted">
  99. {label}
  100. </Typography>
  101. ) : (
  102. <Typography fontWeight={fontWeight}>
  103. {label}
  104. </Typography>
  105. )}
  106. </Box>
  107. </VerticallyCenteredFlex>
  108. <VerticallyCenteredFlex gap={"4px"}>
  109. {endIcon && endIcon}
  110. {variant === "toggle" && (
  111. <PublicShareSwitch
  112. checked={checked}
  113. onClick={handleIconClick}
  114. />
  115. )}
  116. {variant === "path" && (
  117. <ChangeDirectoryOption
  118. changeExportDirectory={handleIconClick}
  119. />
  120. )}
  121. </VerticallyCenteredFlex>
  122. </SpaceBetweenFlex>
  123. </MenuItem>
  124. );
  125. }