index.tsx 3.1 KB

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