index.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import { makeStyles } from '@material-ui/core'
  2. import React, { useState } from 'react';
  3. import { styled } from '@mui/material/styles';
  4. import Avatar from '@mui/material/Avatar';
  5. import Menu from '@mui/material/Menu';
  6. import MenuItem from '@mui/material/MenuItem';
  7. import PersonIcon from '@mui/icons-material/Person';
  8. import GroupIcon from '@mui/icons-material/Group';
  9. import GroupsIcon from '@mui/icons-material/Groups';
  10. import ModeEditOutlineOutlinedIcon from '@mui/icons-material/ModeEditOutlineOutlined';
  11. import CloseIcon from '@mui/icons-material/Close';
  12. const useStyles = makeStyles({
  13. container: {
  14. position: 'absolute',
  15. maxWidth: '100%',
  16. top: 895,
  17. left: 390,
  18. zIndex: 10,
  19. visibility: 'visible',
  20. cursor:'pointer'
  21. },
  22. })
  23. const StyledMenu = styled((props:any) => (
  24. <Menu
  25. elevation={0}
  26. anchorOrigin={{
  27. vertical: 'top',
  28. horizontal: 'right',
  29. }}
  30. transformOrigin={{
  31. vertical: 'bottom',
  32. horizontal: 'right',
  33. }}
  34. {...props}
  35. />
  36. ))(({ theme }:any) => ({
  37. '& .MuiPaper-root': {
  38. borderRadius: 10,
  39. marginTop: theme.spacing(-2),
  40. minWidth: 220,
  41. color:
  42. theme.palette.mode === 'light' ? 'rgb(55, 65, 81)' : theme.palette.grey[500],
  43. boxShadow:
  44. 'rgb(255, 255, 255) 0px 0px 0px 0px, rgba(0, 0, 0, 0.05) 0px 0px 0px 1px, rgba(0, 0, 0, 0.1) 0px 10px 15px -3px, rgba(0, 0, 0, 0.05) 0px 4px 6px -2px',
  45. '& .MuiMenu-list': {
  46. padding: '14px 14px',
  47. },
  48. '& .MuiMenuItem-root': {
  49. marginBottom: theme.spacing(1),
  50. '& .MuiSvgIcon-root': {
  51. fontSize: 21,
  52. color: theme.palette.text.secondary,
  53. marginRight: theme.spacing(4),
  54. }
  55. },
  56. },
  57. }));
  58. const SmallMenuBar = () => {
  59. const classes = useStyles()
  60. const [anchorEl, setAnchorEl] = useState<any>(null);
  61. const open = Boolean(anchorEl);
  62. const handleClick = (e: React.MouseEvent<HTMLDivElement>):void => setAnchorEl(e.currentTarget)
  63. const handleClose = (i:number|null):void => {
  64. console.log('chosen one element from small menu by id',i)
  65. setAnchorEl(null)
  66. }
  67. return (
  68. <div className={classes.container}>
  69. <Avatar onClick={handleClick} sx={{
  70. bgcolor: 'rgb(41, 139, 231)',
  71. width: 56, height: 56 }}>
  72. {!anchorEl?<ModeEditOutlineOutlinedIcon />:<CloseIcon/>}
  73. </Avatar>
  74. <StyledMenu
  75. id="demo-positioned-menu"
  76. aria-labelledby="demo-positioned-button"
  77. anchorEl={anchorEl}
  78. open={open}
  79. onClose={handleClose}
  80. >
  81. <MenuItem onClick={() => handleClose(0)}>
  82. <GroupsIcon />
  83. New Channel
  84. </MenuItem>
  85. <MenuItem onClick={() => handleClose(1)}>
  86. <GroupIcon />
  87. New Group
  88. </MenuItem>
  89. <MenuItem onClick={() => handleClose(2)}>
  90. <PersonIcon />
  91. New Message
  92. </MenuItem>
  93. </StyledMenu>
  94. </div>
  95. );
  96. }
  97. export default SmallMenuBar