FIX[WebApp]: Splits the menu.tsx in two files

This is so that SheetListMenu and SheetRenameDialog are on its own files.

Also renamed isOpen => open and close => onClose
This commit is contained in:
Nicolás Hatcher
2024-12-14 22:12:39 +01:00
committed by Nicolás Hatcher Andrés
parent 23814ec18c
commit fb764fed1c
4 changed files with 105 additions and 102 deletions

View File

@@ -0,0 +1,99 @@
import { styled } from "@mui/material";
import Menu from "@mui/material/Menu";
import MenuItem from "@mui/material/MenuItem";
import { Check } from "lucide-react";
import type { SheetOptions } from "./types";
function isWhiteColor(color: string): boolean {
return ["#FFF", "#FFFFFF"].includes(color);
}
interface SheetListMenuProps {
open: boolean;
onClose: () => void;
anchorEl: HTMLButtonElement | null;
onSheetSelected: (index: number) => void;
sheetOptionsList: SheetOptions[];
selectedIndex: number;
}
const SheetListMenu = (properties: SheetListMenuProps) => {
const {
open,
onClose,
anchorEl,
onSheetSelected,
sheetOptionsList,
selectedIndex,
} = properties;
const hasColors = sheetOptionsList.some((tab) => !isWhiteColor(tab.color));
return (
<StyledMenu
open={open}
onClose={onClose}
anchorEl={anchorEl}
anchorOrigin={{
vertical: "top",
horizontal: "left",
}}
transformOrigin={{
vertical: "bottom",
horizontal: 6,
}}
>
{sheetOptionsList.map((tab, index) => (
<StyledMenuItem
key={tab.sheetId}
onClick={() => onSheetSelected(index)}
>
{index === selectedIndex ? (
<Check
style={{ width: "16px", height: "16px", marginRight: "8px" }}
/>
) : (
<div
style={{ width: "16px", height: "16px", marginRight: "8px" }}
/>
)}
{hasColors && <ItemColor style={{ backgroundColor: tab.color }} />}
<ItemName
style={{ fontWeight: index === selectedIndex ? "bold" : "normal" }}
>
{tab.name}
</ItemName>
</StyledMenuItem>
))}
</StyledMenu>
);
};
const StyledMenu = styled(Menu)({
"& .MuiPaper-root": {
borderRadius: 8,
padding: 4,
},
"& .MuiList-padding": {
padding: 0,
},
});
const StyledMenuItem = styled(MenuItem)({
padding: 8,
borderRadius: 4,
});
const ItemColor = styled("div")`
width: 12px;
height: 12px;
border-radius: 4px;
margin-right: 8px;
`;
const ItemName = styled("div")`
font-size: 12px;
color: #333;
`;
export default SheetListMenu;

View File

@@ -1,15 +1,7 @@
import { Dialog, TextField, styled } from "@mui/material"; import { Dialog, TextField, styled } from "@mui/material";
import Menu from "@mui/material/Menu";
import MenuItem from "@mui/material/MenuItem";
import { Check } from "lucide-react";
import { useState } from "react"; import { useState } from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { theme } from "../../theme"; import { theme } from "../../theme";
import type { SheetOptions } from "./types";
function isWhiteColor(color: string): boolean {
return ["#FFF", "#FFFFFF"].includes(color);
}
interface SheetRenameDialogProps { interface SheetRenameDialogProps {
isOpen: boolean; isOpen: boolean;
@@ -18,7 +10,7 @@ interface SheetRenameDialogProps {
defaultName: string; defaultName: string;
} }
export const SheetRenameDialog = (properties: SheetRenameDialogProps) => { const SheetRenameDialog = (properties: SheetRenameDialogProps) => {
const { t } = useTranslation(); const { t } = useTranslation();
const [name, setName] = useState(properties.defaultName); const [name, setName] = useState(properties.defaultName);
const handleClose = () => { const handleClose = () => {
@@ -84,94 +76,6 @@ export const SheetRenameDialog = (properties: SheetRenameDialogProps) => {
); );
}; };
interface SheetListMenuProps {
isOpen: boolean;
close: () => void;
anchorEl: HTMLButtonElement | null;
onSheetSelected: (index: number) => void;
sheetOptionsList: SheetOptions[];
selectedIndex: number;
}
const SheetListMenu = (properties: SheetListMenuProps) => {
const {
isOpen,
close,
anchorEl,
onSheetSelected,
sheetOptionsList,
selectedIndex,
} = properties;
const hasColors = sheetOptionsList.some((tab) => !isWhiteColor(tab.color));
return (
<StyledMenu
open={isOpen}
onClose={close}
anchorEl={anchorEl}
anchorOrigin={{
vertical: "top",
horizontal: "left",
}}
transformOrigin={{
vertical: "bottom",
horizontal: 6,
}}
>
{sheetOptionsList.map((tab, index) => (
<StyledMenuItem
key={tab.sheetId}
onClick={() => onSheetSelected(index)}
>
{index === selectedIndex ? (
<Check
style={{ width: "16px", height: "16px", marginRight: "8px" }}
/>
) : (
<div
style={{ width: "16px", height: "16px", marginRight: "8px" }}
/>
)}
{hasColors && <ItemColor style={{ backgroundColor: tab.color }} />}
<ItemName
style={{ fontWeight: index === selectedIndex ? "bold" : "normal" }}
>
{tab.name}
</ItemName>
</StyledMenuItem>
))}
</StyledMenu>
);
};
const StyledMenu = styled(Menu)({
"& .MuiPaper-root": {
borderRadius: 8,
padding: 4,
},
"& .MuiList-padding": {
padding: 0,
},
});
const StyledMenuItem = styled(MenuItem)({
padding: 8,
borderRadius: 4,
});
const ItemColor = styled("div")`
width: 12px;
height: 12px;
border-radius: 4px;
margin-right: 8px;
`;
const ItemName = styled("div")`
font-size: 12px;
color: #333;
`;
const StyledDialogTitle = styled("div")` const StyledDialogTitle = styled("div")`
display: flex; display: flex;
align-items: center; align-items: center;
@@ -246,4 +150,4 @@ const StyledButton = styled("div")`
} }
`; `;
export default SheetListMenu; export default SheetRenameDialog;

View File

@@ -6,7 +6,7 @@ import { theme } from "../../theme";
import { NAVIGATION_HEIGHT } from "../constants"; import { NAVIGATION_HEIGHT } from "../constants";
import { StyledButton } from "../toolbar"; import { StyledButton } from "../toolbar";
import type { WorkbookState } from "../workbookState"; import type { WorkbookState } from "../workbookState";
import SheetListMenu from "./menus"; import SheetListMenu from "./SheetListMenu";
import Sheet from "./sheet"; import Sheet from "./sheet";
import type { SheetOptions } from "./types"; import type { SheetOptions } from "./types";
@@ -77,8 +77,8 @@ function Navigation(props: NavigationProps) {
</Advert> </Advert>
<SheetListMenu <SheetListMenu
anchorEl={anchorEl} anchorEl={anchorEl}
isOpen={open} open={open}
close={handleClose} onClose={handleClose}
sheetOptionsList={sheets} sheetOptionsList={sheets}
onSheetSelected={(index) => { onSheetSelected={(index) => {
onSheetSelected(index); onSheetSelected(index);

View File

@@ -4,7 +4,7 @@ import { useRef, useState } from "react";
import ColorPicker from "../colorPicker"; import ColorPicker from "../colorPicker";
import { isInReferenceMode } from "../editor/util"; import { isInReferenceMode } from "../editor/util";
import type { WorkbookState } from "../workbookState"; import type { WorkbookState } from "../workbookState";
import { SheetRenameDialog } from "./menus"; import SheetRenameDialog from "./SheetRenameDialog";
interface SheetProps { interface SheetProps {
name: string; name: string;