Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Swap and fin

Manav Rathid4ae5c118b31
diff --git a/web/apps/auth/src/pages/auth.tsx b/web/apps/auth/src/pages/auth.tsx
index 9c0502d46a..0040dd0b3b 100644
--- a/web/apps/auth/src/pages/auth.tsx
+++ b/web/apps/auth/src/pages/auth.tsx
@@ -3,6 +3,10 @@ import { stashRedirect } from "@/accounts/services/redirect";
import { EnteLogo } from "@/base/components/EnteLogo";
import { ActivityIndicator } from "@/base/components/mui/ActivityIndicator";
import { NavbarBase } from "@/base/components/Navbar";
+import {
+ OverflowMenu,
+ OverflowMenuOption,
+} from "@/base/components/OverflowMenu";
import { isHTTP401Error } from "@/base/http";
import log from "@/base/log";
import { masterKeyFromSessionIfLoggedIn } from "@/base/session-store";
@@ -10,10 +14,6 @@ import {
HorizontalFlex,
VerticallyCentered,
} from "@ente/shared/components/Container";
-import {
- OverflowMenu,
- OverflowMenuOption,
-} from "@ente/shared/components/OverflowMenu";
import { AUTH_PAGES as PAGES } from "@ente/shared/constants/pages";
import LogoutOutlined from "@mui/icons-material/LogoutOutlined";
import {
@@ -154,7 +154,7 @@ const AuthNavbar: React.FC = () => {
<EnteLogo />
</HorizontalFlex>
<HorizontalFlex position={"absolute"} right="24px">
- <OverflowMenu ariaID={"auth-options"}>
+ <OverflowMenu ariaID="auth-options">
<OverflowMenuOption
color="critical"
startIcon={<LogoutOutlined />}
diff --git a/web/packages/shared/components/OverflowMenu.tsx b/web/packages/shared/components/OverflowMenu.tsx
deleted file mode 100644
index 2469094358..0000000000
--- a/web/packages/shared/components/OverflowMenu.tsx
+++ /dev/null
@@ -1,180 +0,0 @@
-import { FluidContainer } from "@ente/shared/components/Container";
-import MoreHorizIcon from "@mui/icons-material/MoreHoriz";
-import {
- Box,
- IconButton,
- MenuItem,
- styled,
- Typography,
- type ButtonProps,
- type IconButtonProps,
- type PaperProps,
-} from "@mui/material";
-import Menu, { type MenuProps } from "@mui/material/Menu";
-import React, { createContext, useContext, useMemo, useState } from "react";
-
-const OverflowMenuContext = createContext({
- // eslint-disable-next-line @typescript-eslint/no-empty-function
- close: () => {},
-});
-
-interface OverflowMenuProps {
- /**
- * An ARIA identifier for the overflow menu when it is displayed.
- */
- ariaID: string;
- /**
- * The icon for the trigger button.
- *
- * If not provided, then by default the MoreHoriz icon from MUI is used.
- */
- triggerButtonIcon?: React.ReactNode;
- /**
- * Optional additional properties for the trigger icon button.
- */
- triggerButtonProps?: Partial<IconButtonProps>;
- /**
- * Optional additional properties for the MUI {@link Paper} that underlies
- * the {@link Menu}.
- */
- menuPaperProps?: Partial<PaperProps>;
-}
-
-/**
- * A custom MUI {@link Menu} with some Ente specific styling applied to it.
- */
-export const StyledMenu = styled(Menu)`
- & .MuiPaper-root {
- margin: 16px auto;
- box-shadow:
- 0px 0px 6px rgba(0, 0, 0, 0.16),
- 0px 3px 6px rgba(0, 0, 0, 0.12);
- }
- & .MuiList-root {
- padding: 0;
- border: none;
- }
-`;
-
-/**
- * An overflow menu showing {@link OverflowMenuOptions}, alongwith a button to
- * trigger the visibility of the menu.
- */
-export const OverflowMenu: React.FC<
- React.PropsWithChildren<OverflowMenuProps>
-> = ({
- ariaID,
- triggerButtonIcon,
- triggerButtonProps,
- menuPaperProps,
- children,
-}) => {
- const [anchorEl, setAnchorEl] = useState<MenuProps["anchorEl"]>();
- const context = useMemo(
- () => ({ close: () => setAnchorEl(undefined) }),
- [],
- );
- return (
- <OverflowMenuContext.Provider value={context}>
- <IconButton
- onClick={(event) => setAnchorEl(event.currentTarget)}
- aria-controls={anchorEl ? ariaID : undefined}
- aria-haspopup="true"
- aria-expanded={anchorEl ? "true" : undefined}
- {...triggerButtonProps}
- >
- {triggerButtonIcon ?? <MoreHorizIcon />}
- </IconButton>
- <StyledMenu
- id={ariaID}
- {...(anchorEl ? { anchorEl } : {})}
- open={!!anchorEl}
- onClose={() => setAnchorEl(undefined)}
- MenuListProps={{
- disablePadding: true,
- "aria-labelledby": ariaID,
- }}
- slotProps={{
- paper: menuPaperProps,
- }}
- anchorOrigin={{
- vertical: "bottom",
- horizontal: "right",
- }}
- transformOrigin={{
- vertical: "top",
- horizontal: "right",
- }}
- >
- {children}
- </StyledMenu>
- </OverflowMenuContext.Provider>
- );
-};
-
-interface OverflowMenuOptionProps {
- onClick: () => void;
- color?: ButtonProps["color"];
- startIcon?: React.ReactNode;
- endIcon?: React.ReactNode;
- children?: any;
- // To avoid changing old places without an audit, new code should use this
- // option explicitly to fix/tweak the alignment of the button label and
- // icon. Once all existing uses have migrated, can change the default.
- centerAlign?: boolean;
-}
-
-export const OverflowMenuOption: React.FC<OverflowMenuOptionProps> = ({
- onClick,
- color = "primary",
- startIcon,
- endIcon,
- centerAlign,
- children,
-}) => {
- const menuContext = useContext(OverflowMenuContext);
-
- const handleClick = () => {
- onClick();
- menuContext.close();
- };
-
- return (
- <MenuItem
- onClick={handleClick}
- sx={{
- minWidth: 220,
- color: (theme) => theme.palette[color].main,
- padding: 1.5,
- "& .MuiSvgIcon-root": {
- fontSize: "20px",
- },
- }}
- >
- <FluidContainer>
- {startIcon && (
- <Box
- sx={{
- padding: 0,
- marginBlockStart: centerAlign ? "6px" : 0,
- marginRight: 1.5,
- }}
- >
- {startIcon}
- </Box>
- )}
- <Typography fontWeight="bold">{children}</Typography>
- </FluidContainer>
- {endIcon && (
- <Box
- sx={{
- padding: 0,
- marginLeft: 1,
- }}
- >
- {endIcon}
- </Box>
- )}
- </MenuItem>
- );
-};