You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

110 lines
2.7 KiB

  1. import { useEffect, useRef, useState } from 'react';
  2. // material-ui
  3. import { useTheme } from '@mui/material/styles';
  4. import { AppBar, Box, ClickAwayListener, IconButton, Paper, Popper, Toolbar } from '@mui/material';
  5. // project import
  6. import Search from './Search';
  7. import Profile from './Profile';
  8. import Transitions from 'components/@extended/Transitions';
  9. // assets
  10. import { MoreOutlined } from '@ant-design/icons';
  11. // ==============================|| HEADER CONTENT - MOBILE ||============================== //
  12. const MobileSection = () => {
  13. const theme = useTheme();
  14. const [open, setOpen] = useState(false);
  15. const anchorRef = useRef(null);
  16. const handleToggle = () => {
  17. setOpen((prevOpen) => !prevOpen);
  18. };
  19. const handleClose = (event) => {
  20. if (anchorRef.current && anchorRef.current.contains(event.target)) {
  21. return;
  22. }
  23. setOpen(false);
  24. };
  25. const prevOpen = useRef(open);
  26. useEffect(() => {
  27. if (prevOpen.current === true && open === false) {
  28. anchorRef.current.focus();
  29. }
  30. prevOpen.current = open;
  31. }, [open]);
  32. return (
  33. <>
  34. <Box sx={{ flexShrink: 0, ml: 0.75 }}>
  35. <IconButton
  36. component="span"
  37. disableRipple
  38. sx={{
  39. bgcolor: open ? 'grey.300' : 'grey.100',
  40. /* WCAG 2.4.7 – visible keyboard focus */
  41. '&:focus-visible': {
  42. outline: '3px solid #0C489E',
  43. outlineOffset: '2px',
  44. borderRadius: '6px'
  45. }
  46. }}
  47. ref={anchorRef}
  48. aria-controls={open ? 'menu-list-grow' : undefined}
  49. aria-haspopup="true"
  50. onClick={handleToggle}
  51. color="inherit"
  52. >
  53. <MoreOutlined />
  54. </IconButton>
  55. </Box>
  56. <Popper
  57. placement="bottom-end"
  58. open={open}
  59. anchorEl={anchorRef.current}
  60. role={undefined}
  61. transition
  62. disablePortal
  63. style={{
  64. width: '100%'
  65. }}
  66. popperOptions={{
  67. modifiers: [
  68. {
  69. name: 'offset',
  70. options: {
  71. offset: [0, 9]
  72. }
  73. }
  74. ]
  75. }}
  76. >
  77. {({ TransitionProps }) => (
  78. <Transitions type="fade" in={open} {...TransitionProps}>
  79. <Paper sx={{ boxShadow: theme.customShadows.z1 }}>
  80. <ClickAwayListener onClickAway={handleClose}>
  81. <AppBar color="inherit">
  82. <Toolbar>
  83. <Search />
  84. <Profile />
  85. </Toolbar>
  86. </AppBar>
  87. </ClickAwayListener>
  88. </Paper>
  89. </Transitions>
  90. )}
  91. </Popper>
  92. </>
  93. );
  94. };
  95. export default MobileSection;