Commit a5a80933 authored by chenshouchao's avatar chenshouchao

feat: 新增菜单下拉选择组件

parent 1ac5fb6c
import * as React from "react"; import * as React from "react";
import Menu from "@mui/material/Menu"; import Menu from "@mui/material/Menu";
import MenuItem from "@mui/material/MenuItem"; import MenuItem from "@mui/material/MenuItem";
import CheckIcon from "@mui/icons-material/Check";
import { ThemeProvider, createTheme } from "@mui/material/styles"; import { ThemeProvider, createTheme } from "@mui/material/styles";
type IOption = { type IOption = {
...@@ -12,30 +13,49 @@ type IMyMenuProps = { ...@@ -12,30 +13,49 @@ type IMyMenuProps = {
children: React.ReactNode; children: React.ReactNode;
options: Array<IOption>; options: Array<IOption>;
value: string; value: string;
setValue?: any;
}; };
const theme = createTheme({ const theme = createTheme({
components: { components: {
// Name of the component MuiMenu: {
styleOverrides: {
root: {
maxHeight: "260px",
overflowY: "scroll",
},
},
},
MuiMenuItem: { MuiMenuItem: {
styleOverrides: { styleOverrides: {
// Name of the slot
root: { root: {
fontSize: "12px", fontSize: "14px",
lineHeight: "36px",
display: "flex",
justifyContent: "space-between",
":hover": { ":hover": {
color: "red", color: "rgba(19, 112, 255, 1)",
}, },
"&.Mui-selected": { "&.Mui-selected": {
backgroundColor: "#2a68c9", backgroundColor: "#fff",
color: "rgba(19, 112, 255, 1)",
}, },
}, },
}, },
}, },
MuiSvgIcon: {
styleOverrides: {
root: {
width: "16px",
height: "16px",
},
},
},
}, },
}); });
const MyMenu = (props: IMyMenuProps) => { const MyMenu = (props: IMyMenuProps) => {
const { children, options, value } = props; const { children, options, value, setValue } = props;
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null); const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
const open = Boolean(anchorEl); const open = Boolean(anchorEl);
const handleClick = (event: React.MouseEvent<HTMLDivElement>) => { const handleClick = (event: React.MouseEvent<HTMLDivElement>) => {
...@@ -43,7 +63,7 @@ const MyMenu = (props: IMyMenuProps) => { ...@@ -43,7 +63,7 @@ const MyMenu = (props: IMyMenuProps) => {
}; };
const handleClose = (value: string) => { const handleClose = (value: string) => {
setAnchorEl(null); setAnchorEl(null);
console.log(value); setValue && setValue(value);
}; };
return ( return (
...@@ -66,8 +86,8 @@ const MyMenu = (props: IMyMenuProps) => { ...@@ -66,8 +86,8 @@ const MyMenu = (props: IMyMenuProps) => {
selected={value === option.value} selected={value === option.value}
key={index} key={index}
> >
{option.label} <span>{option.label}</span>
{value} {value === option.value && <CheckIcon />}
</MenuItem> </MenuItem>
); );
})} })}
......
...@@ -12,7 +12,6 @@ import { observer } from "mobx-react-lite"; ...@@ -12,7 +12,6 @@ import { observer } from "mobx-react-lite";
import { useLocation } from "react-router-dom"; import { useLocation } from "react-router-dom";
import projectImg from "@/assets/project/projectIconSmall.svg"; import projectImg from "@/assets/project/projectIconSmall.svg";
import MyMenu from "@/components/mui/MyMenu";
import WorkbenchTemplate from "./workbenchTemplate"; import WorkbenchTemplate from "./workbenchTemplate";
import WorkbenchList from "./workbenchList"; import WorkbenchList from "./workbenchList";
import Tabs from "@/components/mui/Tabs"; import Tabs from "@/components/mui/Tabs";
...@@ -26,16 +25,6 @@ const ProjectWorkbench = observer(() => { ...@@ -26,16 +25,6 @@ const ProjectWorkbench = observer(() => {
const isPass = usePass(); const isPass = usePass();
const location: any = useLocation(); const location: any = useLocation();
const options = [
{
value: "123",
label: "1234",
},
{
value: "456",
label: "4567",
},
];
const tabList = useMemo(() => { const tabList = useMemo(() => {
return [ return [
{ {
...@@ -73,9 +62,6 @@ const ProjectWorkbench = observer(() => { ...@@ -73,9 +62,6 @@ const ProjectWorkbench = observer(() => {
return ( return (
<div style={{ padding: 24 }}> <div style={{ padding: 24 }}>
<MyMenu options={options} value="123">
<div>123123</div>
</MyMenu>
<div style={{ display: "flex", alignItems: "center" }}> <div style={{ display: "flex", alignItems: "center" }}>
<img src={projectImg} alt="项目logo" /> <img src={projectImg} alt="项目logo" />
<span style={{ marginLeft: 12 }}>工作台</span> <span style={{ marginLeft: 12 }}>工作台</span>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment