实现任何菜单或巨型菜单的代码示例

77 阅读1分钟

很多人认为简单的弹出窗口就可以了;很多人认为模态就可以了,但我认为这是一个更通用的方法来实现它;然而,这是一个永无止境的传奇:

import * as React from 'react';
import Box from '@mui/material/Box';
import Switch from '@mui/material/Switch';
import Paper from '@mui/material/Paper';
import Slide from '@mui/material/Slide';
import FormControlLabel from '@mui/material/FormControlLabel';
import { Card } from '@mui/material';

export default function SimpleSlide() {
  const [checked, setChecked] = React.useState(false);
  //const [checked, setChecked] = React.useState(false);
  const containerRef = React.useRef(null);
  const handleChange = () => {
    setChecked((prev) => !prev);
  };

  return (
    <Box sx={{ height: 'fit-content' }}>
      <Box sx={{ width: `fit-content` }} ref={containerRef}>
          <Box onClick={handleChange}>my hero </Box>

        <Slide direction="up" container={containerRef.current} in={checked} mountOnEnter unmountOnExit>
      <Card sx={{ m: 1 }} elevation={1}>
    <Box  component="svg" sx={{ width: 100, height: 100 }}>
      <Box
        component="polygon"
        sx={{
          fill: (theme) => theme.palette.common.red,
          stroke: (theme) => theme.palette.divider,
          strokeWidth: 1,
        }}
        points="0,0 50,50, 100,100, 0,100"
      />
    </Box>
  </Card>
        </Slide>
      </Box>
    </Box>
  );
}

替换这张卡片上的代码,把你的菜单和菜单项放到这里来实现一个巨型菜单:

<Card sx={{ m: 1 }} elevation={1}>
    <Box  component="svg" sx={{ width: 100, height: 100 }}>
      <Box
        component="polygon"
        sx={{
          fill: (theme) => theme.palette.common.red,
          stroke: (theme) => theme.palette.divider,
          strokeWidth: 1,
        }}
        points="0,0 50,50, 100,100, 0,100"
      />
    </Box>
  </Card>