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